:py:mod:`wolfgpu.SimulationRunner` ================================== .. py:module:: wolfgpu.SimulationRunner .. autoapi-nested-parse:: Author: HECE - University of Liege, Stéphane Champailler, Pierre Archambeau Date: 2024 Copyright (c) 2024 University of Liege. All rights reserved. This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited. Module Contents --------------- .. py:class:: GlWindowManagerInterface Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: wolfgpu.SimulationRunner.GlWindowManagerInterface :parts: 1 :private-bases: Generic enumeration. Derive from this class to define new enumerations. .. py:attribute:: PYGAME :value: 'pygame' .. py:attribute:: GLFW :value: 'glfw' .. py:method:: for_glfw(glfw_window) :classmethod: If one wants to call the swap buffer function in glfw, one needs to have a reference to the window. .. py:data:: MEM_TRACKING :value: False .. py:data:: MOSTLY_DRY_MESHES_THRESHOLD :value: 1e-05 Number of steps recorded in the database of simulation times used by the injection triggering to estimate the next trigger. .. py:data:: INJECTION_TRIGGER_TIME_ESTIMATOR_DEPTH :value: 100 .. py:function:: count_infiltration_cells(a, nb_zones) :param a: infiltration zones array. Zone indices are 1 baseD. :return: a numpy array (1D) with all the counts, one per zone. .. py:class:: SimulatoryQuery(simulator: wolfgpu.glsimulation.GLSimulation, modifiable_area: tuple) Get data over the active zone, not the whoel domain!!!!! .. py:method:: read_bathymetry() -> numpy.array .. py:method:: read_infiltration_zones() -> numpy.array .. py:method:: set_current_infiltration_quantities(q: numpy.array) .. py:method:: set_bathymetry(inf: numpy.array) .. py:class:: InjectorWrapper(injector: wolfgpu.injector.SimulationInjector, sim: wolfgpu.simple_simulation.SimpleSimulation, infiltration_chronolgy: wolfgpu.simple_simulation.InfiltrationChronology) .. py:property:: injector .. py:property:: time_sampler .. py:class:: OpenGLContext(sim: wolfgpu.simple_simulation.SimpleSimulation, gl_wmi: GlWindowManagerInterface = GlWindowManagerInterface.PYGAME) .. py:method:: destroy_context() .. py:class:: SimulationRunner(glsim: wolfgpu.glsimulation.GLSimulation, record_path: Union[pathlib.Path, str] = Path('.'), early_out_delta_max: float = 1e-06, record: bool = True, page_flip_func=pygame.display.flip, enable_alpha_recording: bool = False, data_injector: wolfgpu.injector.SimulationInjector = None) .. py:property:: early_out_threshold :type: float .. py:property:: step_num The step that is going to be computed. Starts at zero. .. py:attribute:: record :type: bool .. py:attribute:: _glsim :type: wolfgpu.glsimulation.GLSimulation .. py:method:: _setup_injectors(data_injector, glsim: wolfgpu.glsimulation.GLSimulation) .. py:method:: continue_a_simulation(sim: wolfgpu.simple_simulation.SimpleSimulation, result_store_path: Union[pathlib.Path, str], refresh_view: float = 0.1, early_out_threshold=None, injector: wolfgpu.injector.SimulationInjector = None) -> wolfgpu.results_store.ResultsStore :classmethod: .. py:method:: _prepare_quick_run(sim: wolfgpu.simple_simulation.SimpleSimulation, record_path: Union[pathlib.Path, str], refresh_view: float = 0.1, early_out_threshold=None, gl_wmi: GlWindowManagerInterface = GlWindowManagerInterface.PYGAME, injector: wolfgpu.injector.SimulationInjector = None, tiling: wolfgpu.glsimulation.TilePackingMode = TilePackingMode.REGULAR) -> SimulationRunner :classmethod: Run a full simulation quickly. By quickly we mean a lot of the setup of the simulator (such as OpenGL context) is done automatically. In particular a progress window is displayed. :param sim: the simulation you want to run :param record_path: a directory where to record the results of the simulation. We accept `str` as well as `Path`. :param refresh_view: how often the progress window is displyaed (every N seconds). :return: At the end of the simulation a ´ResultStore´ is returned. It is open in read only mode, so that it can be used to query your results. .. py:method:: quick_run(sim: wolfgpu.simple_simulation.SimpleSimulation, record_path: Union[pathlib.Path, str], refresh_view: float = 0.1, early_out_threshold=None, gl_wmi: GlWindowManagerInterface = GlWindowManagerInterface.PYGAME, injector: Union[wolfgpu.injector.SimulationInjector, List[wolfgpu.injector.SimulationInjector]] = None, tiling: wolfgpu.glsimulation.TilePackingMode = TilePackingMode.REGULAR) -> wolfgpu.results_store.ResultsStore :classmethod: Run a full simulation quickly. By quickly we mean a lot of the setup of the simulator (such as OpenGL context) is done automatically. In particular a progress window is displayed. :param sim: the simulation you want to run :param record_path: a directory where to record the results of the simulation. We accept `str` as well as `Path`. :param refresh_view: how often the progress window is displyaed (every N seconds). :param injector: A `SimulationInjector` or a list of them. :return: At the end of the simulation a ´ResultStore´ is returned. It is open in read only mode, so that it can be used to query your results. .. py:method:: _finish_quickrun(simulation_runner: SimulationRunner) -> wolfgpu.results_store.ResultsStore :classmethod: .. py:method:: scanned_file() .. py:method:: restart_from_record(start_rec=None) Restart a simulation from a previous record. This is useful when you want to continue a simulation that has been interrupted. When restarting from a record, it means that the record in question will be deleted and simulation will go on from there. :param start_rec: the index of the record you want to start from. If None, the simulation will restart from the last record. .. py:method:: results_path() -> pathlib.Path .. py:method:: results_store() -> wolfgpu.results_store.ResultsStore Gives a result store back. The result store will be opened in read mode. .. py:method:: record_file() .. py:method:: do_record(texture_ndx, global_state, force=False) Record current state of the simulation. Be careful, this implies reading data from the GPU which is *slow* ! .. py:method:: texture_written_by_last_step() -> int After running `run_one_step` this gives the number of the texture that was *written* to (zero or one; rememeber the GPU code often uses flip-flop textures, that's what you query here). .. py:method:: texture_read_by_last_step() -> int .. py:method:: run_extra_step() When a simulation run is complete, this allows to run an additional step. This is useful in debugging. FIXME The way the reporting is updated is not clear right now. .. py:method:: _check_simulation_is_progressing(h, hu, hv) .. py:method:: _refresh_display_parameters() .. py:method:: _read_simulation_global_state() -> wolfgpu.glsimulation.GLSimulationGlobalState Read the current global state of the simulation. The raison d'être of this method is to allow to to cache the result of the query if the global state because it is expensive. .. py:method:: _handle_data_injector(proxy: wolfgpu.injector.SimulationProxy, data_injector_wrapper: InjectorWrapper, sim_finished_step: int, sim_finished_step_time: float, source_quantity: int, infiltration_chronology) -> wolfgpu.injector.SimulationProxy .. py:method:: _run_all_injectors(source_quantity: int, triggered_timers: set[wolfgpu.sampled_timer.TimeSampler], global_state: wolfgpu.glsimulation.GLSimulationGlobalState) -> wolfgpu.injector.SimulationProxy .. py:method:: _apply_changes_in_proxy(proxy: wolfgpu.injector.SimulationProxy, source_quantity: int) .. py:method:: run_one_step(dont_close_results: bool = False) Run only one step of the simulation. Globally, this method does the following: - Run the GLSimulation for one step with the correct `source_quantity` - Record the results if needed - Inverse the `source_quantity` index - Perform some estimation of the next stop time :param dont_close_results: If True, the results store will not be closed .. py:method:: plot_progress2() .. py:method:: file_in_use(f) .. py:method:: _try_reload_bathymetry() .. py:method:: init_result_store() .. py:method:: full_run(refresh_view: int = 1, dont_close_results: bool = False, refresh_colormap: int = 10) Perform a full simulation run. :param refresh_view: Refresh the view every `refresh_view` seconds :param dont_close_results: Leave the result store open :param refresh_colormap: Refresh the colormap every `refresh_colormap * refresh_view` seconds .. py:method:: _admin_tasks(iteration_times: numpy.ndarray, triggered_timers: set, taqadum: tqdm.tqdm) Perform administrative tasks such as updating the progress bar, compute indicators or reload bathymetry. .. py:method:: _must_continue_event() -> bool Check if the simulation was cancelled early by the user. :return bool: True if the simulation should continue, False if it should stop. .. py:method:: _setup_full_run(refresh_view: int = 1, refresh_update_colormap: int = 10) Prepare the simulation for a full run. :param refresh_view: Refresh the view every `refresh_view` seconds. :param refresh_update_colormap: Refresh the colormap every `refresh_view * refresh_update_colormap` seconds. .. py:method:: _teardown_full_run(iteration_times)