Skip to content

Copies and to_dict do not keep per-Q fitted values, and to_dict is not JSON-serializable #293

Open

Description

@henrikjacobsenfys

copy() and from_dict(to_dict()) rebuild a model from its constructor arguments (#126 made that work for every model class). State that is generated per Q after construction is therefore not carried over:

  • SampleModel, ResolutionModel, BackgroundModel: the per-Q component collections, i.e. the values, bounds and fixed flags fitted at each Q. A copy starts again from the template components.
  • ResolutionModel: whether it has been calibrated.
  • InstrumentModel: the per-Q energy offsets.
  • DeltaLorentz, MittagLefflerDiffusion with allow_Q_variation: the per-Q A_0, width, relaxation rate and alpha lists.

So copying a fitted model, or saving and reloading it, silently loses the fit.

Separately, to_dict() is not JSON-serializable when Q is set (a scipp Variable), nor for an Experiment with data (a DataArray), so a model cannot be written to a file yet.

Things to decide:

  • Whether a copy should carry the per-Q state or stay a copy of the template (both are useful; the second is what "make a new analysis from this sample model" wants).
  • How to serialize the per-Q components generated by diffusion models, whose parameters depend on the diffusion model's.
  • A JSON encoding for Q and for the experiment data.

Activity

  1. added
    [scope] ⚠️ label needed
    [priority] ⚠️ label needed
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] ⚠️ label needed[scope] ⚠️ label needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions