Skip to content

Create new basis

Thomas Reisser edited this page Nov 9, 2023 · 9 revisions

How to create and test a new basis

You can follow these steps to create a new basis for QuOCS.

Step 1: QuOCS

Copy the DummyBasis.py in QuOCS/QuOCS/src/quocslib/pulses/basis and name it accordingly (e.g. Fourier.py, Sigmoid.py, Chebyshev.py). Edit it to your needs. Have a look at the other files already there as a guide.

The main points are:

  • Choose a suitable name for the basis class, to prevent confusion with the current implemented one. Usually the same name as the .py file is fine.
  • Rename the basis name variable
  • Set the number of super parameters, i.e. the parameters which are chosen randomly at the beginning of every super-iteration.
  • Set the number of parameters you want to optimize
  • Build the shape of your basis function in _get_shaped_pulse()

You can now link the bsis is your .json file by adding the keys basis_module and basis_class in the basis section of the pulses:

"pulses": [
        {...
         "basis": {
             "basis_module": "Some_Folder.name_of_py_file",
             "basis_class": "name_of_class",
             ...
         },
         ...
     }
]
  • [Optional] Integrate the new basis into the json file QuOCS/QuOCS/src/quocslib/utils/map_dictionary.json
    1. Open the json file
    2. Within the basis_map key add a custom name for the new basis and fill the corresponding module_name and class_name.
  • If the optional step is not performed, to use the new basis the basis_module and basis_class should be provided in the optimization_dictionary file.

Including the basis in the packages src folder (in editable installation mode)

Check how your package is installed

First, check if your quocslib package is installed in the editable mode by using:

  python -m pip list -e

This command returns the list of the packages you installed in the editable mode in your current environment, something like this:

Package                Version Location
---------------------- ------- -----------------------------------------------
quocs-lib              0.0a1   /home/user/QuOCS/QuOCS/src
quocs-pyside2interface 0.0a1   /home/user/QuOCS/QuOCS-pyside2interface/src
quocs-thesuite         0.0a1   /home/user/QuOCS/QuOCS-thesuite
quocs-tools            0.0a1   /home/user/QuOCS/QuOCS-tools

If quocs-lib does not appear as an editable package please install it in the editable mode. Clone the git repository and use the following command:

python -m pip install -e .

ONLY IF YOU WORK WITH THE GUI IN Qudi

Step 2: The GUI file (.ui)

  • Copy one of the files in QuOCS-pyside2interface/src/quocspyside2interface/gui/uifiles for example the FourierBasis.ui.
  • Adapt it to your needs. Pay attention to the names of your widgets, you'll neet them in step 4!

In order to compile the .ui file you have to run the convertuipy.py script in the folder above (QuOCS-pyside2interface/src/quocspyside2interface/gui).

Step 3: The logic

  • Go to QuOCS-pyside2interface/src/quocspyside2interface/logic/OptimalAlgorithmDictionaries and duplicate one of the XXXXXBasisDictionary.py files. Instead of XXXXX name it like your basis in step 1.
  • Change the class name as well as self.basis_name, basis_class and basis_module.
  • Give it some defaults like the basis_vector_number

Step 4: The GUI again (linking logic and GUI)

  • Go to QuOCS-pyside2interface/src/quocspyside2interface/gui/algorithms/dcraboptimization and duplicate one of the XXXXXBasis.py files.
  • Now you have to go through every line and change:
    • imports
    • class name
    • self.basis_dictionary
    • check for all the widgets if they correspond to your .ui file

Test the new basis

Reinstall quocs. Expecially if you have created a new branch, but also in general, it might be helpful to have a look at: Running the GUI on a new branch.

  • Go to the test folder and create/copy a new test algorithm function with the algorithm, and the basis you want to use in the file name
  • To use your basis insert the current module and base class name, and put all the compulsory variables in the basis dictionary