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(cirq-rigetti): use pyquil v4 #6281

Open
wants to merge 111 commits into
base: main
Choose a base branch
from

Conversation

jselig-rigetti
Copy link

Refactors as necessary to anticipate the release of PyQuil v4. Changes between the RC used here and the eventual full release should be compatible, but leave this MR as a draft until the dependency can be pinned to a full >=4.0.0 release.

@google-cla
Copy link

google-cla bot commented Sep 6, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@CirqBot CirqBot added the size: M 50< lines changed <250 label Sep 6, 2023
@jselig-rigetti jselig-rigetti force-pushed the rigetti-use-pyquil-v4 branch 2 times, most recently from d8c1e61 to 1787c12 Compare September 6, 2023 22:12
raise ValueError(f'Symbols not valid for region name {region_name}')
qam_execution_result = quantum_computer.qam.run(executable)
qam_execution_result = quantum_computer.qam.run(executable, memory_map)

Choose a reason for hiding this comment

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

We need to check for atomic values and wrap them in a list to prevent a breaking change here.

In v3, Program.write_memory accepted atomic values for memory regions of length 1. For example, Program.write_memory("ro", 1) was valid if ro was defined as DECLARE ro BIT[1]. In v4, the new MemoryMap only accepts sequences of values for a memory region, even if that memory region happens to be length 1.

Copy link
Author

Choose a reason for hiding this comment

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

fixed this in the lines above 👍

@vtomole
Copy link
Collaborator

vtomole commented Sep 18, 2023

Hey @jselig-rigetti @MarquessV

Can either of you please review rigetti/qcs-api-client-python#12? It's been causing incompatibility issues with Cirq.

@jselig-rigetti jselig-rigetti marked this pull request as ready for review September 20, 2023 15:14
@jselig-rigetti jselig-rigetti force-pushed the rigetti-use-pyquil-v4 branch 2 times, most recently from 86fa3dc to c5f7f3a Compare October 19, 2023 15:07
@vtomole
Copy link
Collaborator

vtomole commented Nov 16, 2023

@jselig-rigetti @MarquessV Hey, how's this PR going?

@MarquessV
Copy link

Hey @vtomole! This PR is ready to review from our perspective. Anything else you need us to do?

Copy link
Author

@jselig-rigetti jselig-rigetti left a comment

Choose a reason for hiding this comment

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

@bramathon Can you please take a look at the 6 comments/questions in this review thread? I've fixed most of the other conflicts but am not sure what to do in the remaining circumstances

op = gate1(beta=np.pi, theta=np.pi)(cirq.LineQubit(0), cirq.LineQubit(1))
op_id = cirq.OpIdentifier(gate2)

assert op in op_id
Copy link
Author

Choose a reason for hiding this comment

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

This test is failing with this message:

<abc.PHASEDXY object at 0x144e5e210>.on(cirq.LineQubit(0), cirq.LineQubit(1))

in

cirq.devices.noise_utils.OpIdentifier(abc.PHASEDXY, )

Inspecting the variables here, I'd expect this test to pass based on the implementation at https://github.com/quantumlib/Cirq/blob/main/cirq-core/cirq/ops/gateset.py#L226:

op.gate
# <abc.PHASEDXY object at 0x13f8e9dd0>

op_id._gate_family.gate
# <class 'abc.PHASEDXY'>

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand how this could happen either.

Copy link
Author

Choose a reason for hiding this comment

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

@bramathon If I change the test to the following, only the second one fails

    gate1 = defgate_to_cirq(defgate)
    gate2 = defgate_to_cirq(defgate)

    op = gate1(beta=np.pi, theta=np.pi)(cirq.LineQubit(0), cirq.LineQubit(1))

    assert op in cirq.OpIdentifier(gate1) # passes
    assert op in cirq.OpIdentifier(gate2) # fails

Looks like this is because defgate_to_cirq is creating a whole new class each time it's called - I've added a @cached_method decorator on to defgate_to_cirq and it seems the tests are passing now. Let me know if this solution is undesirable

cirq-rigetti/cirq_rigetti/quil_input.py Outdated Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/quil_input.py Outdated Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/quil_input.py Outdated Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/quil_input.py Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/quil_input.py Outdated Show resolved Hide resolved
@jselig-rigetti
Copy link
Author

@pavoljuhas thanks for offering to help - I've fixed the format/lint/type/test errors I've found locally, so I believe this should be ready for final review pending feedback on the thread #6281 (comment)

I'm not sure why the CI pipeline is still waiting to run its checks though.

def get_quilt_calibrations(quantum_processor_id: str, client: Optional[QCSClient]) -> str: # pragma: no cover
def get_quilt_calibrations(
quantum_processor_id: str, client: Optional[QCSClient]
) -> str: # pragma: no cover
Copy link
Author

Choose a reason for hiding this comment

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

This likely doesn't need to be tested as it's just a convenience method for an API call, and there's no mock for QCSClient.

@jselig-rigetti
Copy link
Author

I added pragma: no cover to all lines that failed the coverage test as part of 8412760 mostly as a way to show where coverage needed to be added, although not everything looks like it does need a test

@pavoljuhas
Copy link
Collaborator

The failure of pytest ubuntu (3.12) appears to be caused by rigetti/pyquil#1736. The latest "pyquil==4.10.1" can be installed to Python 3.12.0, but not to 3.12.1 or later.

Would it be possible to do a patch release of pyquil with a fixed Python version requirement?

Copy link

codecov bot commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 98.85932% with 3 lines in your changes missing coverage. Please review.

Project coverage is 97.81%. Comparing base (543d9cd) to head (ef4c1f3).
Report is 1 commits behind head on main.

Current head ef4c1f3 differs from pull request most recent head 5245a7d

Please upload reports for the commit 5245a7d to get more accurate results.

Files Patch % Lines
cirq-rigetti/cirq_rigetti/aspen_device.py 90.00% 1 Missing ⚠️
cirq-rigetti/cirq_rigetti/conftest.py 92.85% 1 Missing ⚠️
cirq-rigetti/cirq_rigetti/quil_input.py 99.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6281      +/-   ##
==========================================
- Coverage   97.81%   97.81%   -0.01%     
==========================================
  Files        1067     1066       -1     
  Lines       91550    91693     +143     
==========================================
+ Hits        89549    89686     +137     
- Misses       2001     2007       +6     

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

@jselig-rigetti
Copy link
Author

The failure of pytest ubuntu (3.12) appears to be caused by rigetti/pyquil#1736. The latest "pyquil==4.10.1" can be installed to Python 3.12.0, but not to 3.12.1 or later.

Would it be possible to do a patch release of pyquil with a fixed Python version requirement?

Ah thank you, rigetti/pyquil#1782 will merge soon which should clear that up

@pavoljuhas
Copy link
Collaborator

The failure of pytest ubuntu (3.12) appears to be caused by rigetti/pyquil#1736. The latest "pyquil==4.10.1" can be installed to Python 3.12.0, but not to 3.12.1 or later.
Would it be possible to do a patch release of pyquil with a fixed Python version requirement?

Ah thank you, rigetti/pyquil#1782 will merge soon which should clear that up

Sounds great. Please consider applying the patch at the comment #6281 (comment) here.
It should make the CI tests pass here with Python 3.12, without a need to wait for the next pyquil release on PyPI.

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

A couple of small issues, please see inline comments.
Otherwise it seems to be close, thank you!

cirq-rigetti/cirq_rigetti/aspen_device_test.py Outdated Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/quil_input_test.py Outdated Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/service.py Outdated Show resolved Hide resolved
cirq-rigetti/cirq_rigetti/service_test.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet