OpenCL microsim model

Submodules

ramp.activity module

class microsim.opencl.ramp.activity.Activity(value)

Bases: enum.Enum

An enumeration.

Home = 0
PrimarySchool = 2
Retail = 1
SecondarySchool = 3
Work = 4

ramp.buffers module

class microsim.opencl.ramp.buffers.Buffers(place_activities, place_coords, place_hazards, place_counts, people_ages, people_obesity, people_cvd, people_diabetes, people_blood_pressure, people_statuses, people_transition_times, people_place_ids, people_baseline_flows, people_flows, people_hazards, people_prngs, params)

Bases: tuple

property params

Alias for field number 16

property people_ages

Alias for field number 4

property people_baseline_flows

Alias for field number 12

property people_blood_pressure

Alias for field number 8

property people_cvd

Alias for field number 6

property people_diabetes

Alias for field number 7

property people_flows

Alias for field number 13

property people_hazards

Alias for field number 14

property people_obesity

Alias for field number 5

property people_place_ids

Alias for field number 11

property people_prngs

Alias for field number 15

property people_statuses

Alias for field number 9

property people_transition_times

Alias for field number 10

property place_activities

Alias for field number 0

property place_coords

Alias for field number 1

property place_counts

Alias for field number 3

property place_hazards

Alias for field number 2

ramp.disease_statuses module

class microsim.opencl.ramp.disease_statuses.DiseaseStatus(value)

Bases: enum.Enum

An enumeration.

Asymptomatic = 3
Dead = 6
Exposed = 1
Presymptomatic = 2
Recovered = 5
Susceptible = 0
Symptomatic = 4

ramp.inspector module

class microsim.opencl.ramp.inspector.Inspector(simulator, snapshot, nlines, window_name, width, height, font_path='microsim/opencl/fonts/RobotoMono.ttf')

Bases: object

User Interface: manager for all user input and rendering for the application.

draw()

Renders the UI.

draw_controls_window(width, height)
draw_grid()

Draws a full screen quad with a grid in the pixel shader.

draw_imgui()

Draws the ImGui overlay.

draw_layers_window(width, height)
draw_lines()

Draws a line between each connected location colored by hazards.

draw_parameters_window()

UI window with sliders for changing parameter values.

draw_platform_window(width, height)
draw_points()

Draws a point for each location colored by its hazard.

draw_saveas_window(width, height)
draw_snapshots_window(width, height)
draw_timeseries_window(width, height)
is_active()

Cycles a frame and returns whether the window remains open.

Returns:

True if the application is still open, otherwise False.

is_pressed(key)
key_callback(window, key, scancode, action, mods)

Callback for keyboard controls that must fire exactly once.

resize_callback(window, width, height)

Framebuffer resize callback.

update()

Update loop for running the simulation and updating/rendering the UI.

update_camera()
update_font_scale(font_scale)

Updates the imgui font scale, starts out at 0.5

update_sim()

Run a step of the simulation.

upload_hazards(hazards)

Transfers the contents of hazards to the hazards vertex buffer.

Args:

hazards: A numpy array of nplaces uint32 hazards.

Transforms the 1D place_ids buffer into a 1d element buffer and uploads it.

Args:

place_ids: A numpy array of npeople*nslots uint32 place IDs.

upload_locations(locations, lat=50.7184, lon=- 3.5339)

Reprojects the lat lons around the provided one and uploads them to OpenGL.

Args:

locations: A numpy array of 2 * nplaces float32 lat/lons. lat: The latitude to transform the coordinates around. lon: The longitude to transform the coordinates around.

ramp.kernels module

class microsim.opencl.ramp.kernels.Kernels(places_reset, people_update_flows, people_send_hazards, people_recv_hazards, people_update_statuses)

Bases: tuple

property people_recv_hazards

Alias for field number 3

property people_send_hazards

Alias for field number 2

property people_update_flows

Alias for field number 1

property people_update_statuses

Alias for field number 4

property places_reset

Alias for field number 0

ramp.opencl_dashboard module

Created on Thu Jun 4 16:22:57 2020

@author: Natalie

ramp.params module

class microsim.opencl.ramp.params.IndividualHazardMultipliers(presymptomatic, asymptomatic, symptomatic)

Bases: tuple

property asymptomatic

Alias for field number 1

property presymptomatic

Alias for field number 0

property symptomatic

Alias for field number 2

class microsim.opencl.ramp.params.LocationHazardMultipliers(retail, primary_school, secondary_school, home, work)

Bases: tuple

property home

Alias for field number 3

property primary_school

Alias for field number 1

property retail

Alias for field number 0

property secondary_school

Alias for field number 2

property work

Alias for field number 4

class microsim.opencl.ramp.params.Params(location_hazard_multipliers=LocationHazardMultipliers(retail=0.00655, primary_school=0.00655, secondary_school=0.00655, home=0.00655, work=0.00655), individual_hazard_multipliers=IndividualHazardMultipliers(presymptomatic=1.0, asymptomatic=0.25, symptomatic=1.0), obesity_multipliers=[1, 1.48, 1.48, 1.48], cvd_multiplier=1, diabetes_multiplier=1, bloodpressure_multiplier=1, overweight_sympt_mplier=1, warn=True)

Bases: object

Convenience class for setting simulator parameters. Also holds the hard-coded default values (these defaults should not usually be used; parameters should be read from the parameters file)

asarray()

Pack the parameters into a flat array for uploading.

classmethod fromarray(params_array)
num_bytes()
set_lockdown_multiplier(lockdown_multipliers, timestep)

Update the lockdown multiplier based on the current time.

ramp.projections module

microsim.opencl.ramp.projections.latlon_to_km(locations, lat, lon)

Reprojects a numpy array of lat/lon locations to km offset from lat and lon.

This is a local approximation around the provided center point, so should only be used over relatively small latitude ranges.

Args:

locations: A numpy array of 2 * nplaces float32 lat/lons. lat: The latitude to transform the coordinates around. lon: The longitude to transform the coordinates around.

ramp.run module

microsim.opencl.ramp.run.run_headless(simulator, snapshot, iterations, quiet, store_detailed_counts=True)

Run the simulation in headless mode and store summary data. NB: running in this mode is required in order to view output data in the dashboard. Also store_detailed_counts must be set to True to output the required data for the dashboard, however the model runs faster with this set to False.

microsim.opencl.ramp.run.run_opencl(snapshot, iterations=100, data_dir='./data', use_gui=True, use_gpu=False, num_seed_days=5, quiet=False)

Entry point for running the OpenCL simulation either with the UI or in headless mode. NB: in order to write output data for the OpenCL dashboard you must run in headless mode.

microsim.opencl.ramp.run.run_with_gui(simulator, snapshot)
microsim.opencl.ramp.run.store_summary_data(summary, store_detailed_counts, data_dir)

ramp.shader module

microsim.opencl.ramp.shader.load_shader(shader_name)

Loads, compiles and links vertex and fragment OpenGL shaders with this name.

Args:

shader_name: Name of the shader to compile.

Returns:

program: Compiled OpenGL shader program.

ramp.simulator module

class microsim.opencl.ramp.simulator.Simulator(snapshot, gpu=True, opencl_dir='microsim/opencl/', num_seed_days=5)

Bases: object

Class to manage all OpenCL owned simulator state. Including methods to transfer data buffers to/from OpenCL devices and a step() method to execute the kernels to calculate one timestep of the model.

device_name()

The name of the OpenCL device being used for simulation.

download(name, host_buffer)

Transfers the contents of the named OpenCL buffer to the provided numpy array.

download_all(host_buffers)

Downloads every device buffer, errors if host_buffers is missing a field.

Args:

host_buffers: A dict of string names to numpy buffers.

platform_name()

The name of the OpenCL platform being used for simulation.

step()

Choose whether to run the normal step function or the one for initial case seeding

step_all_kernels()

Runs each kernel in order and updates the time. Blocks until complete.

step_kernel(name)

Run a single kernel specified by name. NB: this is intended only to be used for testing.

step_with_seeding()

For initial case seeding: sets a number of people infected based on the initial cases data, then runs only the kernel which updates people statuses.

upload(name, host_buffer)

Transfers the contents of the provided numpy array to the named OpenCL buffer.

upload_all(host_buffers)

Upload to every device buffer, errors if host_buffers is missing a field.

Args:

host_buffers: A Buffers namedtuple containing numpy arrays.

ramp.snapshot module

class microsim.opencl.ramp.snapshot.Snapshot(nplaces, npeople, nslots, time, area_codes, not_home_probs, lockdown_multipliers, buffers, name='cache')

Bases: object

Thin wrapper around the .npz file format for saving/loading snapshots. This enables loading existing snapshots from file, or generating new snapshots full of random data or zeros. It also has a function for seeding initial infections in the population. Each snapshot consists of the data buffers used by OpenCL, as well as additional static data about the population which is not used in the runtime simulation but may be used for seeding infections at the snapshot stage.

classmethod from_arrays(people_ages, people_obesity, people_cvd, people_diabetes, people_blood_pressure, people_place_ids, people_baseline_flows, area_codes, not_home_probs, place_activities, place_coords, lockdown_multipliers)
classmethod load_full_snapshot(path)

Creates a snapshot by reading the .npz file from the provided path.

num_bytes()

Returns size in bytes of this snapshot.

classmethod random(nplaces, npeople, nslots, lat=50.7, lon=- 3.5)

Generates a random snapshot for testing in a 1 degree square around lat/lon.

sanitize_coords()

Sets all zero coordinate to nan so they can be discarded by the renderer.

save(path)

Saves this snapshot to the provided path as a .npz file.

seed_prngs(seed)

Recomputes the random states of the PRNGs passed to the kernels. The simulator runs deterministically for the same snapshot state, so calling this function gives new PRNG values to get enable stochastic results for different runs.

switch_to_healthier_population()

Updates to a healthier population by reducing obesity. Any individuals that are overweight or obese are moved to the level of obesity below their current one, by subtracting 1.

update_params(new_params)
classmethod zeros(nplaces, npeople, nslots)

Creates a snapshot with correctly sized but zeroed arrays.

ramp.snapshot_convertor module

class microsim.opencl.ramp.snapshot_convertor.SnapshotConvertor(individuals, activity_locations, time_activity_multiplier, data_dir)

Bases: object

Convert dataframe of individuals and activity locations into a Snapshot object that can be used by the OpenCL model

create_global_place_ids()
generate_snapshot()
get_coordinates_from_buildings(home_locations_df)
get_global_place_id(activity_name, local_place_id)
get_not_home_probs()
get_people_ages()
get_people_area_codes()
get_people_blood_pressure()
get_people_cvd()
get_people_diabetes()
get_people_obesity()
get_people_place_data(max_places_per_person=100, places_to_keep_per_person=16)

Calculate the “baseline flows” for each person by multiplying flows for each location by duration, then sorting these flows and taking the top n so they can fit in a fixed size array. Locations from all activities are contained in the same array so the activity specific location ids are mapped to global location ids.

Parameters
  • max_places_per_person – upper limit of places per person so we can use a fixed size array

  • places_to_keep_per_person

Returns

Numpy arrays of place ids and baseline flows indexed by person id

get_place_coordinates()
get_place_data()
microsim.opencl.ramp.snapshot_convertor.get_obesity_value(bmi_vg6_str)

ramp.style module

microsim.opencl.ramp.style.set_styles(style)

Applies the styling for the imgui UI.

ramp.summary module

class microsim.opencl.ramp.summary.Summary(snapshot, store_detailed_counts=False, max_time=365)

Bases: object

Class to hold the aggregate timeseries data for the simulation. Stores and visualises time series of counts of each disease status.

draw_plots(time, size)

Given current time and graph size, draw the imgui plots.

get_age_dataframes()
get_area_dataframes()
get_df_columns()
print_counts(time)

Print out the counts at time to stdout.

update(time, statuses)

Given an array of status enums, compute and save counts.

Module contents