Create StagedModel class for chaining LUMEModel instances#22
Create StagedModel class for chaining LUMEModel instances#22roussel-ryan wants to merge 7 commits intoslaclab:mainfrom
Conversation
electronsandstuff
left a comment
There was a problem hiding this comment.
Overall looks good.
- For the input and output beam variables. I am a little worried about having them hard-coded. This limits flexibility to use with pre-packaged models that have beams exposed, but with the wrong names. Especially with a high level object in lume-base I would prefer to not tie users into a particular naming scheme. Could we look at defining them in software.
- Using fixed names also has the issue that they now conflict with each other with multiple stages... ie
beam_inputexists as a variable in all stages except maybe the first. I think this deserves some thought.
|
|
||
| @property | ||
| def supported_variables(self) -> dict[str, Variable]: | ||
| # TODO: handle conflicts in for beam_input and beam_output variable names across models |
There was a problem hiding this comment.
This could go in as a validation class method that gets called in __init__.
|
Thanks for the comment @electronsandstuff, I'm happy to hear any ideas, we can also chat tomorrow about it |
|
OK, some thoughts on how this could be structured. The big worry I have is that the way the code is structured requires non-overlapping sets of variable names in each stage for things to be unambiguous. However, at the same time, it also requires that the stages have the shared names for initial and final particles. One way this could be resolved is to define the particle input / output programmatically. class ModelParticleInputMixIn:
@property
def input_particles(self):
...
@input_particles.setter
def input_particles(self, par):
...class ModelParticleOutputMixIn:
@property
def output_particles(self):
...These classes can get added by inheritance to any existing concrete lume-models that have a clear input and output particle variable. For instance, in Tao, there is a clearly defined If this seems like an OK implementation, we would add these to staged model. Then the concrete model classes would have the mixins added and the input and output particles defined if they are clear from the simulation tool. The staged model class would validate that each class has the required interface (ie that the first is an instance of |
This pull request introduces a new
StagedModelclass inlume/staged_model.pythat enables the composition of multipleLUMEModelinstances into a staged sequence. This allows users to chain together several models, passing beam distributions between them in a controlled and validated manner.The most important changes are:
New Feature: Staged Model Composition
StagedModelclass, which allows users to stage multipleLUMEModelinstances in sequence, automatically passing beam distributions between them. (lume/staged_model.py)Validation and Safety
validate_lume_model_instancesclass method to ensure that all staged models have compatiblebeam_inputandbeam_outputvariables of typeParticleGroupVariable, preventing misconfiguration. (lume/staged_model.py)API and Interface
supported_variablesproperty that aggregates the supported variables from all staged models, with a note about potential naming conflicts. (lume/staged_model.py)_setmethod to propagate input values through the staged models, updating and passing beam distributions as needed. (lume/staged_model.py)