MCPcopy Create free account
hub / github.com/NanoComp/meep / _run_until

Method _run_until

python/simulation.py:2804–2864  ·  view source on GitHub ↗
(self, cond, step_funcs)

Source from the content-addressed store, hash-verified

2802 return dname
2803
2804 def _run_until(self, cond, step_funcs):
2805 self.interactive = False
2806 if self.fields is None:
2807 self.init_sim()
2808
2809 if not isinstance(cond, list):
2810 cond = [cond]
2811
2812 self.progress = False
2813 for i in range(len(cond)):
2814 if isinstance(cond[i], numbers.Number):
2815 stop_time = cond[i]
2816 t0 = self.round_time()
2817
2818 def stop_cond(sim):
2819 return sim.round_time() >= t0 + stop_time
2820
2821 cond[i] = stop_cond
2822
2823 step_funcs = list(step_funcs)
2824 step_funcs.append(
2825 display_progress(t0, t0 + stop_time, self.progress_interval)
2826 )
2827
2828 if do_progress:
2829 self.progress = FloatProgress(
2830 value=t0, min=t0, max=t0 + stop_time, description="0% done "
2831 )
2832 display(self.progress)
2833 else:
2834 assert callable(
2835 cond[i]
2836 ), "Stopping condition {} is not an integer or a function".format(
2837 cond[i]
2838 )
2839
2840 while not any([x(self) for x in cond]):
2841 for func in step_funcs:
2842 _eval_step_func(self, func, "step")
2843 self.fields.step()
2844
2845 # Translating the recursive scheme version of run-until into an iterative version
2846 # (because python isn't tail-call-optimized) means we need one extra iteration to
2847 # be the same as scheme.
2848 for func in step_funcs:
2849 _eval_step_func(self, func, "step")
2850
2851 for func in step_funcs:
2852 _eval_step_func(self, func, "finish")
2853
2854 if do_progress and self.progress:
2855 self.progress.value = t0 + stop_time
2856 self.progress.description = "100% done "
2857
2858 if verbosity.meep > 0:
2859 print(
2860 "run {} finished at t = {} ({} timesteps)".format(
2861 self.run_index, self.meep_time(), self.fields.t

Callers 2

_run_sources_untilMethod · 0.95
runMethod · 0.95

Calls 6

init_simMethod · 0.95
round_timeMethod · 0.95
meep_timeMethod · 0.95
display_progressFunction · 0.85
_eval_step_funcFunction · 0.85
stepMethod · 0.80

Tested by

no test coverage detected