Python API
This notebook demonstrates how to set up a Jetto interpretive simulation and run it via duqtools.
The cell below sets up logging for the notebook.
import logging
logging.basicConfig(
level=logging.INFO,
format='%(message)s',
)
Below is an example duqtools config.
The example below takes t_e
(electron temperature) from the template, and multiplies it by 1.1.
It also sets a few machine specific parameters (major_radius
, b_field
), and adjusts the start (t_start
) and end time (t_end
) for the simulation.
For more documentation on the parameters, check out the documentation here: https://duqtools.readthedocs.io/en/latest/config/create/
from duqtools.api import create
config = {
'tag': 'data_01',
'create': {
'runs_dir':
'/afs/eufus.eu/user/g/g2ssmee/jetto_runs/duqduq/data_123',
'template':
'/afs/eufus.eu/user/g/g2ssmee/jetto_runs/interpretive_esco02',
'template_data': {
'user': 'g2aho',
'db': 'aug',
'shot': 36982,
'run': 2,
},
'operations': [
{
'variable': 't_e',
'operator': 'multiply',
'value': 1.1,
},
{
'variable': 'major_radius',
'operator': 'copyto',
'value': 165.0,
},
{
'variable': 'b_field',
'operator': 'copyto',
'value': -2.5725,
},
{
'variable': 't_start',
'operator': 'copyto',
'value': 2.875,
},
{
'variable': 't_end',
'operator': 'copyto',
'value': 2.885,
},
],
},
'system': {
'name': 'jetto',
},
}
Running create
will create a new run from the template, copy over the template data, and apply the operations to the data. This will return a dictionary with jobs and runs (Job
and Run
objects).
jobs_and_runs = create(config)
job, run = jobs_and_runs['run_0000']
run
contains some metadata about the run and the locations to the input and output data for the run.
run.model_dump()
job
contains information about the status of the job and the locations of the input and output files for the simulation.
print(job.in_file)
print(job.in_file.exists())
print(job.out_file)
print(job.out_file.exists())
print(job.status())
The job
can be submitted using the configured submit system.
job.submit()
Track the status of the job through job.status()
.
import time
print(job.status())
t0 = time.time()
while not job.is_done:
t1 = time.time() - t0
print(f'{t1:10.2f} - {job.status()}')
time.sleep(1)
print(job.status())
Check that the run has created some data.
print(run.data_out.exists())
Load the data into an xarray.Dataset
and do things with it.
ds_out = run.data_out.get_variables(('time', 'rho_tor_norm', 't_e'))
ds_out.isel(time=[
0,
]).plot.scatter('rho_tor_norm', 't_e', marker='.');