Code Generation
One of the most powerful capabilities of the Custom Experiment Builder is its ability to translate your visual block structure directly into ready-to-run source code. You design your experiment by dragging and dropping blocks, and with a single click you receive the equivalent program in a fully featured programming language.
This bridges the gap between intuitive, graphical experiment design and the limitless flexibility of writing your own scripts.
Code generation lets you move seamlessly from a working graphical experiment to a script you can read, run, and extend. You benefit from the speed and clarity of visual design while keeping the door open to automation, custom data evaluation, and integration into larger workflows, all without rebuilding your experiment from scratch.
Warning
The generated code is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall Zahner be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the generated code or its use. You are solely responsible for any code you run and for the consequences of running it.
Python
The Custom Experiment Builder generates Python code that uses the zahner_link library to control your Zahner IM7 instrument. Python was chosen because it is beginner-friendly, free to use, and backed by a large scientific community with mature packages for data processing and visualization.
Generating and Copying the Code
Generating the code for your experiment is straightforward:
Build your experiment in the Custom Experiment Builder by assembling and configuring the desired blocks.
Click the Python logo in the Custom Experiment Builder. The generated Python code is displayed for the current block structure.
Copy the code and paste it into your own Python file in your editor of choice, then run it as-is or adapt it to your needs.
The generated script mirrors the logic of your block structure exactly, so every step you designed visually has a clear, readable counterpart in the code.
A Starting Point, Not a Finished Application
It is important to understand that the code generator does not produce a finished, turnkey application. Just like the Python examples in our zahner_link GitHub repository, the generated script is a solid foundation that you can build upon.
From this foundation you can extend the script in any direction you like, for example by looping over additional parameters, adding your own data analysis, plotting your results with Matplotlib, or embedding the measurement into a larger automated workflow. This is also an excellent way to learn the zahner_link library, since the generated code shows you exactly how a complete measurement is expressed in code.
A detailed, worked example, from the block setup all the way to a finished evaluation script, is presented in the Getting Started with Python application note.
Things to Keep in Mind
A few points are worth noting when working with the code generation feature:
Python is not included with the Zahner Lab. To run the generated code you need a separate Python installation, along with the zahner_link library. The Getting Started with Python application note explains how to set up Python, choose an editor, and install the required packages.
The conversion only works in one direction. Code generation translates your block structure into Python, but it is not possible to convert a Python script back into a Custom Experiment Builder block structure. If you want to keep editing your experiment graphically, continue to do so in the Custom Experiment Builder and regenerate the code whenever you need it.