Basic Simulation Operations

View as Markdown
# Imports (run once)
from typing import Iterator
from air_sdk import AirApi
from air_sdk.endpoints import Simulation
# Authentication (run once)
api = AirApi.with_ngc_config()
# OR api = AirApi.with_api_key(api_key="...")
# OR api = AirApi.with_device_login(email="...", org_num="...")
# ^ use in terminal only — not supported in Jupyter notebooks

Create

Creating a blank simulation

sim: Simulation = api.simulations.create(name='My First Simulation')
sim.dict()
{'id': '9c74b09e-0782-4f24-bea0-d3028c2d1fed',
'name': 'My First Simulation',
'created': datetime.datetime(2025, 4, 7, 21, 54, 46, 20075, tzinfo=datetime.timezone.utc),
'modified': datetime.datetime(2025, 4, 7, 21, 54, 48, 20076, tzinfo=datetime.timezone.utc),
'state': 'INACTIVE',
'auto_oob_enabled': False,
'disable_auto_oob_dhcp': False,
'sleep_at': None,
'expires_at': None,
'documentation': None,
'complete_checkpoint_count': 0,
'metadata': None}

Update

Updating fields on an existing simulation

sim_id = '...' # replace with actual sim id
sim: Simulation = api.simulations.get(sim_id)
sim.update(name='My Updated Simulation')
print(sim.name)

Delete

Deleting a simulation

sim_id = '...' # replace with actual sim id
sim: Simulation = api.simulations.get(sim_id)
sim.delete()
assert sim.id is None

List/Get

Listing and retrieving simulations

The AirApi offers a convenient way to access a paginated collection of simulation objects. This API returns an iterator composed of Simulation objects, allowing for efficient data handling. If you wish to work with all simulations at once, you can easily convert this iterator into a list by using the list function. Alternatively, you can choose to process each simulation individually by iterating over the iterator directly. This flexibility enables you to handle simulation data in a manner that best suits your specific needs and workflow.

simulations: Iterator[Simulation] = api.simulations.list()
sim_list: list[Simulation] = list(simulations)
# Query parameters may be provided to the list method
active_simulations: Iterator[Simulation] = api.simulations.list(
state='ACTIVE',
ordering='created',
)
# Individual simulations may be retrieved by ID
sim_id = '...' # replace with actual sim id
sim: Simulation = api.simulations.get(sim_id)