Package: qt3utils
Utility Classes and Functions for the QT3 LabThis package provides a number of tools and fully-packaged programs for usage
in the Quantum Technologies Teaching and Test-Bed (QT3) lab at the University of Washington.The QT3 lab confocal microscope utilizes the following hardware to perform
various spin-control experiments on quantum systems, such as NV centers in diamond:TTL pulsersQuantum Composer SapphireSpin Core PulseBlasterExcelitas SPCM for photon detectionNI-DAQ card (PCIx 6363) for data acquisition and controlJena System's Piezo Actuator Stage Control Amplifier[Future] spectrometerThe code in this package facilitates usages of these devices to perform
experiments.SetupPrerequisitesThe utilities in this package depend on publicly available Python packages found
on PyPI and drivers built by National Instruments for DAQmx and
SpinCore for the PulseBlaster. These libraries must be installed separately.National Instruments DAQmxdriver downloadsSpinCore's PulseBlasterspinAPI driverInstallationOnce the prerequisite packages have been installed, qt3utils can be installed from pip.Normal Installationpip install qt3utilsTheqt3utilspackage depends on a handful of otherqt3 packagesand will be installed for you by default.
Additional information may also befound here.Update Tk/TclUpgrading Tcl/Tk via Anaconda overcomes some GUI bugs on Mac OS Sonomaconda install 'tk>=8.6.13'UsageThis package provides GUI applications and a Python API for controlling the hardware and running experiments.For instructions on using the python API,
the simplest way to get started is to see one of theexampleJupyter notebooks.The following notebooks demonstrate usage of their respective experiment classes and
the necessary hardware control objects for those experimentsCWODMRPulsed ODMRRabi OscillationsRamsey(similar usage for spin/Hahn echo and dynamical decoupling)Additionally, there are two notebooks that demonstrate some basic hardware testsPulse Blaster TestsMW Switch TestsMost classes and methods contain docstrings that describe functionality, which you can
discover through the python help() function.Details of how the experiment classes work and how you can modify
them are found inExperimentsDoc.mdHelp toautomatically generate documentationwould be appreciated.ApplicationsQT3 OscilloscopeThe console programqt3scopecomes with this package. It allows you to run
a simple program from the command-line that reads the count rate on a particular
digital input terminal on the NI DAQ. Further development may allow it to
display count rates from other hardware.It can be from the command line / terminal> qt3scopeAfterpip install, there will be an executible file in your python environment. You
should be able to create a softlink to that executable to a desktop or task bar icon, allowing
to launch the program from a mouse click.Starting in version 1.0.3, graphical dropdown menus and configuration windows
will allow users to configure various hardware options.YAML ConfigurationData Acquisition hardware supported by QT3Scope can also be configured by selecting a YAML file.
The YAML file must contain a specific structure and names as shown below.Default NIDAQ Edge Counter YAML configuration:QT3Scope:DAQController:import_path:qt3utils.applications.controllers.nidaqedgecounterclass_name:QT3ScopeNIDAQEdgeCounterControllerconfigure:daq_name:Dev1# NI DAQ Device Namesignal_terminal:PFI0# NI DAQ terminal connected to input digital TTL signalclock_terminal:# Specifies the digital input terminal to the NI DAQ to use for a clock. If left blank, interprets as None or NULLclock_rate:100000# NI DAQ clock rate in Hznum_data_samples_per_batch:1000read_write_timeout:10# timeout in seconds for read/write operationssignal_counter:ctr2# NI DAQ counter to use for counting the input signal, e.g. ctr0, ctr1, ctr2, or ctr3Default Random Data Generator configuration:QT3Scope:DAQController:import_path:qt3utils.applications.controllers.random_data_generatorclass_name:QT3ScopeRandomDataControllerconfigure:simulate_single_light_source:Falsenum_data_samples_per_batch:10default_offset:100signal_noise_amp:0.5All hardware controllers built for QT3Scope have a default
configuration YAML file, which are found insrc/qt3utils/applications/controllers.QT3 Confocal ScanThe console programqt3scanperforms a 2D (x,y) scan using a data acquisition
controller object and a position controller object. The default controllers use
an NIDAQ device that counts TTL edges (typically from an SPCM) and sets
analog voltage values on a Jena system piezo actuator.> qt3scanSimilar toqt3scope, the supported hardware can be configured via GUI or YAML file.All hardware controllers that are built for QT3Scope have a default
configuration YAML file, which will be found insrc/qt3utils/applications/controllers.Default NIDAQ Edge Counter YAML configuration:QT3Scan:DAQController:import_path:qt3utils.applications.controllers.nidaqedgecounterclass_name:QT3ScanNIDAQEdgeCounterControllerconfigure:daq_name:Dev1# NI DAQ Device Namesignal_terminal:PFI0# NI DAQ terminal connected to input digital TTL signalclock_terminal:# Specifies the digital input terminal to the NI DAQ to use for a clock. If left blank, interprets as None or NULLclock_rate:100000# NI DAQ clock rate in Hznum_data_samples_per_batch:250read_write_timeout:10# timeout in seconds for read/write operationssignal_counter:ctr2# NI DAQ counter to use for counting the input signal, e.g. ctr0, ctr1, ctr2, or ctr3PositionController:import_path:qt3utils.applications.controllers.nidaqpiezocontrollerclass_name:QT3ScanNIDAQPositionControllerconfigure:daq_name:Dev1# NI DAQ Device Namewrite_channels:ao0,ao1,ao2# NI DAQ analog output channels to use for writing positionread_channels:ai0,ai1,ai2# NI DAQ analog input channels to use for reading positionscale_microns_per_volt:8# conversion factor from volts to microns, can also supply a list [8,8,8] or [6,4.2,5]zero_microns_volt_offset:0# the voltage value that defines the position 0,0,0, can also supply a list [0,0,0] or [5,5,5]minimum_allowed_position:0# micronsmaximum_allowed_position:80# micronssettling_time_in_seconds:0.001Default Random Data Generator configuration:QT3Scan:PositionController:import_path:qt3utils.applications.controllers.random_data_generatorclass_name:QT3ScanDummyPositionControllerconfigure:maximum_allowed_position:80minimum_allowed_position:0DAQController:import_path:qt3utils.applications.controllers.random_data_generatorclass_name:QT3ScanRandomDataControllerconfigure:simulate_single_light_source:Truenum_data_samples_per_batch:10default_offset:100signal_noise_amp:0.1QT3 Piezo ControllerThe console programqt3piezocomes installed via the 'nipiezojenapy' package, and may be launched from the command line.> qt3piezoThis application can only be configured via command line options at this time.
Thenipiezojenapypython package should probably be moved intoqt3utils.QT3Scope / QT3Scan Hardware DevelopmentFollow these instructions in order to add new hardware support toqt3scopeorqt3scan.For each application, you'll need to build a Python classes that adheres to each application's interfaces.QT3ScopeBuild a class that adheres toQT3ScopeDAQControllerInterfaceas defined insrc/qt3utils/applications/qt3scope/interface.py. There are a number of methods
that you must construct. Two examples areQT3ScopeRandomDataControllerandQT3ScopeNIDAQEdgeCounterController.
In addition to controlling hardware and returning data, they must also supply a way to configure the object via
Python dictionary (configuremethod) and graphically (configure_viewmethod).Create a YAML file with a default configuration, similar to that found inrandom_data_generator.yamlorAdd your new controller toSUPPORTED_CONTROLLERSfound inqt3scopeQT3ScanSimilar toqt3scopebut with a little more work.There are three controllers that are needed byqt3scan:Application Controller --QT3ScanApplicationControllerInterfaceDAQ Controller --QT3ScanDAQControllerInterfacePosition Controller --QT3ScanPositionControllerInterface1. Application ControllerCurrently there is onlyone implementation of the Application Controllerto support standard 2D (x,y) scans. It is used for scans using the NIDAQ Edge Counter
Controller, NIDAQ Position Controller, Random Data Generator and Dummy
Position Controller.If you do not need any changes to the save function
or special functionality to right-click on the scan image, then you can probably
re-use this Application Controller.If you are developing something like the
hyper-spectral image where each pixel in the 2D scan is based on a spectrum
of counts over a range of wavelengths, you'll
likely want to build a new Application Controller. AQT3ScanHyperSpectralApplicationControllerclass would implement a
data view when a user right-clicks on the scan and would implement a function
to save the full 3-dimensional data set.2. DAQ ControllerTo support new hardware that acquires data, build an implementation ofQT3ScanDAQControllerInterface.
Examples areQT3ScanRandomDataController,
andQT3ScanNIDAQEdgeCounterControllerCreate a new python module in insrc/qt3utils/applications/controllersfor your hardware controller.3. Position ControllerTo support a new Position Controller build an implementation ofQT3ScanPositionControllerInterface.
Examples areQT3ScanDummyPositionController,
andQT3ScanNIDAQPositionControllerCreate a new python module in insrc/qt3utils/applications/controllersfor your position controller.4. Default YAML fileCreate a default YAML file that configures your DAQ and Position Controllers. Place the YAML file insrc/qt3utils/applications/controllers5. Update QT3Scan.mainAdd your new controllers toqt3scan.main.pyGeneral Python DevelopmentIf you wish you make changes to qt3-utils (and hopefully merge those improvements into this repository) here are some brief instructions to get started. These instructions assume you are a
member of the QT3 development team and have permission to push branches to this repo. If you are not, you can
instead fork this repo into your own GitHub account, perform development and then issue a pull-request from
your forked repo to this repo through GitHub. Alternatively, reach out to a maintainer of this repo to be added as a developer.These are mostly general guidelines for software development and
could be followed for other projects.1. Create a development environmentUse Conda, venv or virtualenv with Python = 3.9.> conda create --name qt3utilsdev python=3.9As of this writing, we have primarily tested and used Python 3.9.
Reach out to a Maintainer to discuss moving to newer versions of
Python if this is needed.2. Activate that environment> conda activate qt3utilsdev3. Clone this repository> git clone https://github.com/qt3uw/qt3-utils.git4. Install qt3-utils in "editor" mode> cd qt3-utils
> pip install -e .Thepip install -e .command installs the package in editor mode.
This allows you to make changes to the source code and immediately
see the effects of those changes in a Python interpreter. It saves
you from having to call "pip install" each time you make a change and
want to test it.5. Create a new IssueIt's generally good practice to first create an Issue in this GitHub
repository which describes the problem that needs to be addressed.
It's also a good idea to be familiar with the current Issues that
already exist. The change you want to make may already be
reported by another user. In that case, you could collaborate
with that person.6. Create a new branch for your work> git checkout -b X-add-my-fancy-new-featurewhere it's good practice to use X to refer to a specific Issue to fix
in this repository.You should create a new branch only for a specific piece of new work
that will be added to this repository. It is highly discouraged to create
a separate branch for your microscope only and to use that branch
to perform version control for Python scripts or Jupyter notebooks
that run experiments.
If you need version control for your exerpiment scripts and notebooks, you
should create a separate git repository and install qt3utils
in the normal way (pip install -U qt3utils) in a Python environment
for your experimental work. If you need to have recent changes to qt3utils
published to PyPI for your work, reach out to a Maintainer of this
repo to ask them to release a new version.7. Add your code and test with your hardware!We do not have an official style convention, unfortunately. However
please try to follow best-practices as outlined either inPEP 8 styleguideorGoogle's styleguide.
There are other resources online, of course, that provide "best-practices"
advice. Having said that, you will certainly find places where I've
broken those guides. (Ideally, somebody would go through with a linter
and fix all of these.). Please heavily document your source code.We do not have an automatic test rig. Thiscouldbe added by somebody
if desired. But that could be complicated given that this code requires
specific local hardware and the setup for each experiment
is likely to be different. So, be sure to test your code rigorously and
make sure there are no unintended side-effects.Historically, documentation for this project has been "just okay". Please
help this by adding any documentation for your changes where appropriate.
There is now adocsfolder that you can use to include any major
additions or changes.8. Push your branchOnce development and testing are complete you will want to push your
branch to Github in order to merge it into the rest of the code-base.When you first push a branch to Github, you will need to issue this
command.> git push -u origin X-add-my-fancy-new-featureAs you add more commits to your branch, you'll still want to
push those changes every once in a while with a simple> git push(assuming that X-add-my-fancy-new-feature is your current
local working branch)Finally, before you issue a pull request, you will want to
synchrononize your branch with any other changes made in 'main'
to ensure there are no conflicting changes.This is the following "flow" that has been used successfully in
various development projects. However, there are other ways
to do this.> git checkout main
> git pull
> git checkout X-add-my-fancy-new-feature
> git rebase main
> git push -fThe series of commands above will pull down new changes from
Github's main branch to your local working copy. Therebasecommand will then "replay" your changes on top of the
most recent HEAD of the main branch. If there are conflicts,
git will notify you and you will be forced to fix those
conflicts before continuing with the rebase. If it seems too
complicated, you cangit rebase --abortto recover and
then figure out what to do next. Reach out to a more experienced
colleague, perhaps, for help.The finalgit push -fis necessary (if there were indeed new
commits on the main branch) and will "force" push your branch
to Github. This is necessary due to the way git works.You should then test your local branch with your hardware again!This particular flow has the benefit of making a very clear git
history that shows all the commits for each branch being
merged in logical order.Instead of following the instructions above, you may consider
trying GitHub's "rebase" option when issuing a pull request.
It will attempt the same set of operations. However, you may
not have the opportunity to test the changes locally.9. Issue a pull requestAt the top of this qt3-utils GitHub repository is a 'pull-request' tab,
from where you can create a request to merge your branch to another
branch (usually you merge to main)When you issue a pull request, be very clear and verbose about the
changes you are making. New code must be reviewed by another colleague
before it gets merged to master. Your pull request should include things likea statement describing what is changed or newa reference to the Issue being fixed here (Github will automatically generate a handy link)a statement describing why you chose your specific implementationresults of tests on your hardware setup, which could be data, screenshots, etc. There should be a clear record demonstrating functionality.a Jupyter notebook in the "examples" folder that demonstrate usage and changesdocumentation10. Perform Self ReviewBefore asking a colleague to review your changes, it's generally
a good idea to review the changes yourself in Github.
When you see your updates from this perspective you may find
typos and changes that you wish to address first.11. Obtain a Code Review from a colleagueDue to our lack of a test rig, merging should be done with care and
code reviews should be taken seriously. If you are asked by a colleague
to review their code, make sure to ask a lot of questions as you read
through it. You may even want to test the branch on your own setup
to ensure it doesn't break anything.12. Address ChangesIf you and your reviewer decide changes are needed, go back
to your branch, make changes and push new commits. Repeat
steps 7, 8, 10, 11 and 12 until you are satisfied.13. Merge!If you are satisfied and confident that your changes are
ready, and your reviewer has approved the changes, press the
green Merge button.NotesDebuggingLICENSELICENCE