wolfgpu.results_store

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

wolfgpu.results_store.NB_RESULTS_FILE = 'nb_results.txt'[source]
class wolfgpu.results_store.SimulationEventType[source]

Bases: enum.Enum

Inheritance diagram of wolfgpu.results_store.SimulationEventType

Generic enumeration.

Derive from this class to define new enumerations.

BathymetryUpdate = 'BathymetryUpdate'[source]
class wolfgpu.results_store.ResultType[source]

Bases: enum.Enum

Inheritance diagram of wolfgpu.results_store.ResultType

Enumerate all the possible results types stored in the ResultsStore. Some of these represents scalars, some are numpy arrays.

T = 0[source]

The simulation time (the time inside the simulation).

LAST_DELTA_T = 1[source]

The last Δt computed at the moment the record is taken.

DRYUP_NITER = 2[source]
NB_ACTIVE_TILES = 3[source]

The number of active tiles in the simulation. An active tile is a tile where there is some water.

STEP_NUM = 4[source]

The number of the simulation step.

CLOCK_T = 5[source]

The time spent into the simulation (wall clock time)

DELTA_EARLY_OUT = 6[source]

The delta early out is an approximate measurement of the “stabilisation” of the simulation. It is computed like so:

\(\Delta S = S_{i+1} - S_i\) where \(S_i = \sum_{\text{m in all meshes}} |m_h| + |m_{q_x}| + |m_{q_y}|\)

In other words, the rate of change between two successive recordings computed over \(h,qx,qy\) of each mesh individually.

NB_MOSTLY_DRY_MESHES = 7[source]

Number of mostly dry mesh. A mostly dry mesh is a mesh where water height is not zero but very small (< 1e-5 m).

NB_WET_MESHES = 8[source]

Number of wet meshes. A wet mesh is a mesh where water height is above zero.

H = 106[source]

Water height.

QX = 107[source]

Water discharge along X axis.

QY = 108[source]

Water discharge along Y axis.

ALPHA = 109[source]

Information about dry ups (α’s and masks)

DEBUG1 = 110[source]

Debug arrays.

classmethod _from_str(s)[source]
class wolfgpu.results_store.SimulationEvent(event_type: SimulationEventType, simulation_time: float, simulation_step: int, data=None)[source]
property simulation_step[source]
property simulation_time[source]
file_content()[source]

Return the file content of the event. In case of a BathymetryUpdate event, returns the numpy array used for the update.

Note: we return the file content because we make no guarantees on the fact that the file can actually be read from the disk like a regular file (because we may zip it).

_inject_parent_store(store)[source]
to_dict()[source]
wolfgpu.results_store.array_to_bytes(x: numpy.ndarray) bytes[source]
wolfgpu.results_store.bytes_to_array(b: bytes) numpy.ndarray[source]
class wolfgpu.results_store.ResultsStore(sim_path: pathlib.Path, mode: str = 'a', tile_packer: wolfgpu.tile_packer.TilePacker = None)[source]

A ResultsStore is a tiny container meant to hold the results of a simulation. It gives several ways to query the results easily.

property creation_time[source]
property nb_results[source]

The number of results currently stored in the result store. The last result’s index is this value.

property path: pathlib.Path[source]

Returns the path where the result store is located. It is either a directory or a path to a zip-file.

property _first_row_len[source]

Returns the number of columns in the first row of the CSV file.

This is useful to know if the CSV file has been updated with new columns that we don’t know about yet.

_dir: pathlib.Path[source]
_load_current_data()[source]
reload(only_if_changed: bool = True)[source]

Reloads this result store.

If only_if_changed is True (the default), the store will be reloaded only if its number of results has changed (compared to what it was when first opened). If False, the store will be reloaded forcefully. Reloading only makes sense in ‘r’ (read) mode.

This method can be used to track the growth of a result store while it is populated by the simulator.

truncate_at_report(n: int)[source]

Kill records from n+1 (included) to the last one n is one based !

_update_track_files()[source]
close()[source]
make_a_copy(dest_path: str | pathlib.Path) ResultsStore[source]

Make a copy of the result store and put it in the given path.

Parameters:

dest_path – where to put the copy.

Returns:

the copy of the results store, open in read only mode.

append_result(step_num: int, sim_time: float, dt: float, niter: int, niter_rk: int, h: numpy.ndarray, qx: numpy.ndarray, qy: numpy.ndarray, dbg1: numpy.ndarray = None, dbg2: numpy.ndarray = None, clock_time: float = 0, delta_early_out: float = 0, nb_mostly_dry_meshes: int = 0)[source]
append_additional_result(name, data: numpy.ndarray)[source]

One can store additional results which have their own names (so they don’t belong to the ResultType). For now this is limited to numpy arrays.

This function is a hack to help debugging. Don’t use it !!!

add_event(event_type: SimulationEventType, simulation_time=float, simulation_step=int, data=None)[source]

Record a simulation event. - simulation_time is expressed in seconds - simulation_step is of course an unsigned integer

For BathymetryUdate event you must pass the a Path to the bathymetry update file (which will be copied into the result store).

get_events_between_steps(first_step: int, last_step: int) list[SimulationEvent][source]

Query the events that sits between the given first/last simulation steps.

Parameters:
  • first_step – the first simulation steps to consider (1-based)

  • last_step – the last simulation steps to consider (1-based)

get_last_result_index() int[source]

Get the index of the last result in in this result store. The index can be used to query data in the store.

get_last_result(ndx=0) tuple[float, float, int, int, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

returns [t,dt,n_iter_dry_up_euler, n_iter_dry_up_rk, h,qx,qy]

get_result(ndx: int) tuple[float, float, int, int, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

returns [t, dt, n_iter_dry_up_euler, n_iter_dry_up_rk, h, qx, qy]

get_last_named_result(name: str | list[str], delta_ndx: int = 0) numpy.ndarray | list[numpy.ndarray][source]
Get the last result by name(s). The names are those accepted by

get_named_result. delta_ndx means an offset to be added to the last index so that you can count backward fro the last index (so it’s always negative). For example a value of -2 means you’ll take the third result starting from the last one. A value of 0 means you take the last one.

You can call this like this: - get_last_named_result(“qy”) - get_last_named_result( “h”, “qy”) - get_last_named_result( [ “h”, “qy” ]) - get_last_named_result( [ “h”, “qy”, ResultType.QX ])

_is_result_type_in_database(rt: ResultType)[source]
get_named_series(name: str | ResultType) list[source]

Returns the series of all recordings of the value identified by the name parameter.

Currently only works for scalar values (i.e. not matrices).

get_additional_named_result(name: str, ndx: int) numpy.ndarray[source]
get_named_result(name: str | list[str] | ResultType | list[ResultType], ndx: int) numpy.ndarray | list[numpy.ndarray][source]

Looks for result by names.

Parameters:
  • name – Supported names are: t, last_delta_t, step_num, h, qx, qy. You can also use ResultType.

  • ndx – Result number. 1-based.

get_result_index_at_t(t)[source]

Get index of the result closest to time t.

_init_filesystem_for_reading(mode)[source]
_init_filesystem_for_writing()[source]
_writestr(fname, s)[source]
_delete_file(fname: pathlib.Path)[source]
_write_file_copy(fname_src: pathlib.Path, fname_dest: str)[source]
_write_numpy(fname, a)[source]
_read(fname)[source]
_read_numpy(fname)[source]
_source_path()[source]