Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bmaranville
Copy link
Member

These versions of FunctionalProfile and FunctionalMagnetism differ from the original:

  • if the classes are initialized with a profile function, they will read the source with inspect.getsource.
  • if the classes are initialized with profile_source string, the string will be executed in a context with scipy and np 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)
  • profile functions can only use basic math operators and anything in the np and scipy namespaces (these are embedded in the execution context), e.g.
def blobby(z, a, b):
    return scipy.special.erf(b) * np.sin(a * z)
  • parameters for the function are not added to the class as attributes
  • they are instead added to a dict attribute FunctionalProfile.profile_params
  • new attributes are added which are Parameter objects, and a Calculation object in their slot attribute:
    • rho_start
    • irho_start
    • rho_end
    • irho_end
  • the start and end 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 a set_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

@bmaranville
Copy link
Member Author

Given that these changes will probably break the way that e.g. molgroups use FunctionalProfile, we should probably offer them as a new type rather than replacing the existing classes.

@acaruana2009
Copy link
Contributor

Given that these changes will probably break the way that e.g. molgroups use FunctionalProfile, we should probably offer them as a new type rather than replacing the existing classes.

I am happy with this. How would it work in principle? Would we just have a different name for the class/type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants