Basic Simulation Operations#

Author: Sam Eure

April 4, 2025

Create#

Creating a blank simulation

[ ]:
from air_sdk import AirApi
from air_sdk.endpoints import Simulation

api = AirApi.with_ngc_config()
# Or use SAK directly
# api = AirApi.with_api_key(api_key='nvapi-xyz')

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, 46, 20091, tzinfo=datetime.timezone.utc),
 'state': 'INACTIVE',
 'auto_oob_enabled': False,
 'netq_auto_enabled': False}

Update#

Updating fields on an existing simulation

[ ]:
from air_sdk.endpoints import 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

[12]:
from air_sdk.endpoints import 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.

[ ]:
from typing import Iterator

from air_sdk.endpoints import Simulation

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)