Closed Andeloth closed 1 year ago
So you want something along the lines of
def custom_component_factory(name: str, wl: np.ndarray, s: np.ndarray):
def s_params(self, wl):
return interpolate(wl, self.wl, self.s)
return type(name, (Model,), {ocount=s.shape[1], wl=wl, s=s, s_params=s_params}
which is really just the same as
def s_params(self, wl):
return interpolate(wl, self.wl, self.s)
my_models = []
for (name, wl, s) in my_collection:
my_models.append(type(name, (Model,), {ocount=s.shape[1], wl=wl, s=s, s_params=s_params}))
which is a one=-liner. I don't see a reason to implement a function so that you can replace a one-liner with a different one-liner. We can document this method of creating dynamic models in a tutorial, but I don't think we'll add it to the codebase.
It would be good to have some kind of component that can be used to represent an arbitary s-matrix that was simulated in Lumerical for example. Something along these lines would be good:
I used a factory function because I'm not sure that there is another way to dynamically set the number of ports in a class (not instance) variable. Maybe an overloaded init function would work that called this function and returned this? Don't really know.