Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non interactive gate set characterization + action builder #239

Merged
merged 96 commits into from
Feb 17, 2023

Conversation

wilkensJ
Copy link
Contributor

@wilkensJ wilkensJ commented Feb 8, 2023

In this pull request the architecture and basic structure for a new way of implementing high level characterization for quantum hardware is implemented. We coined it 'Non-interactive Gate Set Characterization', short niGSC.
A new module can easily be implemented with that architecture using the predefined classes and functions along with a thorough documentation and explanation. qq can handle the new modules.

A module consists of the following parts;

  • an iterator generating circuits with a wanted gate set distribution (qibocal/calibration/niGSC/base/circuitfactoryp.y),
  • an experiment class knowing how to store and proceed with relevant data from experimentally executing the circuits (qibocal/calibration/niGSC/base/experiment.py),
  • and post processing functions encoding the way data should be handled, processed, and displayed (module specific, plotting found in qibocal/calibration/niGSC/base/plot.py, qibocal/calibration/niGSC/base/fitting.py.

In the subfolder qibocal/calibration/niGSC/base/ the abstract classes and functions shared within all the modules are stored.
A detailed explanation of a module can be found in the documentation doc/source/getting-started/niGSC/niGSC_and_standardrb.rst explaining the workflows in qibocal/calibration/niGSC/standardrb.py.
How to write a module is explained in the comments of qibocal/calibration/niGSC/XIdrb.py.

Below a figure with a schematic diagram of niGSC can be found. First the instructions are put into qibo circuits, which are send to the hardware (or simulated) outputting data which, along with the used gates, are forming the gate set shadow. Different post processing methods calculate sequential and aggregational tasks (along with fitting mostly exponentials) which are then displayed in a report summarizing the found results of that protocol.

Non interactive gate set characterization explanation in a diagram

Jadwiga Wilkens and others added 30 commits November 28, 2022 14:28
Simplify action builder + fix tests
@andrea-pasquale
Copy link
Contributor

Now I have another problem with the documentation: When creating the html via 'make html' in the doc folder, following error message is displayed:

For me the command is working. Also CI doesn't complain. Give it a try with a clean env to check if this error is still there.

@scarrazza scarrazza added this to the Qibocal 0.0.1 milestone Feb 15, 2023
@scarrazza scarrazza added the enhancement New feature or request label Feb 15, 2023
Copy link
Member

@stavros11 stavros11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this. A couple of quick comments regarding code style, I will have a more detailed look later.

The docs are indeed nice, particularly the figures. Would be great to use this in other parts of qibo docs. One thing I find weird is that the circuits drawings are inverted (measurements are on the left) compared to the common notation, however I am guessing you did that so the gate order matches the mathematical representation of the circuit (as product of operators).

src/qibocal/calibrations/niGSC/basics/circuitfactory.py Outdated Show resolved Hide resolved
Comment on lines 39 to 44
assert circuitfactory is None or isinstance(
circuitfactory, Iterable
), """
given circuit factory has wrong type {}, must be Iterable | None.""".format(
type(circuitfactory)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that here and in other places below and in XIdrb.py you are using assert to catch errors. Usually we do something like

Suggested change
assert circuitfactory is None or isinstance(
circuitfactory, Iterable
), """
given circuit factory has wrong type {}, must be Iterable | None.""".format(
type(circuitfactory)
)
if circuitfactory is not None and not isinstance(circuitfactory, Iterable):
raise TypeError("given circuit factory has wrong type {}, must be Iterable | None.".format(type(circuitfactory)))

but I have no strong opinion on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case where circuitfactory can be an arbitrary iterable or does it always need to be a Circuitfactory object? If it is the latter, why you don't check for Circuitfactory type directly instead of Iterable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be a list, or even another generator/iterator. The important thing is that is it iterable.
I can change the error handling.

src/qibocal/calibrations/niGSC/XIdrb.py Outdated Show resolved Hide resolved
@scarrazza
Copy link
Member

I believe this is good to go, could you please confirm?

@wilkensJ
Copy link
Contributor Author

The only open question from @andrea-pasquale is how to organize the files, else everything was cleared I think.

@andrea-pasquale
Copy link
Contributor

andrea-pasquale commented Feb 17, 2023

@wilkensJ I would like to have these points solved before merging:

The other two about re-organizing folders and experiment_directory could be addressed after the merge if necessary.

Copy link
Member

@stavros11 stavros11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I did not test this, so far I did not see any blocking issues at least in the code. Below are some mostly cosmetic comments which are not very important but also relatively easy to implement.

src/qibocal/calibrations/niGSC/basics/circuitfactory.py Outdated Show resolved Hide resolved

def experiment_directory(name: str):
"""Make the directory where the experiment will be stored."""
from datetime import datetime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally prefer top level imports unless there is a strong motivation (eg. optional library) to import inside the method. Here datetime is standard library so I do not see an issue with importing on top. This comment may also be relevant in other parts of the code.

Comment on lines +2 to +3
from os import mkdir
from os.path import isdir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I just import os and then use os.mkdir etc. but no strong opinion here.

return depolp


def probabilities(allsamples: Union[list, np.ndarray]) -> np.ndarray:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tracked exactly where this function is used, but if you are getting allsamples from qibo it may be simpler to use .frequencies to do this calculation (but probably you already know this).

src/qibocal/calibrations/niGSC/simulfilteredrb.py Outdated Show resolved Hide resolved
"""

def __init__(
self, nqubits: int, depths: list | np.ndarray | int, qubits: list = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using lists (and generally mutable objects) as default arguments may lead to unexpected behavior. I believe this is not relevant here because you are not manipulating qubits in the function, so no change required, just letting you know in case you encounter this somewhere else.

@scarrazza
Copy link
Member

@wilkensJ @andrea-pasquale if you can please implement Stavros suggestions so we can merge later today and include in the first release.

@scarrazza
Copy link
Member

I believe there is something wrong with one or more tests in this PR.

@andrea-pasquale
Copy link
Contributor

I believe there is something wrong with one or more tests in this PR.

Yes I know. I've approved it too soon. I will have a look now.

@andrea-pasquale
Copy link
Contributor

Now it is ready to merge @scarrazza.
The other points can be fixed later.

@scarrazza
Copy link
Member

Perfect, thank you.

@scarrazza scarrazza merged commit 35b01ad into main Feb 17, 2023
@scarrazza scarrazza deleted the jadwiga/rb_action_builder branch February 17, 2023 15:41
@wilkensJ wilkensJ mentioned this pull request Feb 27, 2023
3 tasks
@andrea-pasquale andrea-pasquale mentioned this pull request Mar 8, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants