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

Bump cirq version from 0.10.0 to 0.13.0 #988

Merged
merged 17 commits into from
Feb 2, 2022

Conversation

vtomole
Copy link
Contributor

@vtomole vtomole commented Oct 17, 2021

Replacing #915

Description

Checklist

Check off the following once complete (or if not applicable) after opening the PR. The PR will be reviewed once this checklist is complete and all tests are passing.

If some items remain, you can mark this a draft pull request.

Tips

  • If the validation check fails:

    1. Run make check-types (from the root directory of the repository) and fix any mypy errors.

    2. Run make check-style and fix any flake8 errors.

    3. Run make format to format your code with the black autoformatter.

    For more information, check the Mitiq style guidelines.

  • Write "Fixes #XYZ" in the description if this PR fixes Issue #XYZ.

@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch vtomole/mitiq/patch-1

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello @vtomole, thank you for submitting a PR to Mitiq! We will respond as soon as possible, and if you have any questions in the meantime, you can ask us on the Unitary Fund Discord.

@vtomole
Copy link
Contributor Author

vtomole commented Oct 17, 2021

This change depends on either #927 or #935 for the checks to pass.

@rmlarose
Copy link
Contributor

Thanks @vtomole. Can you merge master? #992 handled pyquil. Should be good to go after this.

@vtomole
Copy link
Contributor Author

vtomole commented Oct 19, 2021

@rmlarose Done.

@nathanshammah
Copy link
Member

nathanshammah commented Oct 19, 2021

Thank you @vtomole. At validation there are these errors

mitiq/pec/representations/optimal.py:23: error: Module "cirq" has no attribute "channel"  [attr-defined]
mitiq/pec/representations/depolarizing.py:22: error: Module "cirq" has no attribute "channel"  [attr-defined]
mitiq/pec/representations/damping.py:22: error: Module "cirq" has no attribute "channel"  [attr-defined]
Found 3 errors in 3 files (checked 53 source files)

I could not track where channel ended up into in the current Cirq.

There are also these issues in tests with pennylane and PEC:

=========================== short test summary info ============================
FAILED mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py::test_integration
FAILED mitiq/cdr/tests/test_clifford_training_data.py::test_count_non_cliffords[pennylane]
ERROR mitiq/pec/representations/tests/test_damping.py
ERROR mitiq/pec/representations/tests/test_depolarizing.py
ERROR mitiq/pec/representations/tests/test_optimal.py
ERROR mitiq/pec/tests/test_channels.py
ERROR mitiq/pec/tests/test_pec.py
ERROR mitiq/pec/tests/test_pec_sampling.py
====== 2 failed, 984 passed, 124 warnings, 6 errors in 364.11s (0:06:04) =======
make: *** [Makefile:75: test-all] Error 1

@vtomole
Copy link
Contributor Author

vtomole commented Oct 19, 2021

cirq.channel was deprecated. I've pushed the updated changes.

@andreamari
Copy link
Member

@vtomole Thanks!
From the log of the tests, it seems that there are other cirq.channels around to be updated to cirq.kraus. Probably also in the PEC example of the docs.

There are also other strange errors on PennyLane tests that I don't immediately understand (maybe Cirq changed something about qasm conversions 🤔).

@vtomole
Copy link
Contributor Author

vtomole commented Oct 26, 2021

quantumlib/Cirq#4113 breaks the pennylane conversion to a point where

a, b = cirq.LineQubit.range(2)
    circuit = Circuit(
        cirq.rz(0.0).on(a),  # Clifford.
        cirq.rx(0.1 * np.pi).on(b),  # Non-Clifford.
        cirq.rx(0.5 * np.pi).on(b),  # Clifford
        cirq.rz(0.4 * np.pi).on(b),  # Non-Clifford.
        cirq.rz(0.5 * np.pi).on(b),  # Clifford.
        cirq.CNOT.on(a, b),  # Clifford.
    )

compiles to

cirq.Circuit(
        cirq.Rz(0.0).on(cirq.NamedQubit('q_0')),
        cirq.Rx(0.3141592653589793).on(cirq.NamedQubit('q_1')),

        cirq.Rz(1.5707963267948963).on(cirq.NamedQubit('q_1')),
        cirq.Ry(1.5707963267948968).on(cirq.NamedQubit('q_1')),
    
        cirq.Rz(-1.5707963267948966).on(cirq.NamedQubit('q_1')),
        cirq.Rz(1.2566370614359172).on(cirq.NamedQubit('q_1')),
        cirq.circuits.qasm_output.QasmUGate(theta=0, phi=0, lmda=0.5).on(cirq.NamedQubit('q_1')),
        cirq.CNOT(cirq.NamedQubit('q_0'), cirq.NamedQubit('q_1')),
        )

Notice the cirq.circuits.qasm_output.QasmUGate(theta=0, phi=0, lmda=0.5).on(cirq.NamedQubit('q_1')), gate.

@nathanshammah
Copy link
Member

Thanks for looking in detail into the breaking issue, @vtomole.

@vtomole
Copy link
Contributor Author

vtomole commented Nov 11, 2021

@nathanshammah What do you think is best way to fix this? I think we should raise this issue up to pennylane because pennylane_from_qasm

qfunc = pennylane_from_qasm(to_qasm(circuit))
is giving the incorrect conversion.

@vtomole
Copy link
Contributor Author

vtomole commented Nov 11, 2021

Pennylane doesn't support sx gate out of the box. It compiles it to a QubitUnitary instead

import pennylane

qasm_string = """
// Generated from Cirq v0.13.1

OPENQASM 2.0;
include "qelib1.inc";


// Qubits: [0, 1]
qreg q[2];


rz(0) q[0];
rx(pi*0.1) q[1];
sx q[1];
rz(pi*0.4) q[1];
s q[1];
cx q[0],q[1];
"""

qfunc = pennylane.from_qasm(qasm_string)

with pennylane.tape.QuantumTape() as tape:
        qfunc(wires=pennylane.wires.Wires(range(2)))

print(tape.operations)
# prints
# [RZ(0.0, wires=[0]), 
# RX(0.3141592653589793, wires=[1]), 
# QubitUnitary(array([[0.5+0.5j, 0.5-0.5j],
#        [0.5-0.5j, 0.5+0.5j]]), wires=[1]), 
#        RZ(1.2566370614359172, wires=[1]), 
#        S(wires=[1]), 
#        CNOT(wires=[0, 1])]

Just moved to PennyLaneAI/pennylane#1891

@vtomole
Copy link
Contributor Author

vtomole commented Nov 11, 2021

Not a solution; but to get this PR in we could remove the cirq.rx(0.5 * np.pi).on(b) operation, # Clifford out of this test.

@vtomole
Copy link
Contributor Author

vtomole commented Nov 12, 2021

The fix: PennyLaneAI/pennylane-qiskit#158

@andreamari
Copy link
Member

andreamari commented Nov 12, 2021

The fix: PennyLaneAI/pennylane-qiskit#158

Thanks for asking for this fix in PL, @vtomole! Given this fact, I think we just need to wait.

@nathanshammah
Copy link
Member

Great suggestion, @vtomole!

@vtomole
Copy link
Contributor Author

vtomole commented Nov 12, 2021

Given this fact, I think we just need to wait.

Great suggestion

I'm getting conflicting information. Should we wait for that Pennylane PR to get merged and for Pennylane to cut a new release before we merge this or should we modify the test here so it passes for us?

@nathanshammah
Copy link
Member

@vtomole I referred to the idea of upstreaming this to Pennylane and the issue you opened on Pennylane. Let's wait for that release. We can also discuss at the Mitiq meeting if you want to join, at 12pm ET on http://discord.unitary.fund/

@vtomole
Copy link
Contributor Author

vtomole commented Nov 12, 2021

Okay, thanks for clearing that up!

@vtomole
Copy link
Contributor Author

vtomole commented Dec 14, 2021

@rmlarose @nathanshammah @rmlarose Ready for re-review 🙂

@nathanshammah
Copy link
Member

Probably this will have the same issue of #1048(?), the pennylane update. #1049 updates pennylane-qiskit.

@vtomole
Copy link
Contributor Author

vtomole commented Jan 27, 2022

The docs check is failing with a

Command killed due to excessive memory consumption

message.

@crazy4pi314
Copy link
Member

The docs check is failing with a

Command killed due to excessive memory consumption

message.

This can randomly happen when one of the examples has a call to scipy.fit that does not converge, often re-running (which I just kicked off) should allow it to proceed if that was the issue.

@codecov
Copy link

codecov bot commented Jan 27, 2022

Codecov Report

Merging #988 (851d7c3) into master (84385d9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #988   +/-   ##
=======================================
  Coverage   97.98%   97.98%           
=======================================
  Files          54       54           
  Lines        2527     2527           
=======================================
  Hits         2476     2476           
  Misses         51       51           
Impacted Files Coverage Δ
mitiq/pec/representations/damping.py 100.00% <100.00%> (ø)
mitiq/pec/representations/depolarizing.py 100.00% <100.00%> (ø)
mitiq/pec/representations/optimal.py 97.22% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84385d9...851d7c3. Read the comment docs.

@vtomole
Copy link
Contributor Author

vtomole commented Jan 27, 2022

@nathanshammah @andreamari Ready for re-review :)

u_1 = cirq.unitary(base_circ)
u_2 = cirq.unitary(circ_recovered)

assert np.allclose(u_1, u_2)
cirq.testing.assert_allclose_up_to_global_phase(u_1, u_2, atol=0)
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Comment on lines -140 to -149
params = list(np.pi * np.random.rand(gate.num_params))
rnd_wires = np.random.choice(
range(n_wires), size=gate.num_wires, replace=False
)
gate(
*params,
wires=[
int(w) for w in rnd_wires
], # make sure we do not address wires as 0-d arrays
)
Copy link
Member

Choose a reason for hiding this comment

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

I guess you had to remove this for some tricky reason.
If not possible to re-introduce:

  • Can we restore the random rotation parameters only?
  • Can we restore the random wires only?

If not, it's fine. This is not a blocker for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this change is because gate.num_params is now dynamic. Since this test is copied from pennylane, the following PR recommends re-writing the test this way. See https://github.com/PennyLaneAI/pennylane/pull/1898/files#r750946650.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see, very nice finding!

@andreamari andreamari self-requested a review January 31, 2022 09:58
Copy link
Member

@andreamari andreamari left a comment

Choose a reason for hiding this comment

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

Many thanks @vtomole! LGTM
(running all the tests now, we can merge once they pass)

@nathanshammah
Copy link
Member

Thanks @vtomole! LGTM. I opened #1112 to check that RTD does not fail on all PRs. I will restart the checks to see if now they pass. It was killed for eccessive memory consumption.

@andreamari
Copy link
Member

Hi @astrojuanlu, do you know why RDT is failing for this PR (and only for this PR)?

My guess, please correct me if I am wrong, is this: due to a slightly longer pip install process, the docs build of this PR exceeds the 15 minutes limit that is discussed at this page (https://docs.readthedocs.io/en/stable/builds.html).
In the same page it is also written that:

We can increase build limits on a per-project basis. Send an email to [email protected] providing a good reason why your documentation needs more resources.

Do you think we can get some extra build time? This would help us unblock urgent PRs until we find a more scalable solution for the docs.

@astrojuanlu
Copy link

Hi @andreamari ! It looks like the other builds are on the edge of the 15 minute limit. Looks like most of the build time is spent executing notebooks, which makes a ton of sense. Please send an email to [email protected] and the support team will take care of it :)

@nathanshammah
Copy link
Member

Thanks @astrojuanlu for the info and @andreamari for investigating.

If we switch in the future to Jupyter book, it may be simpler to cache notebooks (at least for some CI checks).

@andreamari
Copy link
Member

andreamari commented Feb 1, 2022

Hi @andreamari ! It looks like the other builds are on the edge of the 15 minute limit. Looks like most of the build time is spent executing notebooks, which makes a ton of sense. Please send an email to [email protected] and the support team will take care of it :)

I just sent and email to [email protected], thanks for the advice!

Copy link
Member

@nathanshammah nathanshammah left a comment

Choose a reason for hiding this comment

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

Thank you @vtomole, all tests now pass.

@nathanshammah nathanshammah merged commit b687150 into unitaryfund:master Feb 2, 2022
@andreamari
Copy link
Member

And also thanks to @astrojuanlu (RTD is working now)!

@vtomole
Copy link
Contributor Author

vtomole commented Feb 2, 2022

@nathanshammah @andreamari Thanks for your patience!

@vtomole vtomole deleted the patch-1 branch February 2, 2022 15:17
@andreamari andreamari mentioned this pull request Feb 2, 2022
4 tasks
@andreamari
Copy link
Member

@allcontributors please add @vtomole for tests and code

@allcontributors
Copy link
Contributor

@andreamari

I've put up a pull request to add @vtomole! 🎉

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.

Update version of Cirq in core requirements
6 participants