M48. Solutions in files

Package: K7, its first part: a solution is saved to a file with its plan, its diagnostics and the description of its problem, and loaded again as a solution that can be read, called for values and plotted.

What was built

  • solution.save(path) and pm.load(path), in the new file python/pdemagic/_files.py. The ending .npz is added where it is missing, on the way in and on the way out.

  • The file is a numpy archive. It holds the arrays as they are, one entry field/<name> for each unknown, the recorded times, and what the method holds of the solution beyond its grid (decision D46.3), so that a loaded solution on a region is still called for values. The plan, the diagnostics and the problem as the solver read it are JSON. A first entry names the format.

  • SavedProblem: what a loaded solution knows of its problem. It has the domain, made anew from what it was made from, the time span, and the description that the solver read. Plotting reads the first two, the call for values the third.

What was checked

A solution comes back with the same values, times, plan and diagnostics, bit for bit: a complex unknown in time on a region with a hole, a system with two unknowns, and one stationary problem on each kind of domain. Every domain comes back with the same entries as the one that was saved. The loaded solution gives the same values between its points, and is plotted and animated. A file that is no solution, or of a later format, is refused.

Decisions

D48.1. A numpy archive, and nothing that is executed

Developer, 2026-11-19.

The file is what numpy writes for several arrays: a zip of arrays, which every tool that reads numpy opens. Texts are stored as arrays of one string. Nothing in it is pickled, and it is loaded with pickling forbidden, so opening a file from somebody else runs no code of theirs. That rules out the short way of keeping the problem, which would have been to pickle it with its sympy expressions.

This is the format of the Python frontend for its own solutions. Which formats problems and results have between languages and tools is still the owner’s to decide (E6).

D48.2. A loaded solution has a saved problem, not a problem

Developer, 2026-11-19.

A problem in Python holds sympy expressions, and the way from the description that the solver reads back to sympy does not exist (B5). So the file keeps the description, and of the frontend’s side the domain alone, by what it was made from: its kind, its coordinates by name, its sizes, the pieces of its curves. That is what a solution needs to be drawn and to be called. The loaded solution says what it has, a SavedProblem, which cannot be solved. It does not pretend to be a Problem that fails when it is used.

The coordinates come back as symbols with the names of the original ones, real if those were. Other assumptions of sympy are not kept.

D48.3. The values of data fields stay outside

Developer, 2026-11-19.

A problem with data was given arrays. They are the user’s, they may be large, and the solution does not need them to be read. The file does not hold them.

What is left

  • Export to other tools: VTK for ParaView, xarray.

  • A saved problem that can be solved again (B5).