gfem.job#
Serialized runs: Job (job.json) and load_result (result.json).
A job bundle is job.json, the mesh file it references (by path and
sha256) and, when the job has arrays, a .npz sidecar next to it. The
sidecar stores every array of the job (material fields, moved mesh nodes, a
refined mesh, which has no file, …), keyed by where it sits in the job, e.g.
.model.materials['oxide'].eps_r. A result bundle is a directory with
result.json and result.npz. A uniform sweep that stops at an unsolved
frequency leaves a partial bundle there instead, partial.json and
partial.npz: the same layout, holding the partial result, never under the
name result.json. Both documents carry schema_version
and gfem_version: gfem reads older schema versions and refuses newer
ones, and it refuses by name any entry it does not know (one a newer gfem
wrote, or a misspelt one).
Run a job bundle with python -m gfem run job.json --out results/ (or
Job.run), and read the result back with load_result.
Across ranks rank 0 reads and writes the files, and a result bundle holds its fields in one-process numbering, so a bundle from any rank count is an ordinary one that a laptop reads.
Classes#
A self-contained run: a model, a problem and solver options. |
Functions#
|
Read a result bundle written by |
Module Contents#
- class Job#
A self-contained run: a model, a problem and solver options.
The unit gsim and cloud runners exchange.
to_jsonwrites it as a job bundle;python -m gfem run job.json --out DIRorrunsolves it. A job is a JAX pytree whose arrays are the model’s and the problem’s.- Variables:
model – The device.
problem – What to solve, e.g.
gfem.Electrostatic.options – The numerics;
NoneisSolverOptions().
- Raises:
TypeError – An argument has the wrong type.
- classmethod from_json(path, *, comm=None)#
Read a job bundle written by
to_json.The mesh is read again and its sha256 checked. Across ranks this is collective: rank 0 reads the files, and every rank gets the same job or the same error.
- Parameters:
comm (Any) – The communicator, as for
gfem.solve. Ranks reading job files of their own passMPI.COMM_SELF.
- Raises:
FileNotFoundError – The JSON file, its sidecar or its mesh is missing.
ValueError – Not a job file, a newer schema version, a type or an entry this gfem does not know, or a mesh file that changed.
RuntimeError – Ranks asked for different paths.
- Return type:
- run(out=None, *, device=None, comm=None, cache=None)#
Solve the job:
gfem.solve(model, problem, options=options).- Parameters:
out (str | Path | None) – If given, a directory to write the result bundle to (
result.jsonandresult.npz, read byload_result). Across ranks this is collective and rank 0 writes. A partial bundle left there by an earlier run is removed.device (str | None) – Overrides
options.device(e.g. a job written for a GPU run on a CPU machine). The bundle records the device used.comm (Any) – The communicator, as for
gfem.solve; not part of the job, which does not say where it runs.cache (str | PathLike | None) – A directory for the solve cache, as for
gfem.solve: the result is read from it when this job was solved and stored there before, and stored there otherwise. Independent ofout: the bundle is written either way. With a cache the bundle’srunentry has acacheitem:status("hit","miss", or"bypass"when the cache was not used),key(the solve key, or None), and on a hitsolved, thedevice,ranksandwall_time_sof the run that solved it;wall_time_sof therunentry is this call’s.None(the default) solves without a cache and adds nocacheitem.
- Returns:
The problem type’s result.
- Raises:
OSError – Rank 0 cannot write the bundle; on every rank.
LinearSolverConvergenceError – A linear solve did not converge. When a uniform sweep stopped with a partial result and
outis given, the partial result is written there first as a partial bundle,partial.jsonandpartial.npz(neverresult.json, and aresult.jsonof an earlier run is left alone), and the error carries a note saying where it is. Read it withgfem.load_result(out / "partial.json"); itsrunentry lists the unsolved frequencies.
- Return type:
Any
- to_json(path)#
Write the job bundle’s
job.json(and its.npzsidecar).The mesh is referenced by its file path and sha256; the path is stored relative to the JSON file’s directory when the mesh lies inside it, so a directory holding the job and its mesh can be moved or uploaded as one bundle. A mesh with no file (a refined mesh) is stored whole in the sidecar instead. The sidecar,
<stem>.npznext to the JSON file, holds every array of the job (material fields, moved mesh nodes), keyed by where it sits in the job, e.g..model.materials['oxide'].eps_r; it is written only when there are arrays.Not collective: across ranks a script calls it on rank 0.
- options: SolverOptions = None#
- problem: Any#
- load_result(path, *, comm=None)#
Read a result bundle written by
python -m gfem runorJob.run.A bundle from any rank count reads on one process. Under a launcher a bundle with no fields holds no mesh and is read with no communication, on any rank, so a read that fails is one rank’s failure: it ends the job, and the errors below raise only on one process.
- Parameters:
path (str | Path) – The result directory, or its
result.json. A partial bundle is read by its file,DIR/partial.json: it returns the partial result, over the solved frequencies only.comm (Any) – The communicator, as for
gfem.solve.MPI.COMM_SELFunder a launcher reads a bundle with fields as one-process fields.
- Returns:
The result, e.g. a
gfem.ElectrostaticResult, with the same values as the in-process solve.- Raises:
FileNotFoundError – No
result.json(the message says when the directory holds a partial bundle instead), or its sidecar is missing.ValueError – Not a result file, a newer schema version, or an entry this gfem does not know.
DistributedUnsupportedError – A bundle with fields, above one rank.
- Return type:
Any