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

Update GST to take in gates.Unitary #1587

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Update GST to take in gates.Unitary #1587

wants to merge 26 commits into from

Conversation

mho291
Copy link
Contributor

@mho291 mho291 commented Feb 12, 2025

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

Comment on lines 301 to 308
if isinstance(params, list):
init_args = signature(gate).parameters
valid_angles = [arg for arg in init_args if arg in angles]
angle_values = dict(zip(valid_angles, params))
else:
init_args = signature(gate).parameters
valid_angles = [arg for arg in init_args if arg in matrix]
angle_values = dict(zip(valid_angles, [params]))
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
if isinstance(params, list):
init_args = signature(gate).parameters
valid_angles = [arg for arg in init_args if arg in angles]
angle_values = dict(zip(valid_angles, params))
else:
init_args = signature(gate).parameters
valid_angles = [arg for arg in init_args if arg in matrix]
angle_values = dict(zip(valid_angles, [params]))
if not isinstance(params, list):
params = [params]
init_args = signature(gate).parameters
valid_angles = [arg for arg in init_args if arg in angles]
angle_values = dict(zip(valid_angles, params))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @renatomello for spotting this. I have made the changes. But still trying to get it to work. It's currently complaining

FAILED tests/test_tomography_gate_set_tomography.py::test_GST[numpy-False-target_gates0] - ValueError: axes don't match array
FAILED tests/test_tomography_gate_set_tomography.py::test_GST[numpy-True-target_gates0] - ValueError: axes don't match array
FAILED tests/test_tomography_gate_set_tomography.py::test_GST[qibojit-numba-False-target_gates0] - ValueError: axes don't match array
FAILED tests/test_tomography_gate_set_tomography.py::test_GST[qibojit-numba-True-target_gates0] - ValueError: axes don't match array

Will keep trying to debug.

@@ -233,8 +235,7 @@ def GST(
gate_set (tuple or set or list): set of :class:`qibo.gates.Gate` and parameters to run
GST on.
E.g. gate_set = [(gates.RX, [np.pi/3]), gates.Z, (gates.PRX, [np.pi/2, np.pi/3]),
(gates.GPI, [np.pi/7]), gates.CNOT,
(gates.Unitary, (np.array([[1,0],[0,1]])))]
(gates.GPI, [np.pi/7]), gates.CNOT]
Copy link
Contributor

Choose a reason for hiding this comment

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

This docstring is generating a warning when the documentation is compiled because of identation. I fixed it in #1584. Please look at it to also fix it here.

@mho291
Copy link
Contributor Author

mho291 commented Mar 4, 2025

Hi @MatteoRobbiati, I need some advice with this. When I run the pytests locally, they pass. But here, they always run into dimension error:

FAILED tests/test_tomography_gate_set_tomography.py::test_GST[qiboml-pytorch-False-target_gates0] - RuntimeError: permute(sparse_coo): number of dimensions in the tensor input does not match the length of the desired ordering of dimensions i.e. input.dim() = 1 is not equal to len(dims) = 2

Could there be an issue with qiboml-pytorch?

Thanks so much!

@MatteoRobbiati
Copy link
Contributor

Could there be an issue with qiboml-pytorch?

Ehi @mho291! Thanks for asking :)
I tested locally your branch and in my case I get the same failure, but on all the backends (numpy, qibojit, pytorch, tensorflow), so ig the source of the problem is elsewhere.
It seems to me the problem is appearing when calling this line in gates.py.

Copy link

codecov bot commented Mar 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.11%. Comparing base (3a13d61) to head (091519a).
Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1587   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files          77       77           
  Lines       11480    11518   +38     
=======================================
+ Hits        11378    11416   +38     
  Misses        102      102           
Flag Coverage Δ
unittests 99.11% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mho291 mho291 marked this pull request as ready for review March 25, 2025 01:56
@mho291
Copy link
Contributor Author

mho291 commented Mar 25, 2025

Could there be an issue with qiboml-pytorch?

Ehi @mho291! Thanks for asking :) I tested locally your branch and in my case I get the same failure, but on all the backends (numpy, qibojit, pytorch, tensorflow), so ig the source of the problem is elsewhere. It seems to me the problem is appearing when calling this line in gates.py.

Hi @MatteoRobbiati ! Sorry for the radio silence for the past two weeks as I was away. I revisited this PR yesterday and the tests no longer fail on GitHub (but not my local machine), so I tidied it up anyway, and it is ready for review now. Greatly appreciate your help!

@mho291
Copy link
Contributor Author

mho291 commented Apr 3, 2025

I have added an option for ancilla=True or ancilla=False. When ancilla=True, it will simulate a resetting to |0> state by disabling the line circ.add(_prepare_state(k, nqubits)). This is crucial to do GST of certain basis operations in probabilistic error cancellation that require resetting the quantum state to |0> to re-prepare state |0> , |+>, or |y+> (reference paper: Appendix D, Table II).

The ancilla flag, together with the ability to input gates.Unitary gates in GST, will most likely be the final version of GST that can be used for probabilistic error cancellation, which I am working on locally (single qubit & two qubit PEC), and will do a PR soon.

@mho291
Copy link
Contributor Author

mho291 commented Apr 4, 2025

Sorry, please hold the review, I will need to modify the current changes to increase the functionality!

@mho291
Copy link
Contributor Author

mho291 commented Apr 8, 2025

Sorry, please hold the review, I will need to modify the current changes to increase the functionality!

The code is now ready for review! :)

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.

3 participants