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

Mermin refactor #1038

Merged
merged 35 commits into from
Nov 28, 2024
Merged

Mermin refactor #1038

merged 35 commits into from
Nov 28, 2024

Conversation

Edoardo-Pedicillo
Copy link
Contributor

@Edoardo-Pedicillo Edoardo-Pedicillo commented Nov 5, 2024

@igres26 I have opened this PR to track the Mermin refactoring.
I have some questions:

  1. Could you explain this hard-coded value ?
    [qubits[0]] + [qubits[i]], sequence.finish + 8
  2. In Generalizing Mermin to n qubits and adding theta angles for plot #1005, the mitigation matrix is evaluated but not saved. Do you want to use it?
  3. Can we choose only one between Mermin with pulses and circuits? (we have already quite discussed about it, but could be better to answer here, since other people could be interested) I am refactoring the pulse one and have deleted the other one because only the first one was tested, but maybe it would be nice to have only the second one.

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.
  • Compatibility with Qibo modules (Please edit this section if the current pull request is not compatible with the following branches).
    • Qibo: master
    • Qibolab: 0.1
    • Qibolab_platforms_qrc: 0.1

@alecandido
Copy link
Member

alecandido commented Nov 6, 2024

Can we choose only one between Mermin with pulses and circuits? (we have already quite discussed about it, but could be better to answer here, since other people could be interested) I am refactoring the pulse one and have deleted the other one because only the first one was tested, but maybe it would be nice to have only the second one.

Just to add my 2c: whenever the circuits expression is supposed to be equivalent (i.e. usually the original protocol's definition is given in terms of circuits), it'd be better to express anything as circuits, as the higher level abstraction.
However, this certainly relies on the compiler to be doing its job, and sometimes the transpiler as well. I acknowledge this can be non-trivial. In general, if you encounter issues, feel free to use any workaround you need, but please report why you had to, and document it even in Qibocal (anywhere, an issue, or even a document in https://github.com/qiboteam/qibocal/tree/main/doc/dev). In principle, there should be no need for manual compilation (& transpilation), also because this will be the execution setup as well.

@Edoardo-Pedicillo
Copy link
Contributor Author

ust to add my 2c: whenever the circuits expression is supposed to be equivalent (i.e. usually the original protocol's definition is given in terms of circuits), it'd be better to express anything as circuits, as the higher level abstraction.
However, this certainly relies on the compiler to be doing its job, and sometimes the transpiler as well. I acknowledge this can be non-trivial. In general, if you encounter issues, feel free to use any workaround you need, but please report why you had to, and document it even in Qibocal (anywhere, an issue, or even a document in https://github.com/qiboteam/qibocal/tree/main/doc/dev). In principle, there should be no need for manual compilation (& transpilation), also because this will be the execution setup as well.

I agree, but from what I understood, there are some discrepancies. Maybe @igres26 could elaborate more on this.

@Edoardo-Pedicillo
Copy link
Contributor Author

After #1040 I think we can use circuits

@Edoardo-Pedicillo Edoardo-Pedicillo changed the base branch from mermin-nqubits to main November 14, 2024 12:50
@Edoardo-Pedicillo Edoardo-Pedicillo added this to the Qibocal 0.1.1 milestone Nov 14, 2024
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 99.09910% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.32%. Comparing base (c8cd2a9) to head (407d537).
Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
...l/protocols/two_qubit_interaction/mermin/pulses.py 97.14% 1 Missing ⚠️
...al/protocols/two_qubit_interaction/mermin/utils.py 96.29% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1038      +/-   ##
==========================================
- Coverage   97.37%   97.32%   -0.06%     
==========================================
  Files         120      124       +4     
  Lines        9749     9893     +144     
==========================================
+ Hits         9493     9628     +135     
- Misses        256      265       +9     
Flag Coverage Δ
unittests 97.32% <99.09%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/qibocal/protocols/__init__.py 100.00% <ø> (ø)
src/qibocal/protocols/readout_mitigation_matrix.py 97.50% <100.00%> (-2.50%) ⬇️
...ibocal/protocols/two_qubit_interaction/__init__.py 100.00% <100.00%> (ø)
...l/protocols/two_qubit_interaction/chsh/circuits.py 100.00% <100.00%> (ø)
...l/protocols/two_qubit_interaction/chsh/protocol.py 97.66% <100.00%> (ø)
...protocols/two_qubit_interaction/mermin/__init__.py 100.00% <100.00%> (ø)
...protocols/two_qubit_interaction/mermin/protocol.py 100.00% <100.00%> (ø)
src/qibocal/protocols/utils.py 92.22% <100.00%> (+0.02%) ⬆️
...l/protocols/two_qubit_interaction/mermin/pulses.py 97.14% <97.14%> (ø)
...al/protocols/two_qubit_interaction/mermin/utils.py 96.29% <96.29%> (ø)

... and 2 files with indirect coverage changes

@Edoardo-Pedicillo Edoardo-Pedicillo marked this pull request as ready for review November 15, 2024 08:48
@igres26
Copy link
Contributor

igres26 commented Nov 18, 2024

I am trying to test this. What other branches of Qibo and qibolab should I be using to run this? I cannot get the versions to work on my end.

figures = []
targets = data.targets

n_targets = len(targets)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
n_targets = len(targets)
n_targets = len(targets[0])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so n_targets = len(target) would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

It just has to be the number of qubits involved. Any way we get that it should work.

@igres26
Copy link
Contributor

igres26 commented Nov 19, 2024

@Edoardo-Pedicillo

Together with my proposed changes and @andrea-pasquale's it finally works.

Here are some results for 3 qubit Mermin: http://login.qrccluster.com:9000/bAaPJfD_RCyLslDSTgNkFA==/

And some for 2 qubit Mermin: http://login.qrccluster.com:9000/L-IDUlkmTRSYQp8oW95_GQ==/

Readout error mitigation works weirdly. It seems to invert the results, so it might be easy to fix. This is a result with it enabled: http://login.qrccluster.com:9000/Fp6E5gXxRpqhISPPmWPnmA==/

@Edoardo-Pedicillo
Copy link
Contributor Author

Readout error mitigation works weirdly. It seems to invert the results, so it might be easy to fix. This is a result with it enabled: http://login.qrccluster.com:9000/Fp6E5gXxRpqhISPPmWPnmA==/

This is because the zeros are treated as ones and vice versa. The cause of this is the strange shape of the mitigation matrix, where the columns are flipped respect to what it is usually expected.

matrix[:, int(state, 2)] = np.flip(column)

This should be fixed in #1045

@igres26
Copy link
Contributor

igres26 commented Nov 20, 2024

Readout error mitigation works weirdly. It seems to invert the results, so it might be easy to fix. This is a result with it enabled: http://login.qrccluster.com:9000/Fp6E5gXxRpqhISPPmWPnmA==/

This is because the zeros are treated as ones and vice versa. The cause of this is the strange shape of the mitigation matrix, where the columns are flipped respect to what it is usually expected.

matrix[:, int(state, 2)] = np.flip(column)

This should be fixed in #1045

Then we should be ready to merge.

Copy link
Contributor

@igres26 igres26 left a comment

Choose a reason for hiding this comment

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

With the readout error mitigation fixed in another pull request, this should be ready.

@igres26
Copy link
Contributor

igres26 commented Nov 25, 2024

Did you try to run it? I am getting an error now:

�[38;20m[Qibocal 0.1.1|INFO|2024-11-25 09:18:57]: Finished acquisition in 310.17 seconds�[0m
Traceback (most recent call last):
  File "/nfs/users/sergi.ramos/qiboenv/bin/qq", line 8, in <module>
    sys.exit(command())
  File "/nfs/users/sergi.ramos/qiboenv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/nfs/users/sergi.ramos/qiboenv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/nfs/users/sergi.ramos/qiboenv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/nfs/users/sergi.ramos/qiboenv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/nfs/users/sergi.ramos/qiboenv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/cli/_base.py", line 75, in run
    protocols_execution(runcard, folder, force, update)
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/cli/run.py", line 42, in protocols_execution
    history = runcard.run(
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/auto/runcard.py", line 63, in run
    instance.run_protocol(
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/auto/execute.py", line 131, in run_protocol
    completed = task.run(platform=self.platform, targets=self.targets, mode=mode)
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/auto/task.py", line 169, in run
    completed.results, completed.results_time = operation.fit(completed.data)
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/auto/operation.py", line 42, in wrapper
    out = func(*args, **kwds)
  File "/nfs/users/sergi.ramos/qibocal/src/qibocal/protocols/two_qubit_interaction/mermin/protocol.py", line 153, in _fit
    mitigated_output = np.dot(
ValueError: shapes (8,8) and (1,) not aligned: 8 (dim 1) != 1 (dim 0)

In the error mitigation part.

@Edoardo-Pedicillo
Copy link
Contributor Author

@DavidSarlle
Copy link
Collaborator

DavidSarlle commented Nov 28, 2024

@Edoardo-Pedicillo @igres26 I have tried with qblox and IQM chip and it seems to work using qibolab 0.1.
http://login.qrccluster.com:9000/sStJijTvQs6RbovUlHyHVA==

The only thing is that, qblox intruments are connected and disconnected multiple times:

�[38;20m[Qibocal 0.1.1|INFO|2024-11-28 11:27:56]: Executing mode AUTOCALIBRATION on mermin.�[0m
INFO:qibocal.config:Executing mode AUTOCALIBRATION on mermin.
[Qibo 0.2.12|INFO|2024-11-28 11:27:56]: Loading platform /home/users/david.fuentes/qibolab_platforms_qrc/iqm5q
INFO:qibo.config:Loading platform /home/users/david.fuentes/qibolab_platforms_qrc/iqm5q
[Qibo 0.2.12|INFO|2024-11-28 11:27:56]: Using qibolab (/home/users/david.fuentes/qibolab_platforms_qrc/iqm5q) backend on /CPU:0
INFO:qibo.config:Using qibolab (/home/users/david.fuentes/qibolab_platforms_qrc/iqm5q) backend on /CPU:0
[Qibo 0.2.12|INFO|2024-11-28 11:27:56]: Minimal execution time (sequence): 1.236992
INFO:qibo.config:Minimal execution time (sequence): 1.236992
[Qibo 0.2.12|INFO|2024-11-28 11:28:00]: Connecting to instrument <qibolab.instruments.qblox.controller.QbloxController object at 0x77a99e9e5c60>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.controller.QbloxController object at 0x77a99e9e5c60>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: QbloxController: all modules connected.
INFO:qibo.config:QbloxController: all modules connected.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.rohde_schwarz.SGS100A object at 0x77a99e9e5c90>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.rohde_schwarz.SGS100A object at 0x77a99e9e5c90>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f75ed0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f75ed0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f76bc0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f76bc0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5cf0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5cf0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5b70>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5b70>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5840>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5840>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7010>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7010>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7910>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7910>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7fd0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7fd0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7340>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7340>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:09]: Minimal execution time (sequence): 1.2373196800000001
INFO:qibo.config:Minimal execution time (sequence): 1.2373196800000001
[Qibo 0.2.12|INFO|2024-11-28 11:28:13]: Connecting to instrument <qibolab.instruments.qblox.controller.QbloxController object at 0x77a99e9e5c60>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.controller.QbloxController object at 0x77a99e9e5c60>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:21]: QbloxController: all modules connected.
INFO:qibo.config:QbloxController: all modules connected.
[Qibo 0.2.12|INFO|2024-11-28 11:28:21]: Connecting to instrument <qibolab.instruments.rohde_schwarz.SGS100A object at 0x77a99e9e5c90>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.rohde_schwarz.SGS100A object at 0x77a99e9e5c90>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f75ed0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f75ed0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f76bc0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qrm_rf.QrmRf object at 0x77a9a5f76bc0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5cf0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5cf0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5b70>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5b70>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5840>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_rf.QcmRf object at 0x77a99e9e5840>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7010>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7010>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7910>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7910>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7fd0>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7fd0>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7340>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.cluster_qcm_bb.QcmBb object at 0x77a99e9e7340>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:22]: Minimal execution time (sequence): 1.2373196800000001
INFO:qibo.config:Minimal execution time (sequence): 1.2373196800000001
[Qibo 0.2.12|INFO|2024-11-28 11:28:26]: Connecting to instrument <qibolab.instruments.qblox.controller.QbloxController object at 0x77a99e9e5c60>.
INFO:qibo.config:Connecting to instrument <qibolab.instruments.qblox.controller.QbloxController object at 0x77a99e9e5c60>.
[Qibo 0.2.12|INFO|2024-11-28 11:28:34]: QbloxController: all modules connected.
INFO:qibo.config:QbloxController: all modules connected.

Is it normal??

@Edoardo-Pedicillo
Copy link
Contributor Author

Is it normal??

Yes, because the platform is connected twice in the acquisition: when we evaluate the mitigation matrix, the platform is connected to execute the circuits and disconnected by Qibolab afterwards, so before running the Mermin experiment, we need to reconnect it again.

@Edoardo-Pedicillo Edoardo-Pedicillo added this pull request to the merge queue Nov 28, 2024
Merged via the queue into main with commit 1ecda26 Nov 28, 2024
21 checks passed
@Edoardo-Pedicillo Edoardo-Pedicillo deleted the mermin_refactor branch November 28, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants