Package: qutech-util
qutil / qutech_utilLong term goal is to gather utility functions here.
The original name wasqutilbut we included the additional aliasqutech_utilso you can install it viapipy.
It is not meant as a lightweight package but some heavy dependencies like qcodes are feature gated.
If you don't have a reason for a lightweight install you should install all features i.e.qutil[complete].
If you just want to use it you can install the latest "released" version viapython-mpipinstallqutech-util[complete]However, this package profits from everybody's work and the releases are infrequent. Please make a development install
and contribute your changes. You can do this viapython-mpipinstall-egit+https://git.rwth-aachen.de/qutech/qutil.git#egg=qutech-util[complete]This will download the source code (i.e. clone the git repository) into a subdirectory of the./srcargument and link the files into your environment instead of copying them. If you are on windows you can useSourceTreewhich is a nice GUI for git.
You can specify the source code directory with the--srcargument (which needs to be BEFORE-e):python-mpipinstall--srcsome_directory/my_python_source-egit+https://git.rwth-aachen.de/qutech/qutil.git#egg=qutech-util[complete]If you have already downloaded/cloned the package yourself you can usepython -m pip install -e .[complete].Please file an issue if any of these instructions does not work.TestsThere is no plan for writing extensive tests for the code in this package but please try to write proper docstrings for
your functions and include examples in them which can be checked viadoctest.
Follow the link for an example for an example :)You can run the tests either viapython-mpytest--doctest-modulesor to check if everything works for a clean install (requires hatch to be installed)python-mhatchruntest:runDocumentationThe auto-generated documentation can be found atthe Gitlab Pages.To build the documentation locally, navigate todoc/and run either.\make.bat html(on Windows),makehtml(on Unix), orsphinx-build -b html source buildMake sure the dependencies are installed viapython-mpipinstall-e.[doc]in the top-level directory.qutil.plottingThis module contains useful classes and functions surroundingmaptlotlibplots.cycle_plotshelps you cycling through many plots with the arrow keys (there are probably much better functions for this out there)plot_2d_dataframehelps you plot 2d data frames with numeric indicesBlitManagercan be used to significantly speed up plotting when certain parts of the plot, such as the artists on the canvas (lines, annotations, etc.) change but others do not (axes, labels, etc.) does not.CoordClickerandLineClickerallow some interactive selection of data.get_rwth_color_cycleand the predefinedrwth_color_cycleare cycler instances with the official RWTH corporate design colors:qutil.matlabIn this module there are functions that are helpful for reading.matfiles, especially those created with special measure.
It depends on the optionalmatlabfeature which is included in the complete install.
If you simply want to open a random.matfile you can usehdf5storage.loadmat.
Some functionality requires the matlab engine python interface to work, i.e. python will use a MATLAB instance to open files.
However, the matlab engine interface isnotinstalled by default because the install process depends on the version and fails if MATLAB is not installed.
For older MATLAB versions navigate to$MATLAB_INSTALL_FOLDER/extern/engines/pythonand executepython setup.py install.
For newer MATLAB versions you can install the engine interface viapython -m pip install matlabengine.Loading matlab files with "newer" MATLAB classes liketablerequires connecting (and starting) MATLAB instance.
The functionload_special_measure_with_matlab_enginecan load most special measure scans by utilizing the MATLAB engine interface. To use it you require a "sufficiently new" version of MATLAB and then navigate toC:\Program Files\MATLAB\$VERSION\extern\engines\pythonand callpython setup.py install.Recommended: There are dataclasses likeSimpleScanorVirtualScanthat are a python representation of certain common scan
types and have a convenienceto_xarraymethod. Useload_simple_scan_with_matlab_engineorload_virtual_scan_with_matlab_engineto load them.There are the dataclassesFigureData,AxesDataandPlotDatathat represent matlab figure data. They help inspecting saved matlab figures with the help of a matlab engine.qutil.constThis module defines all the constants you could wish for as well as functions to convert temperatures (convert_temperature) or between wavelengths and frequencies (lambda2nu,nu2lambda). For an overview, see the module docstring.qutil.linalgThis module provides several handy linear algebra functions. While some are implemented elsewhere, the implementation here is typically speedier for large arrays. For example,pauli_expmexploits the fact that a matrix exponential of Pauli matrices can be written as a cosine times the identity matrix plus a sine times the Paulis to speed up the calculation.For an overview of the included functions, see the module docstring.qutil.uiThis module collects UI helpers, such as a progress bar for loops that can be used like so:foriinqutil.ui.progressbar(range(n)):do_something()qutil.qiIn this module there are some quantities and functions related to quantum information, like the Pauli matrices in different data types.qutil.randomHere we collect functions for random numbers likerandom_hermitianto generate random Hermitian matrices.qutil.itertoolsThis module contains everything fromitertools,more_itertoolsand custom functions.qutil.cachingHere you find decorators, functions and classes that help you implement caching likefile_cacheandlru_cache. This is helpful if you need to call computationally expensive functions with the same arguments repeatedly.qutil.ioUser input related functions likequery_yes_noor aCsvLoggerinterface (for reading use pandas.read_csv).to_global_pathresolves all network drive mappings (such asZ:\) as well as domain names
(such as\\janeway) to their global address (\\janeway.physik.rwth-aachen.dein this case).qutil.parallelFunctions and classes related to parallel execution i.e. multi-threading, multi-processing and asyncio.
There is a class for periodic callbacks from another threadThreadedPeriodicCallback.qutil.hardwareThis package contains little scripts to talk to various hardware devices. For example reading the leak tester via serial interface.qutil.electronicslumped_elementsExposes the contents offastz, a package for simple lumped-elements calculations. Overloads+and//to implement series and parallel connections, respectively.See thefastzdocumentation for more information.qutil.qcodesFunctions to convert from and to qcodes data sets. Currently only
frompandas.DataFrametoqcodes.data.data_set.DataSetqutil.measurementThis package is supposed to contain measurement-related functionality. It is currently empty besides some backward compatibility imports.spectrometerMoved tohttps://git.rwth-aachen.de/qutech/python-spectrometer.qutil.typecheckFunctions and decorators to  help with runtime typechecking. Notably the@check_literalsdecorator to ensure that arguments match an annotated literal.
Imports thetypeguardwhich provides the powerful@typecheckeddecorator.fromtypingimportLiteral,Sequencefromqutil.typecheckimportcheck_literals@check_literalsdefmy_function(a:Sequence[int],b:Literal['forward','backward']):pass# do something# worksmy_function([1,2,3],'backward')# works because the first arguement is not checked at runtimemy_function({'no':'sequence'},'backward')# runtime error because of typo in 'backward'my_function('wrong','backwardd')qutil.pandas_toolsPandas utility functions for common code patterns.consecutive_groupbyis likepandas.DataFrame.groupbybut only
groups consecutive rows.qutil.imageImage and video processing tools.convert_tiffconverts a multipage.tifimage to a video with a format of choice usingmoviepy.