zoomy_jax.symsolver.runtime#
JAX runtime of the symbolic solvers: what each name of a printed solver means on JAX. The
printed template (solver template -> PyPrinter) is plain Python calling this name table: nsm
is the vmapped JaxRuntime of the kernels, every other entry a zoomy_core.symsolver block.
References
Bradbury et al. 2018, jax-ml/jax
Module Contents#
Classes#
How the JAX march is differentiated. |
|
The |
|
A participant exchanging the model’s vertical column with a resolved peer (VOF) or with
another level of the model: it writes |
Functions#
All solver geometry from vertex coordinates |
|
Build the name table (dict of callables) a printed solver runs against: the JAX
implementation of every |
|
Boundary faces carrying boundary tag |
|
|
|
Execute printed source against the name table and return the function |
API#
- class zoomy_jax.symsolver.runtime.AdMode#
Bases:
zoomy_core.misc.options.OptionHow the JAX march is differentiated.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- forward#
‘forward’
- reverse#
‘reverse’
- class zoomy_jax.symsolver.runtime.Geometry#
Bases:
typing.NamedTupleThe
meshargument of a printed solver, computed from the vertex coordinates inside the traced function so thatjax.gradreaches the vertices. Topology (indices, stencils) is static and lives in the runtime’s closures.- cell_volumes: jax.numpy.ndarray#
None
- cell_centers: jax.numpy.ndarray#
None
- cell_inradius: jax.numpy.ndarray#
None
- face_normals: jax.numpy.ndarray#
None
- face_volumes: jax.numpy.ndarray#
None
- face_centers: jax.numpy.ndarray#
None
- lsq_gradQ: jax.numpy.ndarray#
None
- lsq_closure: jax.numpy.ndarray#
None
- zoomy_jax.symsolver.runtime.geometry_of(topo, X)#
All solver geometry from vertex coordinates
X(dim, n_vertices).
- zoomy_jax.symsolver.runtime.runtime(nsm, rt, mesh_np, mesh_j, topo, *, ad_mode=AdMode.forward, checkpoints=64, on_write=None, on_save=None, on_load=None, couple=None, implicit=None, systems=None, partition=None)#
Build the name table (dict of callables) a printed solver runs against: the JAX implementation of every
zoomy_core.symsolverblock on this mesh. Called by the JAX solver driver’s_setup.Args
topo: static topology (geometry_xp.build_topology) with the boundary-closure classesad_mode:AdMode.forward, orAdMode.reversefor a time loop withcheckpointscheckpointson_write:on_write(time, Q, Qaux)snapshot callback (forward mode)on_save,on_load: the restart pair (host),on_save(time, Q, Qaux)(forward mode) andon_load(time, Q, Qaux) -> (time, Q, Qaux); None: no restart file / not restartingcouple: preCICE settingsdict(adapter=, tag=, side=)implicit: Newton and linear-solver settings ofrootandlinsolvesystems: further{name: (nsm, JaxRuntime)}a template uses besidesnsmpartition: this rank’s piece of a distributed run; itshaloand global reductions replace the serial ones
Returns
dict name -> callable
- class zoomy_jax.symsolver.runtime.ColumnPreciceAdapter(name, config, mesh_name, write, read, nz, comm=None, y=0.5)#
Bases:
zoomy_core.symsolver.precice_adapter.PreciceAdapterA participant exchanging the model’s vertical column with a resolved peer (VOF) or with another level of the model: it writes
interpolate_to_3dof the cells next to the coupled faces and reads the peer’s column back throughproject_from_3d(of the interface model, whenbindis given one), as the six canonical fields[b, h, u, v, w, p](write,read: six data names each) at thenzcell-centre heightssigma_k = (k + 1/2)/nzof each coupled face, vertex(x_face, y, sigma_k).read_round_trip()is the own state as the peer reads it,P(I(q)), of the last write.modelandparametersare bound by the runtime (bind).Initialization
As
PreciceAdapter;nzheights per face,ythe vertices’ second coordinate.- bind(model, parameters, interface=None)#
The model (its
interpolate_to_3d,project_from_3dand aux order) and the parameter vector;interface(a SystemModel): the columns, the peer’s and the own round trip, are projected to its state instead (a lifted shared face).
- set_vertices(coords)#
nzvertices(x, y, sigma_k)per coupled face centre incoords, face-major.
- init(q, qaux=None)#
Write the initial column if required, initialise; returns whether coupling is ongoing.
- write(q, qaux=None)#
Write the column of
q; keeps its round trip.
- read()#
The peer’s states
(n_state, faces)(interface: its rows), projected from its columns (all zero before the peer has written).
- read_round_trip()#
The own states of the last write as the peer reads them,
P(I(q)).
- zoomy_jax.symsolver.runtime.coupled_face_indices(mesh_np, tag)#
Boundary faces carrying boundary tag
tag(by name).
- zoomy_jax.symsolver.runtime.hoisted_jit(fn)#
jax.jit(fn)with the constantsfncaptures (the mesh index arrays) passed as arguments, so compile time and program size stay independent of the mesh. Its compile goes through the persistent compilation cache also when the program has host callbacks (compile_cache; withjax_compilation_cache_dirset).
- zoomy_jax.symsolver.runtime.build(src, name, module)#
Execute printed source against the name table and return the function
name; raises if the source uses a block the table lacks.