2.Cellscanbeeditedandexecuted.Toeditacell,double-clickuntiltheframearounditturnsgreen.Bydefault,we'll execute the whole notebook when you load it, but to explicitly execute a cell (whether you'veediteditornot),selectitandpressShift+Enter.Thiswillexecutethecell,recorditsoutput,andadvancetothenextcell.
3.UnlikeJupyternotebooks,whichyoumayhaveusedbefore,marimonotebooksare_reactive_,meaningthatchangingthecodeinacellwillcauseanycelldependingonthechangedcell's outputs to re-run. This makes it possible to develop interactive apps and dashboards, but it also limits a potential reproducibility challenge that can come up while editing non-reactive notebooks.
Thenextcellisacodecell.Itshouldhaverunautomatically,buttryexecutingitifnot.You'll be editing and re-running this cell in the next step.
✅Changethecodeabovetoshowapurple-tintedimageinsteadofablue-tintedone.(Ifyoudon't know exactly what it'sdoing,trychangingsomeofthevariablestoseehowitaffectsthepicture!)
Inthenotebookswe'll be working on today, there will be many opportunities to change cells and see how small code changes influence the results and performance of our models. You should always feel free to edit notebook cells and experiment with changes to code. We'llcalloutseveralplaceswherewe've made it especially easy to try new things (or where we'vegivenyouexercisestotry)withacheckmarkemoji,likethis:✅
Youjustdidthat,soyou'll notice it next time!
# Recovering from mistakes
Nextup,we'll see how to backtrack. Say you make a mistake in your notebook and overwrite a variable declaration that you need, or perhaps you get stuck and can'tfigureouthowtogetbacktoacleanslate.Runthenextcell.
"""
)
return
@app.cell
def_():
deffoo(x):
""" paradoxically, this is an unhelpful function """
return"sorry, I don't know anything about %r"%x
help=foo
help(foo)
return
@app.cell(hide_code=True)
def_(mo):
mo.md(
r"""
Oh,no!We've overwritten the definition of the `help` built-in function. This is an important way to access documentation as we'reexperimentingwithnewPythonlibraries.Fortunately,wecanusethisasanopportunitytolearnhowtocleanupafterourmistake.
Sincesomeofthecodewe'll execute will allocate memory on the GPU, we may need to clean up after it before moving on to other notebooks. When you'redonewithanotebook,simplygotothedrop-downmenuandselect`Kernel->ShutDownKernel`beforeproceedingtothenextnotebook.
# These notebooks
Inthesenotebooks,you'll be using JAX to accelerate prototype implementations of a machine learning technique. Here'showtoproceed: