wolfgpu.SimulationRunner

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

class wolfgpu.SimulationRunner.GlWindowManagerInterface[source]

Bases: enum.Enum

Inheritance diagram of wolfgpu.SimulationRunner.GlWindowManagerInterface

Generic enumeration.

Derive from this class to define new enumerations.

PYGAME = 'pygame'[source]
GLFW = 'glfw'[source]
classmethod for_glfw(glfw_window)[source]

If one wants to call the swap buffer function in glfw, one needs to have a reference to the window.

wolfgpu.SimulationRunner.MEM_TRACKING = False[source]
wolfgpu.SimulationRunner.MOSTLY_DRY_MESHES_THRESHOLD = 1e-05[source]

Number of steps recorded in the database of simulation times used by the injection triggering to estimate the next trigger.

wolfgpu.SimulationRunner.INJECTION_TRIGGER_TIME_ESTIMATOR_DEPTH = 100[source]
wolfgpu.SimulationRunner.count_infiltration_cells(a, nb_zones)[source]
Parameters:

a – infiltration zones array. Zone indices are 1 baseD.

Returns:

a numpy array (1D) with all the counts, one per zone.

class wolfgpu.SimulationRunner.SimulatoryQuery(simulator: wolfgpu.glsimulation.GLSimulation, modifiable_area: tuple)[source]

Get data over the active zone, not the whoel domain!!!!!

read_bathymetry() numpy.array[source]
read_infiltration_zones() numpy.array[source]
set_current_infiltration_quantities(q: numpy.array)[source]
set_bathymetry(inf: numpy.array)[source]
class wolfgpu.SimulationRunner.InjectorWrapper(injector: wolfgpu.injector.SimulationInjector, sim: wolfgpu.simple_simulation.SimpleSimulation, infiltration_chronolgy: wolfgpu.simple_simulation.InfiltrationChronology)[source]
property injector[source]
property time_sampler[source]
class wolfgpu.SimulationRunner.OpenGLContext(sim: wolfgpu.simple_simulation.SimpleSimulation, gl_wmi: GlWindowManagerInterface = GlWindowManagerInterface.PYGAME)[source]
destroy_context()[source]
class wolfgpu.SimulationRunner.SimulationRunner(glsim: wolfgpu.glsimulation.GLSimulation, record_path: 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)[source]
property early_out_threshold: float[source]
property step_num[source]

The step that is going to be computed. Starts at zero.

record: bool[source]
_glsim: wolfgpu.glsimulation.GLSimulation[source]
_setup_injectors(data_injector, glsim: wolfgpu.glsimulation.GLSimulation)[source]
classmethod continue_a_simulation(sim: wolfgpu.simple_simulation.SimpleSimulation, result_store_path: pathlib.Path | str, refresh_view: float = 0.1, early_out_threshold=None, injector: wolfgpu.injector.SimulationInjector = None) wolfgpu.results_store.ResultsStore[source]
classmethod _prepare_quick_run(sim: wolfgpu.simple_simulation.SimpleSimulation, record_path: 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[source]

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.

Parameters:
  • sim – the simulation you want to run

  • record_path – a directory where to record the results of the simulation. We accept str as well as Path.

  • refresh_view – how often the progress window is displyaed (every N seconds).

Returns:

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.

classmethod quick_run(sim: wolfgpu.simple_simulation.SimpleSimulation, record_path: pathlib.Path | str, refresh_view: float = 0.1, early_out_threshold=None, gl_wmi: GlWindowManagerInterface = GlWindowManagerInterface.PYGAME, injector: wolfgpu.injector.SimulationInjector | List[wolfgpu.injector.SimulationInjector] = None, tiling: wolfgpu.glsimulation.TilePackingMode = TilePackingMode.REGULAR) wolfgpu.results_store.ResultsStore[source]

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.

Parameters:
  • sim – the simulation you want to run

  • record_path – a directory where to record the results of the simulation. We accept str as well as Path.

  • refresh_view – how often the progress window is displyaed (every N seconds).

  • injector – A SimulationInjector or a list of them.

Returns:

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.

classmethod _finish_quickrun(simulation_runner: SimulationRunner) wolfgpu.results_store.ResultsStore[source]
scanned_file()[source]
restart_from_record(start_rec=None)[source]

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.

Parameters:

start_rec – the index of the record you want to start from. If None, the simulation will restart from the last record.

results_path() pathlib.Path[source]
results_store() wolfgpu.results_store.ResultsStore[source]

Gives a result store back. The result store will be opened in read mode.

record_file()[source]
do_record(texture_ndx, global_state, force=False)[source]

Record current state of the simulation.

Be careful, this implies reading data from the GPU which is slow !

texture_written_by_last_step() int[source]

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).

texture_read_by_last_step() int[source]
run_extra_step()[source]

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.

_check_simulation_is_progressing(h, hu, hv)[source]
_refresh_display_parameters()[source]
_read_simulation_global_state() wolfgpu.glsimulation.GLSimulationGlobalState[source]

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.

_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[source]
_run_all_injectors(source_quantity: int, triggered_timers: set[wolfgpu.sampled_timer.TimeSampler], global_state: wolfgpu.glsimulation.GLSimulationGlobalState) wolfgpu.injector.SimulationProxy[source]
_apply_changes_in_proxy(proxy: wolfgpu.injector.SimulationProxy, source_quantity: int)[source]
run_one_step(dont_close_results: bool = False)[source]

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

Parameters:

dont_close_results – If True, the results store will not be closed

plot_progress2()[source]
file_in_use(f)[source]
_try_reload_bathymetry()[source]
init_result_store()[source]
full_run(refresh_view: int = 1, dont_close_results: bool = False, refresh_colormap: int = 10)[source]

Perform a full simulation run.

Parameters:
  • refresh_view – Refresh the view every refresh_view seconds

  • dont_close_results – Leave the result store open

  • refresh_colormap – Refresh the colormap every refresh_colormap * refresh_view seconds

_admin_tasks(iteration_times: numpy.ndarray, triggered_timers: set, taqadum: tqdm.tqdm)[source]

Perform administrative tasks such as updating the progress bar, compute indicators or reload bathymetry.

_must_continue_event() bool[source]

Check if the simulation was cancelled early by the user or by an early-out condition.

Return bool:

True if the simulation should continue, False if it should stop.

_setup_full_run(refresh_view: int = 1, refresh_update_colormap: int = 10)[source]

Prepare the simulation for a full run.

Parameters:
  • refresh_view – Refresh the view every refresh_view seconds.

  • refresh_update_colormap – Refresh the colormap every refresh_view * refresh_update_colormap seconds.

_teardown_full_run(iteration_times)[source]