Skip to content

Create new basis

Bzzzt90 edited this page Jun 22, 2021 · 9 revisions

How to create and test a new basis

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

Check how your package is installed

Before starting, check 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/mrossign/QuOCS/QuOCS/src
quocs-pyside2interface 0.0a1   /home/mrossign/QuOCS/QuOCS-pyside2interface/src
quocs-thesuite         0.0a1   /home/mrossign/QuOCS/QuOCS-thesuite
quocs-tools            0.0a1   /home/mrossign/QuOCS/QuOCS-tools

If quocs-lib does not appear as an editable package please install it in the editable mode


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 of the module 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()

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

Re-install quocs. Expecially if you created a new branch but also otherwise it might be helpful to have a look at: Running the GUI on a nwe 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

Clone this wiki locally