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#

Job

A self-contained run: a model, a problem and solver options.

Functions#

load_result(path, *[, comm])

Read a result bundle written by python -m gfem run or Job.run.

Module Contents#

class Job#

A self-contained run: a model, a problem and solver options.

The unit gsim and cloud runners exchange. to_json writes it as a job bundle; python -m gfem run job.json --out DIR or run solves 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; None is SolverOptions().

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:
  • path (str | Path) – The JSON file.

  • comm (Any) – The communicator, as for gfem.solve. Ranks reading job files of their own pass MPI.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:

Job

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.json and result.npz, read by load_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 of out: the bundle is written either way. With a cache the bundle’s run entry has a cache item: status ("hit", "miss", or "bypass" when the cache was not used), key (the solve key, or None), and on a hit solved, the device, ranks and wall_time_s of the run that solved it; wall_time_s of the run entry is this call’s. None (the default) solves without a cache and adds no cache item.

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 out is given, the partial result is written there first as a partial bundle, partial.json and partial.npz (never result.json, and a result.json of an earlier run is left alone), and the error carries a note saying where it is. Read it with gfem.load_result(out / "partial.json"); its run entry lists the unsolved frequencies.

Return type:

Any

to_json(path)#

Write the job bundle’s job.json (and its .npz sidecar).

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>.npz next 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.

Parameters:

path (str | Path) – The JSON file to write; its directory is created.

Returns:

The JSON file’s path.

Raises:

TypeError – The job holds values computed inside jax.grad, jax.jit or jax.vmap; write it from fixed values.

Return type:

Path

model: Model#
options: SolverOptions = None#
problem: Any#
load_result(path, *, comm=None)#

Read a result bundle written by python -m gfem run or Job.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_SELF under 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