Starting and Stopping Simulations#
Author: Sam Eure
May 28, 2025
[ ]:
# Imports (run once)
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 a new simulation#
[ ]:
json_data = {
'format': 'JSON',
'name': 'JSON Sim',
'content': {
'nodes': {
'node1': {
'cpu': 2,
'memory': 1024,
'storage': 10,
'os': 'generic/ubuntu2204',
'cpu_arch': 'x86',
},
},
'oob': False,
},
}
sim: Simulation = api.simulations.import_from_data(**json_data)
sim.wait_for_state('INACTIVE', error_states='INVALID')
Start the simulation#
Request that the simulation be started. If successful, the simulation will transition from INACTIVE → REQUESTING → PROVISIONING → PREPARE_BOOT → BOOTING → ACTIVE.
[ ]:
sim.start()
sim.wait_for_state('ACTIVE', error_states='INACTIVE')
sim.state
'ACTIVE'
Shut down the simulation#
Request that the simulation be shut down. If successful, the simulation will transition from ACTIVE → PREPARE_SHUTDOWN → SHUTTING_DOWN → SAVING → INACTIVE.
[ ]:
sim.shutdown()
sim.wait_for_state('INACTIVE')
for history in list(sim.get_history()):
print(history.description)
Transitioning from `SAVING` to `INACTIVE` state.
Checkpoint `Checkpoint 2026-03-11 18:36:14` has been successfully saved.
Transitioning from `SHUTTING_DOWN` to `SAVING` state.
Simulation `JSON Sim` with ID `c0b5e717-9bd1-46dd-84c3-fdd323b32cb2` created by importing a topology in `JSON` format. Topology is scheduled for validation.
Initiating topology validation.
Validation complete. Initiating creation of simulation objects.
Topology successfully imported.
Transitioning from `IMPORTING` to `INACTIVE` state.
Transitioning from `INACTIVE` to `REQUESTING` state.
Transitioning from `REQUESTING` to `PROVISIONING` state.
Transitioning from `PROVISIONING` to `PREPARE_BOOT` state.
Transitioning from `PREPARE_BOOT` to `BOOTING` state.
Transitioning from `BOOTING` to `ACTIVE` state.
Transitioning from `ACTIVE` to `PREPARE_SHUTDOWN` state.
Transitioning from `PREPARE_SHUTDOWN` to `SHUTTING_DOWN` state.
Transitioning from `SHUTTING_DOWN` to `INACTIVE` state.
[15]:
sim.state
[15]:
'INACTIVE'