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

paulistring optimize_test.py: Changed Z gate string representation #5546

Closed
verult opened this issue Jun 17, 2022 · 2 comments · Fixed by #5643
Closed

paulistring optimize_test.py: Changed Z gate string representation #5546

verult opened this issue Jun 17, 2022 · 2 comments · Fixed by #5643
Assignees
Labels
area/contrib kind/bug-report Something doesn't seem to work. priority/p3 should be done in the next 6 months triage/discuss Needs decision / discussion, bring these up during Cirq Cynque

Comments

@verult
Copy link
Collaborator

verult commented Jun 17, 2022

Description of the issue
CI coverage check failed in #5445 for cirq-core/cirq/contrib/paulistring/optimize_test.py:

deftest_optimize():
        q0, q1, q2 = cirq.LineQubit.range(3)
        c_orig = cirq.Circuit(
            cirq.X(q0) ** 0.5,
            cirq.X(q1),
            cirq.CZ(q1, q2),
            cirq.X(q2) ** 0.125,
            cirq.Z(q1) ** 0.5,
            cirq.Y(q1) ** 0.5,
            cirq.CZ(q0, q1),
            cirq.Z(q1) ** 0.5,
            cirq.CZ(q1, q2),
            cirq.Z(q1) ** 0.5,
            cirq.X(q2) ** 0.875,
            cirq.CZ(q1, q2),
            cirq.X(q2) ** 0.125,
        )
        cirq.testing.assert_has_diagram(
            c_orig,
"""
0: ───X^0.5─────────────────────────@───────────────────────────────────
                                    │
1: ───X───────@───S─────────Y^0.5───@───S───@───S─────────@─────────────
              │                             │             │
2: ───────────@───X^(1/8)───────────────────@───X^(7/8)───@───X^(1/8)───
""",
        )
        c_opt = optimized_circuit(c_orig)
        cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-6)
>       cirq.testing.assert_has_diagram(
            c_opt,
"""
0: ───X^0.5────────────@────────────────────────────────────────
                       │
1: ───@───────X^-0.5───@───@────────────────@───Z^-0.5──────────
      │                    │                │
2: ───@────────────────────@───[X]^(-7/8)───@───[X]^-0.25───Z───
""",
        )
E       AssertionError: Circuit's text diagram differs from the desired diagram.
E       
E       Diagram of actual circuit:
E       0: ───X^0.5────────────@──────────────────────────────────────────────
E                              │
E       1: ───@───────X^-0.5───@───@────────────────@───Z^-0.5────────────────
E             │                    │                │
E       2: ───@────────────────────@───[X]^(-7/8)───@───[X]^-0.25───[Z]^(1)───
E       
E       Desired text diagram:
E       0: ───X^0.5────────────@────────────────────────────────────────
E                              │
E       1: ───@───────X^-0.5───@───@────────────────@───Z^-0.5──────────
E             │                    │                │
E       2: ───@────────────────────@───[X]^(-7/8)───@───[X]^-0.25───Z───
E       
E       Highlighted differences:
E       0: ───X^0.5────────────@────────────────────────────────────────██████
E                              │
E       1: ───@───────X^-0.5───@───@────────────────@───Z^-0.5──────────██████
E             │                    │                │
E       2: ───@────────────────────@───[X]^(-7/8)───@───[X]^-0.25───██████████
cirq-core/cirq/contrib/paulistring/optimize_test.py:53: AssertionError

This test only started failing after pulling in Cirq head. The cause is possibly a bad interaction between the latest changes and the swap from `AnyUnitaryGateFamily(1)` to `PhasedXZGate` in `CZTargetGateset`.

Fixing for now by changing the expected Z gate string.
@viathor
Copy link
Collaborator

viathor commented Jun 22, 2022

I don't think we should be making unit exponent explicit. We definitely shouldn't do it in an arbitrary way.

@viathor viathor added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Jun 22, 2022
@dstrain115
Copy link
Collaborator

@tanujkhattar will take a look at it and fix it or close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/contrib kind/bug-report Something doesn't seem to work. priority/p3 should be done in the next 6 months triage/discuss Needs decision / discussion, bring these up during Cirq Cynque
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants