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.
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)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:
QSwitch is a programmable relay matrix for routing signals between instruments and device pads. Each QSwitch channel has 10 relays: relay 0 is ground, relays 1-9 connect to different instruments or buses. This lets you reconfigure measurement setups without manual cable swapping.
Basic configuration:
The breakout_channel on each pad maps to a QSwitch channel. The breakout_line on each instrument indicates which relay connects to that instrument.
High-level device operations:
Direct instrument access for fine-grained control:
Safety pattern:
Key methods:
set_grounded(channel) / set_ungrounded(channel): Control relay 0 (ground)set_connected(channel, line) / set_disconnected(channel, line): Control specific relayget_grounded(channel) / get_connected(channel, line): Query relay stateThe QSwitch uses SCPI commands over TCP/IP. Each channel-relay pair is addressed as channel!relay in SCPI notation (e.g., 1!9 for channel 1, relay 9).
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.
Need to support custom hardware? Here’s how to write a driver.
Every driver implements one or both protocols:
Create stanza/drivers/mycustom.py:
Add it to your device configuration:
Stanza automatically discovers and instantiates your driver.
Here’s a complete driver for a serial DAC:
Use it:
When you call device.sweep_1d(), here’s what happens:
control_instrument.set_voltage(gate, voltage)measurement_instrument.measure(contact)Your driver just needs to implement set_voltage() and measure(). Stanza handles the rest.
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.
Write tests to verify your driver works:
Test with actual device configuration:
“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.