Skip to main content
Version: 1.3.4

SDK

The SDK allows you to trigger and retreive information about a simulation. The CLI might be an easier way of doing this if you're not using a notebook or creating automated systems on top of the simulator. To read more about that go here.

Requirement

  • Authenticated gcloud cli running
gcloud auth application-default login
  • Set the default project-id
gcloud config set project almanak-production

Installation

Add this to ~/.pypirc

[distutils]
index-servers =
almanak-py

[almanak-py]
repository: https://europe-west4-python.pkg.dev/almanak-production/almanak-py/

Make sure this is in the pip.conf file of which the location you can fine here. (If the file is in the wrong location it won't work, for me it's ~/.config/pip/pip.conf )

[global]
extra-index-url = https://europe-west4-python.pkg.dev/almanak-production/almanak-py/simple/

If this is set you can do

pip install keyrings.google-artifactregistry-auth
pip install almanak-simulations-sdk

Functions

Create

from almanak.simulations.sdk import create

create()
ParamaterTypeExample
stagingboolFalse
parameterlist[tuple][('swapping_fees_ETH_2', '0.002')]
parameters_as_jsonstr'[{"name": "swapping_fees_ETH_1", "value": 0.002}]'
gcs_linkstr'gs://almanak-simulations-prod/test-folder/test-file'
sim_idstr'a2ddba31-3736-4897-a28d-beb116f19778'
pathstr'.'

Please note that the sim_id paramater has to be a UUIDv4 with the first character as a lowercase letter. Any parameter set using the parameters_as_json will be overwitten by any parameter set through parameter. The function expects local files to upload in the current working directory except for if the gcs_link is specified.

Returns the id of the created simulation.

Get

from almanak.simulations.sdk import create

get('a2ddba31-3736-4897-a28d-beb116f19778')
ParamaterTypeExample
stagingboolFalse
sim_idstr'a2ddba31-3736-4897-a28d-beb116f19778'

Returns an instance of the class SimulationGetResult.

id: str
status: str
storage_url: str
result: str | None
errorLog: str | None

The status variable can be used to debug where your simulation is in the execution pipeline. When status has the value UPLOADED, the documents have been uploaded to google cloud storage via a create, but the simulation run has not been submitted to be run on google cloud batch. Once the simulation has been submitted to google cloud batch, the value of status will be updated to the job state of the batch job. Such values can be STATE_UNSPECIFIED, QUEUED, SCHEDULED, RUNNING, SUCCEEDED, FAILED, DELETION_IN_PROGRESS.

Result

from almanak.simulations.sdk import create

result('a2ddba31-3736-4897-a28d-beb116f19778')
ParamaterTypeExample
stagingboolFalse
sim_idstr'a2ddba31-3736-4897-a28d-beb116f19778'

Returns the result as an array. The result is defined by the reward function in the simulator.

Logs

from almanak.simulations.sdk import create

logs('a2ddba31-3736-4897-a28d-beb116f19778')
ParamaterTypeExample
sim_idstr'a2ddba31-3736-4897-a28d-beb116f19778'

Returns a generator (using yield) which you can loop over to read the logs.

Metrics

from almanak.simulations.sdk import create

get_metrics('a2ddba31-3736-4897-a28d-beb116f19778', 'postgres', 'postgres', '0.0.0.0', 5432)
ParamaterTypeExample
stagingboolFalse
sim_idstr'a2ddba31-3736-4897-a28d-beb116f19778'
postgres_userstrpostgres
postgres_passwordstrpostgres
postgres_hoststr'0.0.0.0'
postgres_portint5432

Returns a generator (using yield) tuple for the values of the metrics.