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.
Let’s write a simple routine to sweep a gate and measure current:
Run it:
The ctx parameter gives you access to everything your routine needs:
Routines can access results from earlier routines:
Run them in sequence:
Instead of passing parameters every time, configure them in your device YAML:
Now run without arguments:
Configure in YAML:
Run it:
Routines can iterate until they find what they’re looking for:
Build intelligent workflows that adapt based on measurements:
Run the workflow:
Use nested routines in your YAML to organize multi-step processes:
Run the entire workflow:
When you provide a logger to RoutineRunner, data is automatically logged:
Your routine receives a session parameter automatically:
Handle errors gracefully to prevent tune-up interruption:
Here’s a complete example combining multiple routines:
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.