示例#1
0
def discretize_to_pixelated_grating(cont_var: goos.Variable,
                                    height_fracs: np.ndarray,
                                    pixel_size: float,
                                    start_height_ind: int,
                                    end_height_ind: int,
                                    min_features: np.ndarray,
                                    max_features: np.ndarray = None,
                                    divisions: int = 5,
                                    use_edge_locs: bool = False,
                                    discr_min_features: np.ndarray = None,
                                    discr_max_features: np.ndarray = None,
                                    **kwargs):

    widths_or_edge_locs = goos.Variable(0)
    height_index = goos.Variable(0)
    grating = PixelatedGrating(widths_or_edge_locs,
                               height_index,
                               height_fracs,
                               use_edge_locs=use_edge_locs,
                               **kwargs)

    action = GratingL2D(cont_var,
                        widths_or_edge_locs,
                        height_index,
                        pixel_size,
                        height_fracs,
                        start_height_ind,
                        end_height_ind,
                        min_features,
                        max_features,
                        divisions,
                        use_edge_locs=use_edge_locs,
                        discr_min_features=discr_min_features,
                        discr_max_features=discr_max_features)
    goos.get_default_plan().add_action(action)
    height_index.freeze()

    return widths_or_edge_locs, height_index, grating
示例#2
0
def scipy_minimize(objective: goos.Function, *args,
                   **kwargs) -> ScipyOptimizer:
    optimizer = ScipyOptimizer(objective, *args, **kwargs)
    goos.get_default_plan().add_action(optimizer)
    return optimizer
示例#3
0
 def thaw(self):
     if self._is_param:
         raise ValueError("Cannot thaw a parameter.")
     goos.get_default_plan().add_action(ThawVariable(self))
示例#4
0
 def freeze(self):
     goos.get_default_plan().add_action(FreezeVariable(self))
示例#5
0
 def set(self, value):
     if isinstance(value, numbers.Number) or isinstance(value, np.ndarray):
         value = Constant(value)
     goos.get_default_plan().add_action(SetVariable(self, value))
示例#6
0
 def eval(self, inputs: List) -> flows.NumericFlow:
     return flows.NumericFlow(goos.get_default_plan().get_var_value(self))
示例#7
0
文件: generic.py 项目: zizai/spins-b
def log_print(*args, **kwargs) -> LogPrint:
    action = LogPrint(*args, **kwargs)
    goos.get_default_plan().add_action(action)
    return action