OxIonics / ionics_fits

Small python fitting library with an emphasis on Atomic Molecular and Optical Physics
Apache License 2.0
1 stars 0 forks source link

Modifying model parameters affects class attributes #20

Closed hartytp closed 1 year ago

hartytp commented 1 year ago

Consider this case:

import ionic_fits as fits

model1 = fits.models.Rectangle()
print(model1.parameters["a"].fixed_to)
model1["a"].fixed_to = 1

model2 = fits.models.Rectangle()
print(model2.parameters["a"].fixed_to)

prints

None
1

which is not desired behaviour. @mbirtwell any thoughts about the best way of handling this?

hartytp commented 1 year ago

Replacing https://github.com/OxIonics/ionics_fits/blob/4116574ce7a0507e23ba3a9d1ce7fa2f10812a69/ionics_fits/common.py#L147 with


            self.parameters = {name: copy.deepcopy(spec.annotations[name]) for name in spec.args[2:]}
``` resolves this. Not sure if that's the most appropriate resolution though?
mbirtwell commented 1 year ago

I think that deepcopy is a perfectly reasonable way to resolve this.