def main(): "Main code for demo purposes" logging.basicConfig(level=logging.DEBUG) mysys = OpticalSystem(name="s") mysys.lst = [] mysys.lst.append({}) mysys.lst.append({}) mysys.lst[0]["a"] = FloatOptimizableVariable(FixedState(3.0), name="v1") mysys.lst[1]["b"] = FloatOptimizableVariable(VariableState(7.0), name="v2") mysys.rootcoordinatesystem.decz = FloatOptimizableVariable( FixedState(-99.0), name="decz") listOptimizableVariables(mysys) confmanager = ConfigManager(mysys, name="mc") [mysys2, mysys3] = confmanager.set_optimizable_variables( ("s2", "s3"), { "s.global.decz": (("pickup", lambda x: x + 2.0), ("pickup", lambda x: x + 3.0)), "s.global.decy": (("fixed", -2.), ("fixed", -3.)) }) mysys.rootcoordinatesystem.decx.setvalue(-98.0) for syscopy in (mysys2, mysys3): mydict = listOptimizableVariables(syscopy) print(mydict)
def getVariable(self, key): """ Gets variable from short key. """ dict_of_vars = self.getAllVariables() variable = dict_of_vars["vars"][key] return variable ''' if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) s = OpticalSystem(name="s") s.lst = [] s.lst.append({}) s.lst.append({}) s.lst[0]["a"] = FloatOptimizableVariable(FixedState(3.0), name="v1") s.lst[1]["b"] = FloatOptimizableVariable(VariableState(7.0), name="v2") s.rootcoordinatesystem.decz = FloatOptimizableVariable(FixedState(-99.0), name="decz") listOptimizableVariables(s) m = ConfigManager(s, name="mc") [s2, s3] = m.setOptimizableVariables( ("s2", "s3"), { "s.global.decz":
self.warning("Unknown type for multi config values") else: self.debug("Reseting %s" % (key,)) instance.resetVariable(key, self.base_instance.getVariable(key)) # set names of the new instances accordingly self.debug("Setting name of instance %s" % (names_tuple[index])) instance.setName(names_tuple[index]) return instance_list if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) s = OpticalSystem(name="s") s.lst = [] s.lst.append({}) s.lst.append({}) s.lst[0]["a"] = OptimizableVariable(variable_type="fixed", name="v1", value=3.0) s.lst[1]["b"] = OptimizableVariable(variable_type="variable", name="v2", value=7.0) s.rootcoordinatesystem.decz = OptimizableVariable(name="decz", value=-99.0) listOptimizableVariables(s) m = ConfigManager(s, name="mc") [s2, s3] = m.setOptimizableVariables(("s2", "s3"), {"s.global.decz": (("pickup", lambda x: x + 2.0), ("pickup", lambda x: x + 3.0)), "s.global.decy": (("fixed", -2.), ("fixed", -3.))})