def test_eval_script(self): my_script = "load('base_fdtd_script_test.fsp');" base_script_obj = BaseScript(my_script) base_script_obj.eval(self.sim.fdtd) self.assertTrue(self.sim.fdtd.getnamednumber('FDTD') == 1) self.assertTrue(self.sim.fdtd.getnamednumber('source') == 1) self.assertTrue(self.sim.fdtd.getnamednumber('polygon') == 1)
def test_eval_project_file(self): my_project_file = os.path.join(self.file_dir, 'base_varfdtd_script_test.lms') base_script_obj = BaseScript(my_project_file) base_script_obj(self.sim.fdtd) self.assertTrue(self.sim.fdtd.getnamednumber('varFDTD') == 1) self.assertTrue(self.sim.fdtd.getnamednumber('polygon') == 1)
def __init__(self, base_script, wavelengths, fom, geometry, optimizer, hide_fdtd_cad=False, use_deps=True): self.base_script = base_script if isinstance( base_script, BaseScript) else BaseScript(base_script) self.wavelengths = wavelengths if isinstance( wavelengths, Wavelengths) else Wavelengths(wavelengths) self.wavelengths = wavelengths if isinstance( wavelengths, Wavelengths) else Wavelengths(wavelengths) self.fom = fom self.geometry = geometry self.optimizer = optimizer self.hide_fdtd_cad = bool(hide_fdtd_cad) self.use_deps = bool(use_deps) if self.use_deps: print("Accurate interface detection enabled") self.plotter = Plotter() self.forward_fields = None self.adjoint_fields = None self.gradients = None self.fomHist = [] self.paramsHist = [] self.gradient_fields = None frame = inspect.stack()[1] calling_file_name = os.path.abspath(frame[0].f_code.co_filename) Optimization.goto_new_opts_folder(calling_file_name, base_script) self.workingDir = os.getcwd()
def __init__(self, base_script, wavelengths, fom, geometry, optimizer, use_var_fdtd=False, hide_fdtd_cad=False, use_deps=True, plot_history=True, store_all_simulations=True, save_global_index=False, label=None, source_name='source', fields_on_cad_only=False): super().__init__(plot_history=plot_history, fields_on_cad_only=fields_on_cad_only) self.base_script = base_script if isinstance( base_script, BaseScript) else BaseScript(base_script) self.wavelengths = wavelengths if isinstance( wavelengths, Wavelengths) else Wavelengths(wavelengths) self.fom = fom self.geometry = geometry self.optimizer = optimizer self.use_var_fdtd = bool(use_var_fdtd) self.hide_fdtd_cad = bool(hide_fdtd_cad) self.source_name = source_name if callable(use_deps): self.use_deps = True self.custom_deps = use_deps else: self.use_deps = bool(use_deps) self.custom_deps = None self.store_all_simulations = store_all_simulations self.save_global_index = save_global_index self.unfold_symmetry = geometry.unfold_symmetry self.label = label self.plot_fom_on_log_scale = (float(fom.target_fom) != 0.0) if self.use_deps: print("Accurate interface detection enabled") ## Figure out from which file this method was called (most likely the driver script) frame = inspect.stack()[1] self.calling_file_name = os.path.abspath(frame[0].f_code.co_filename) self.base_file_path = os.path.dirname(self.calling_file_name)
def __init__(self, base_script, wavelengths, fom, geometry, optimizer, use_var_fdtd=False, hide_fdtd_cad=False, use_deps=True, plot_history=True, store_all_simulations=True): self.base_script = base_script if isinstance( base_script, BaseScript) else BaseScript(base_script) self.wavelengths = wavelengths if isinstance( wavelengths, Wavelengths) else Wavelengths(wavelengths) self.fom = fom self.geometry = geometry self.optimizer = optimizer self.use_var_fdtd = bool(use_var_fdtd) self.hide_fdtd_cad = bool(hide_fdtd_cad) self.use_deps = bool(use_deps) self.plot_history = bool(plot_history) self.store_all_simulations = store_all_simulations self.unfold_symmetry = geometry.unfold_symmetry if self.use_deps: print("Accurate interface detection enabled") self.plotter = None #< Initialize later, when we know how many parameters there are self.fomHist = [] self.paramsHist = [] frame = inspect.stack()[1] calling_file_name = os.path.abspath(frame[0].f_code.co_filename) Optimization.goto_new_opts_folder(calling_file_name, base_script) self.workingDir = os.getcwd()
def test_eval_script_file(self): my_script_file = os.path.join(self.file_dir, 'base_varfdtd_script_test.lsf') base_script_obj = BaseScript(my_script_file) base_script_obj.eval(self.sim.fdtd) self.assertTrue(self.sim.fdtd.getnamednumber('varFDTD') == 1)
def test_eval_python_script(self): my_fun = lambda fdtd_handle: fdtd_handle.addvarfdtd() base_script_obj = BaseScript(my_fun) base_script_obj.eval(self.sim.fdtd) self.assertTrue(self.sim.fdtd.getnamednumber('varFDTD') == 1)