Drivers
Drivers are the translators between Stanza’s high-level device operations and the specific commands your hardware understands. Stanza includes drivers for common instruments (QDAC-II, OPX) and makes it straightforward to add support for custom hardware.
Built-in Drivers
QDAC-II: Voltage Control and DC Measurement
The QDAC-II is a 24-channel DAC with built-in current measurement. It’s perfect for DC gate control and low-noise current measurements.
Basic setup for voltage control:
Adding current measurement:
Or use one instrument for both:
Key parameters:
slew_rate
: How fast voltages ramp (V/s). Lower is safer but slower.measurement_duration
: Total time to measure (seconds). Longer = less noise.sample_time
: Integration time per sample. Smaller = more samples.current_range
:"LOW"
(±1 μA) or"HIGH"
(±100 μA)
OPX: Fast DC Measurements
The OPX driver provides DC current measurement with pause-based synchronization. It’s useful when you need faster measurements than QDAC can provide:
The OPX driver automatically generates QUA programs for pause-based measurements. During sweeps, it pauses between voltage steps, measures current, and streams data back.
Example sweep with OPX:
Testing Without Hardware
Enable simulation mode to develop code before hardware access:
Create sim_config.yaml
to define simulated responses:
Now your code runs without hardware, using these simulated characteristics.
Writing a Custom Driver
Need to support custom hardware? Here’s how to write a driver.
Step 1: Understand What You Need
Every driver implements one or both protocols:
- ControlInstrument: For setting/reading voltages
- MeasurementInstrument: For measuring currents
Step 2: Create Your Driver File
Create stanza/drivers/mycustom.py
:
Step 3: Use Your Driver
Add it to your device configuration:
Stanza automatically discovers and instantiates your driver.
Example: Simple Serial Instrument
Here’s a complete driver for a serial DAC:
Use it:
How Sweeps Work
When you call device.sweep_1d()
, here’s what happens:
- Stanza generates voltage points from your start/stop/n_points
- For each voltage:
- Calls
control_instrument.set_voltage(gate, voltage)
- Waits for voltage to settle (based on slew rate)
- Calls
measurement_instrument.measure(contact)
- Calls
- Returns arrays of voltages and measurements
- If session provided, logs the data automatically
Your driver just needs to implement set_voltage()
and measure()
. Stanza handles the rest.
Driver Best Practices
Validate inputs: Check voltage bounds before sending to hardware.
Handle errors gracefully: Catch and re-raise with context.
Implement close(): Clean up resources.
Support simulation: Add a simulation flag for testing.
Add logging for debugging: Use Python’s logging module.
Testing Your Driver
Write tests to verify your driver works:
Test with actual device configuration:
Troubleshooting
“Cannot connect to instrument”: Check IP address and network connection.
“Voltage out of bounds”: Check your device configuration voltage limits match your hardware.
“No response from instrument”: Verify your command syntax matches the instrument’s protocol. Check the manual or use the instrument’s native software to test commands.
“Channel not found”: Make sure channel numbers in your YAML match the driver’s expectations.
Next Steps
- Device Configuration - Configure instruments in your device YAML
- Routines - Use devices with drivers in your measurements
- Data Logging - Automatically log data from driver measurements