-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make a serializable version of FunctionalProfile and FunctionalMagnetism #219
base: master
Are you sure you want to change the base?
Conversation
Given that these changes will probably break the way that e.g. molgroups use |
I am happy with this. How would it work in principle? Would we just have a different name for the class/type? |
Not loving the increased verbosity of Does the existing Maybe have a start/end as properties could be problematic since they create a new SLD object each time. That is, Is there a case for end users providing |
Actually, the way dataclass equality comparison works the result is (layer.start == layer.start) is True (it compares attributes, and they're all equal) The dynamic attributes don't specifically interfere with serialization, but add maintenance overhead for the developers (weird bugs!) and cognitive overhead for the users (not a common pattern in python anymore, and full of footguns). The rho_start etc. are by default |
These versions of FunctionalProfile and FunctionalMagnetism differ from the original:
profile
function, they will read the source withinspect.getsource
.profile_source
string, the string will be executed in a context withscipy
andnp
defined, and the function that results will be pulled out. (the function is expected to be the only defined name in the locals context when the exec is complete, so the string should contain only a function definition and nothing else)np
andscipy
namespaces (these are embedded in the execution context), e.g.FunctionalProfile.profile_params
slot
attribute:rho_start
irho_start
rho_end
irho_end
start
andend
attributes are now properties, which create an SLD object, e.g.start == SLD(rho=rho_start, irho=irho_start)
For
FunctionalMagnetism
, a further difference is that the total thickness is stored as an expression in the class. You can set it with aset_anchor
function as before, but now that function will construct a thickness expression, or you can pass in an existing Parameter or Expression, e.g.layer[3].thickness + layer[4].thickness