wolfgpu.sampled_timer
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.sampled_timer.TimeSamplingStrategy[source]
Bases:
enum.Enum
When a simulation is run, interrogating the GPU is costly. Therefore we interrogate it not at each step but on a regular basis. This enumeration describes the various strategies of interrogation.
When reporting, the sync time is a multiple of
- class wolfgpu.sampled_timer.TimeSampler(strategy: TimeSamplingStrategy, name: str = None)[source]
Example: - read GPU every 100 iterations - report every 111 iterations - update bathymetry every 3 seconds +/-.
To solve this we make three timelines: - read at 100, 200, 300,… - read at 111, 222, 333,… - read at 3s, 6.25, 8,75,…
For the first two time lines, knowing the current iteration allows to know when the next stop is. For the third one, only a planner knows.
- property strategy: TimeSamplingStrategy[source]
- classmethod make_one_shot_timer(period: wolfgpu.glsimulation.SimulationDuration, name=None) TimeSampler [source]
A one-shot timer which have a fixed period. Fixed means you can’t change it over time.
- Parameters:
period – If int then the period is expressed as a number of iterations. If timedelta then the period is expressed as a number of seconds.
- classmethod make_dynamic_timer(query_function: Callable, duration_type: wolfgpu.glsimulation.SimulationDurationType, name=None) TimeSampler [source]
A timer which has a varying period. To know the time to next timer trigger time, the caller must provide a query function that will tell us how long to wait before the next trigger in function of the current time/iteration.
- Parameters:
duration_type – The type of duration used by this timer. This must be constant over time (so you can’t go from steps to time or vice versa).
- classmethod make_periodic_wall_clock_timer(period, triggers_on_zero=False, name: str = None)[source]
A timer which triggers every period seconds (seconds are wall clock seconds, not simulation seconds).
- Parameters:
period – Either a timedelta or a SimulationDuration.
- classmethod make_periodic_timer(period: wolfgpu.glsimulation.SimulationDuration, name=None) TimeSampler [source]
A recurring timer which have a fixed period.
- Parameters:
period – If int then the period is expressed as a number of iterations. If timedelta then the period is expressed as a number of seconds.
- class wolfgpu.sampled_timer.TimerManager(sampling_period: int)[source]
-
- ticker() TimeSampler [source]
- _remove_strategy(strategy: TimeSampler)[source]
- add_strategy(time_sampler: TimeSampler)[source]
- set_simulation_time_steps(steps)[source]
Set the simulation times steps database that can be used to estimate the next iteration upon which a time sampler must be triggered.
- Parameters:
steps – A collection of simulation step durations (in seconds).
- _estimate_iterations_for_duration(seconds)[source]
Try to convert a time into a number of iterations using past knowledge.
We use two databases to do that. The first one is built in this manager based on the iteration/times provided to it when querying/updating its state. It’s not very accurate. The second one is a list of time steps which is provided by the caller whenever it has up to date data. It’s meant to be more accurate.
- update_one_shot_timer(timer: TimeSampler, new_period: wolfgpu.glsimulation.SimulationDuration, current_iteration, current_time)[source]
- _reevaluate_time_samplers(current_iteration, current_time)[source]
Reevaluate the iteration that is planned for the trigger of each “time” (instead of “iterations”) timers. We do that systematically, that is as often as possible.
- update_clock_wall_timers()[source]
Update the wall clock timers.
The wall clock timers being based on the real passage of time, they must be checked more often than the timers inside a simulation to be accurate. Since querying timers inside simulation is very expensive, we moved the clock wall timer update here, outside the more general timers update mechanism (in the update() method). This way, they can be updated as fast as needed without updating the more expensive simulation timers.
- Returns:
The set of wall clock timers that have triggered.
- update(current_iteration: int, current_time) set[TimeSampler] [source]
Update all timers.
- Returns:
The set of timers that have triggered.