stochss_compute.core package

Submodules

stochss_compute.core.errors module

stochss_compute.core.errors

exception stochss_compute.core.errors.CacheError[source]

Bases: Exception

General cache error.

exception stochss_compute.core.errors.RemoteSimulationError[source]

Bases: Exception

General simulation error.

stochss_compute.core.messages module

stochss_compute.core.messages

class stochss_compute.core.messages.Request[source]

Bases: ABC

Base class.

abstract encode()[source]

Encode self for http.

abstract static parse(raw_request)[source]

Parse http for python.

class stochss_compute.core.messages.Response[source]

Bases: ABC

Base class.

abstract encode()[source]

Encode self for http.

abstract static parse(raw_response)[source]

Parse http for python.

class stochss_compute.core.messages.ResultsRequest(results_id)[source]

Bases: Request

Request results from the server.

Parameters:

results_id (str) – Hash of the SimulationRunRequest

encode()[source]
Returns:

self.__dict__

Return type:

dict

static parse(raw_request)[source]

Parse HTTP request.

Parameters:

raw_request (dict[str, str]) – The request.

Returns:

The decoded object.

Return type:

ResultsRequest

class stochss_compute.core.messages.ResultsResponse(results=None)[source]

Bases: Response

A response from the server about the Results.

Parameters:

results (str) – The requested Results from the cache. (JSON)

encode()[source]
Returns:

self.__dict__

Return type:

dict

static parse(raw_response)[source]

Parse HTTP response.

Parameters:

raw_response (dict[str, str]) – The response.

Returns:

The decoded object.

Return type:

ResultsResponse

class stochss_compute.core.messages.SimStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Status describing a remote simulation.

DOES_NOT_EXIST = 'There is no evidence of this simulation either running or on disk.'
ERROR = 'The Simulation has encountered an error.'
PENDING = 'The simulation is pending.'
READY = 'Simulation is done and results exist in the cache.'
RUNNING = 'The simulation is still running.'
static from_str(name)[source]

Convert str to Enum.

class stochss_compute.core.messages.SimulationRunRequest(model, **kwargs)[source]

Bases: Request

A simulation request.

Parameters:
  • model (gillespy2.Model) – A model to run.

  • kwargs (dict[str, Any]) – kwargs for the model.run() call.

encode()[source]

JSON-encode model and then encode self to dict.

hash()[source]

Generate a unique hash of this simulation request. Does not include number_of_trajectories in this calculation.

Returns:

md5 hex digest.

Return type:

str

static parse(raw_request)[source]

Parse HTTP request.

Parameters:

raw_request (dict[str, str]) – The request.

Returns:

The decoded object.

Return type:

SimulationRunRequest

class stochss_compute.core.messages.SimulationRunResponse(status, error_message=None, results_id=None, results=None, task_id=None)[source]

Bases: Response

A response from the server regarding a SimulationRunRequest.

Parameters:
  • status (SimStatus) – The status of the simulation.

  • error_message (str | None) – Possible error message.

  • results_id (str | None) – Hash of the simulation request. Identifies the results.

  • results (str | None) – JSON-Encoded gillespy2.Results

encode()[source]

Encode self to dict.

static parse(raw_response)[source]

Parse HTTP response.

Parameters:

raw_response (dict[str, str]) – The response.

Returns:

The decoded object.

Return type:

SimulationRunResponse

class stochss_compute.core.messages.SourceIpRequest(cloud_key)[source]

Bases: Request

Restrict server access.

Parameters:

cloud_key (str) – Random key generated locally during launch.

encode()[source]
Returns:

self.__dict__

Return type:

dict

static parse(raw_request)[source]

Parse HTTP request.

Parameters:

raw_request (dict[str, str]) – The request.

Returns:

The decoded object.

Return type:

SourceIpRequest

class stochss_compute.core.messages.SourceIpResponse(source_ip)[source]

Bases: Response

Response from server containing IP address of the source.

Parameters:

source_ip (str) – IP address of the client.

encode()[source]
Returns:

self.__dict__

Return type:

dict

static parse(raw_response)[source]

Parses a http response and returns a python object.

Parameters:

raw_response (str) – A raw http SourceIpResponse from the server.

Returns:

The decoded object.

Return type:

SourceIpResponse

class stochss_compute.core.messages.StatusRequest(results_id)[source]

Bases: Request

A request for simulation status.

Parameters:

results_id (str) – Hash of the SimulationRunRequest

encode()[source]
Returns:

self.__dict__

Return type:

dict

static parse(raw_request)[source]

Parse HTTP request.

Parameters:

raw_request (dict[str, str]) – The request.

Returns:

The decoded object.

Return type:

StatusRequest

class stochss_compute.core.messages.StatusResponse(status, message=None)[source]

Bases: Response

A response from the server about simulation status.

Parameters:
  • status (SimStatus) – Status of the simulation

  • message (str) – Possible error message or otherwise

encode()[source]

Encodes self. :returns: self as dict :rtype: dict[str, str]

static parse(raw_response)[source]

Parse HTTP response.

Parameters:

raw_response (dict[str, str]) – The response.

Returns:

The decoded object.

Return type:

StatusResponse

stochss_compute.core.remote_results module

stochss_compute.core.remote_results

class stochss_compute.core.remote_results.RemoteResults(data=None)[source]

Bases: Results

Wrapper for a gillespy2.Results object that exists on a remote server and which is then downloaded locally. A Results object is: A List of Trajectory objects created by a gillespy2 solver, extends the UserList object.

These three fields must be initialized manually: id, server, n_traj, task_id.

Parameters:
  • data (UserList) – A list of trajectory objects.

  • id (str) – ID of the cached Results object.

  • server (stochss_compute.ComputeServer) – The remote instance of StochSS-Compute where the Results are cached.

  • task_id (str) – Handle for the running simulation.

property data

The trajectory data.

Returns:

self._data

Return type:

UserList

get_gillespy2_results()[source]

Get the GillesPy2 results object from the remote results.

Returns:

The generated GillesPy2 results object.

Return type:

gillespy.Results

id = None
property is_ready

True if results exist in cache on the server.

Returns:

status == SimStatus.READY

Return type:

bool

n_traj = None
server = None
property sim_status

Fetch the simulation status.

Returns:

Simulation status enum as a string.

Return type:

str

task_id = None

stochss_compute.core.remote_simulation module

RemoteSimulation

class stochss_compute.core.remote_simulation.RemoteSimulation(model, server=None, host: str = None, port: int = 29681, solver=None)[source]

Bases: object

An object representing a remote gillespy2 simulation. Requires a model and a host address. A solver type may be provided, but does not accept instantiated solvers.

Parameters:
  • model (gillespy2.Model) – The model to simulate.

  • server (stochss_compute.Server) – A server to run the simulation. Optional if host is provided.

  • host (str) – The address of a running instance of StochSS-Compute. Optional if server is provided.

  • port (int) – The port to use when connecting to the host. Only needed if default server port is changed. Defaults to 29681.

  • solver (gillespy2.GillesPySolver) – The type of solver to use. Does not accept instantiated solvers.

is_cached(**params)[source]

Checks to see if a dummy simulation exists in the cache.

Parameters:

params (dict[str, Any]) – Arguments for simulation.

Returns:

If the results are cached on the server.

Return type:

bool

run(**params)[source]

Simulate the Model on the target ComputeServer, returning the results or a handle to a running simulation.

See here.

Parameters:

params (dict[str, Any]) – Arguments to pass directly to the Model#run call on the server.

Returns:

RemoteResults populated with Results if cached, otherwise and unpopulated RemoteResults

Return type:

RemoteResults

Raises:

RemoteSimulationError – In the case of SimStatus.ERROR

Module contents

stochss_compute.core