Routines
Routines are Python functions that orchestrate your device measurements. Think of them as recipes - they take a device, perform a sequence of operations, and return results. The @routine
decorator handles parameter management, logging, and result storage automatically.
Your First Routine
Let’s write a simple routine to sweep a gate and measure current:
Run it:
Understanding the Context
The ctx
parameter gives you access to everything your routine needs:
Accessing Your Device
Using Previous Results
Routines can access results from earlier routines:
Run them in sequence:
Pre-configuring Parameters
Instead of passing parameters every time, configure them in your device YAML:
Now run without arguments:
Example: Building a 2D Charge Stability Diagram
Configure in YAML:
Run it:
Example: Iterative Tuning with Feedback
Routines can iterate until they find what they’re looking for:
Example: Conditional Workflows
Build intelligent workflows that adapt based on measurements:
Run the workflow:
Organizing Complex Tune-ups
Use nested routines in your YAML to organize multi-step processes:
Run the entire workflow:
Automatic Data Logging
When you provide a logger
to RoutineRunner
, data is automatically logged:
Your routine receives a session
parameter automatically:
Error Handling
Handle errors gracefully to prevent tune-up interruption:
Complete Example: Automated Tuneup Workflow
Here’s a complete example combining multiple routines:
Tips and Best Practices
Always return dictionaries: Makes results easy to access and extend later.
Use type hints: Helps with IDE autocomplete and documentation:
Document your routines: Write clear docstrings explaining what the routine does and what parameters it expects.
Keep routines focused: Each routine should do one thing well. Compose complex workflows from simple routines.
Check for previous results: Always check if ctx.results.get()
returns None before using results.
Use finally blocks: Ensure cleanup code runs even if errors occur:
Test incrementally: Test each routine individually before chaining them together.
Version your code: Keep routines in git and document changes.
Next Steps
- Data Logging - Learn how to log and retrieve measurement data
- Device Configuration - Configure your device for use with routines
- Drivers - Understand how device operations communicate with hardware