stochss_compute.server package

Submodules

stochss_compute.server.api module

stochss_compute.server.api

async stochss_compute.server.api.start_api(port=29681, cache='cache/', dask_host='localhost', dask_scheduler_port=8786, rm=False)[source]

Start the REST API with the following arguments.

Parameters:
  • port (int) – The port to listen on.

  • cache (str) – The cache directory path.

  • dask_host (str) – The address of the dask cluster.

  • dask_scheduler_port (int) – The port of the dask cluster.

  • rm (bool) – Delete the cache when exiting this program.

stochss_compute.server.cache module

Cache for StochSS-Compute

class stochss_compute.server.cache.Cache(cache_dir, results_id)[source]

Bases: object

Parameters:
  • cache_dir (str) – The root cache directory.

  • results_id (str) – Simulation hash.

create() None[source]

Create the results file if it does not exist.

exists() bool[source]

Check if the results file exists.

Returns:

os.path.exists(self.results_path)

Return type:

bool

get() Results[source]

Retrieve a gillespy2.Results object from the cache or None if error.

Returns:

Results.from_json(results_json)

Return type:

gillespy2.Results or None

is_empty() bool[source]

Check if the results are empty.

Returns:

filesize == 0 or self.exists()

Return type:

bool

is_ready(n_traj_wanted) bool[source]

Check if the results are ready to be retrieved from the cache.

Parameters:

n_traj_wanted – The number of requested trajectories.

Type:

int

Returns:

n_traj_wanted <= len(<Results in cache>)

Return type:

bool

n_traj_in_cache() int[source]

Check the number of trajectories in the cache.

Returns:

len() of the gillespy2.Results

Return type:

int

n_traj_needed(n_traj_wanted) int[source]
Calculate the difference between the number of trajectories the user has requested

and the number of trajectories currently in the cache.

Parameters:

n_traj_wanted – The number of requested trajectories.

Type:

int

Returns:

A number greater than or equal to zero.

Return type:

int

read() str[source]

Retrieve a gillespy2.Results object as a JSON-formatted string.

Returns:

The output of reading the file.

Return type:

str

save(results: Results) None[source]

Save a newly processed gillespy2.Results object to the cache.

Parameters:

results – The new Results.

Type:

gillespy2.Results

stochss_compute.server.is_cached module

stochss_compute.server.is_cached

class stochss_compute.server.is_cached.IsCachedHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: RequestHandler

Endpoint that will determine if a particular simulation exists in the cache.

async get(results_id=None, n_traj=None)[source]

Process GET request.

Parameters:
  • results_id (str) – Hash of the simulation.

  • n_traj (str) – Number of trajectories to check for.

initialize(cache_dir)[source]

Set cache path.

Parameters:

cache_dir (str) – Path to the cache.

stochss_compute.server.results module

stochss_compute.server.results

class stochss_compute.server.results.ResultsHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: RequestHandler

Endpoint for Results objects.

async get(results_id=None, n_traj=None)[source]

Process GET request.

Parameters:
  • results_id (str) – Hash of the simulation.

  • n_traj (str) – Number of trajectories in the request.

initialize(cache_dir)[source]

Set the cache directory.

Parameters:

cache_dir (str) – Path to the cache.

stochss_compute.server.run module

stochss_compute.server.run

class stochss_compute.server.run.RunHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: RequestHandler

Endpoint for running Gillespy2 simulations.

initialize(scheduler_address, cache_dir)[source]

Sets the address to the Dask scheduler and the cache directory.

Parameters:
  • scheduler_address (str) – Scheduler address.

  • cache_dir (str) – Path to the cache.

async post()[source]

Process simulation run request.

stochss_compute.server.sourceip module

stochss_compute.server.sourceip

class stochss_compute.server.sourceip.SourceIpHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: RequestHandler

Responds with the IP address associated with the request. Used only by cloud api.

post()[source]

Process POST request.

Returns:

request.remote_ip

Return type:

str

stochss_compute.server.status module

stochss_compute.server.status

class stochss_compute.server.status.StatusHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: RequestHandler

Endpoint for requesting the status of a simulation.

async get(results_id=None, n_traj=None, task_id=None)[source]

Process GET request.

Parameters:
  • results_id (str) – Hash of the simulation. Required.

  • n_traj (str) – Number of trajectories in the request. Default 1.

  • task_id (str) – ID of the running simulation. Required.

initialize(scheduler_address, cache_dir)[source]

Sets the address to the Dask scheduler and the cache directory.

Parameters:
  • scheduler_address (str) – Scheduler address.

  • cache_dir (str) – Path to the cache.

Module contents

stochss_compute.server