You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, we are dropped into a new REPL with full access to the variables in the scope where the `NaN` occurred. However, because of how `post_op_callback`, this is at a low level within `ClimaCore`, which is typically not useful. Hence, the next step is to type `@trace`, which prints out
Now, when we evaluate our problematic expression (the one at the top level, in this case `renormalized_energy(myrho, myP, myu)`), we will be dropped in a REPL inside `specific_energy`. Here, we have access to `density_without_restmass`, and we notice that it can be zero, leading to the `NaN`.
182
+
183
+
!!! tip
184
+
185
+
The infiltrator REPL is different from the normal Julia repl. Type `?` for
186
+
some useful commands. You can fetch objects defined in the main REPL by
187
+
prepending their name with `Main`. Similarly, if you want to infiltrate inside a
188
+
module, prepend `@infiltrate` with `Main` (`Main.@infiltrate`).
189
+
190
+
Looking at this code, we could have probably guess that the `NaN` comes from a
191
+
division from 0, and the real question is how do we get that?. In more complex
192
+
cases, the functions are spread across different packages and involve several
193
+
different variables. This approach allows one to systematically identify where
194
+
things go wrong.
195
+
196
+
##### Exfiltrating and StructuredPrinting
197
+
198
+
Let's now see a different way to use Infiltrator, where we move the variables in specific scope to the Main scope in the REPL and do some analysis on it.
199
+
83
200
```julia
84
201
import ClimaCore
85
202
import Infiltrator # must be in your default environment
@@ -162,7 +279,7 @@ bc.axes.5::Base.OneTo{Int64}
162
279
bc.axes.5.stop::Int64
163
280
```
164
281
165
-
### Caveats
282
+
####Caveats
166
283
167
284
!!! warn
168
285
@@ -183,3 +300,41 @@ bc.axes.5.stop::Int64
183
300
as Test.jl may continue running through code execution, until all of the
184
301
tests in a given `@testset` are complete, and the result will be that you
185
302
will get the _last_ observed instance of `NaN` or `Inf`.
303
+
304
+
#### Faster explorations when the initialization is expensive
305
+
306
+
Sometimes, we want to start from a given simulation state and explore different
307
+
ideas. For example, we want to run a simulation for 10 days, and then test how
308
+
different approaches affect its stability. Sometimes, checkpoints offer a way to
309
+
do this, but not everything can be checkpointed.
310
+
311
+
A simple way to "checkpoint" a simulation is to `deepcopy` its state. This
312
+
allows one to step the copy instead of the original one, which can be re-used to
313
+
make new copies, allowing for various explorations. `ClimaCore` does not support
314
+
this workflow out-of-the-box. The reason for this is that `ClimaCore` uses
315
+
pointers to perform certain safety checks, and deepcopies return new pointers
316
+
(by definition). To enable this, override the
317
+
`DebugOnly.allow_mismatched_spaces_unsafe` function so that it returns true. When
318
+
`DebugOnly.allow_mismatched_spaces_unsafe` returns true, `ClimaCore` can mix fields
319
+
defined on space that are not identically the same.
0 commit comments