Run a simulation in a study

Run a protocol simulation inside a study — the Studies-page flow — against a saved parameterized model, and read its results.

On the Studies page you run a simulation against a saved parameterized model and it's filed under a study. From Python this is the same client.simulation.protocol call, with a study_id so the run shows up on that study's Simulations tab.

Install and authenticate first: pip install ionworks and set IONWORKS_API_KEY and IONWORKS_PROJECT_ID. See the Python API client page.

import ionworks as iw

client = iw.api.Client()

# A study to hold the run (see "Set up a new project"), and the parameterized
# model to simulate (see "Upload a model").
study = client.study.create({"name": "Cycling Test"}, project_id="your-project-id")
parameterized_model_id = "your-parameterized-model-id"

protocol = """
global:
  initial_soc: 1
  temperature: 25
steps:
  - Discharge:
      mode: C-rate
      value: 1
      ends:
        - "Voltage < 2.5"
"""

response = client.simulation.protocol({
    "parameterized_model": parameterized_model_id,
    "protocol_experiment": {"protocol": protocol, "name": "1C discharge"},
    "study_id": study.id,
})
client.simulation.wait_for_completion(response.simulation_id, timeout=120)

result = client.simulation.get_result(response.simulation_id)
print(result.time_series)   # DataFrame: one row per time point
print(result.metrics)       # dict of scalar metrics

What's happening

  • This is the same call as protocol simulations; the study_id files the run under a study, so it appears on that study's Simulations tab in Studio.
  • parameterized_model takes the id of a model you built (see Upload a model), or an inline quick model like {"capacity": 5.0, "chemistry": "NMC/Graphite"} for a throwaway run.
  • Read results with get_result(...) — .time_series, .steps, .metrics. To sweep parameters across many runs, use protocol_batch (see Run protocol simulations).

Learn more

On this page