quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.28k stars 1.02k forks source link

Regression in PyQuil `CPHASE00` conversions #6714

Open natestemen opened 2 months ago

natestemen commented 2 months ago

Description of the issue

When converting a PyQuil program to a Cirq circuit using the cirq_rigetti.circuit_from_quil function the output differs between cirq versions 1.4.1 and 1.3.0. Specifically, in cirq==1.4.1, the CPHASE00 gate is converted into a custom USERGATE gate with complex matrix elements, while in cirq==1.3.0, the gate is correctly recognized and output as CPHASE00.

How to reproduce the issue

  1. Create a file pyquil_conv.py with the following script.

    from cirq_rigetti import circuit_from_quil
    from cirq_rigetti.quil_output import QuilOutput
    from pyquil import Program
    
    QUIL_PROGRAM = """
    RZ(pi/2) 0
    CPHASE00(pi/2) 0 1
    """
    
    p = Program(QUIL_PROGRAM)
    circ = circuit_from_quil(p.out())
    print(QuilOutput(circ.all_operations(), circ.all_qubits()))
  2. Run the script with cirq==1.4.1

    $ pip list | grep -E "cirq-core|cirq-rigetti"
    cirq-core                       1.4.1
    cirq-rigetti                    1.4.1
    $ python pyquil_conv.py
    # Created using Cirq.
    
    RZ(1.5707963267948966) 0
    DEFGATE USERGATE1:
        6.123233995736766e-17+1.0i, 0.0+0.0i, 0.0+0.0i, 0.0+0.0i
        0.0+0.0i, 1.0+0.0i, 0.0+0.0i, 0.0+0.0i
        0.0+0.0i, 0.0+0.0i, 1.0+0.0i, 0.0+0.0i
        0.0+0.0i, 0.0+0.0i, 0.0+0.0i, 1.0+0.0i
    USERGATE1 0 1
  3. Run the script with cirq==1.3.0

    $ pip list | grep -E "cirq-core|cirq-rigetti"
    cirq-core                1.3.0
    cirq-rigetti             1.3.0
    $ python pyquil_conv.py
    # Created using Cirq.
    
    RZ(1.5707963267948966) 0
    CPHASE00(1.5707963267948966) 0 1

Related

When adding support for pyquil v4 a similar example was found in https://github.com/quantumlib/Cirq/pull/6281#issuecomment-2075385259.