Skip to content

PyQrack seems to misinterpret Rz gate in this circuitΒ #222

@lamq317

Description

@lamq317

Even after #219 , the Rz gate seems to be misinterpret by PyQrack in the following minimal examples

import pyqrack
from qiskit.circuit import QuantumCircuit
from bloqade.qasm2.parse.lowering import QASM2
from bloqade import qasm2
from bloqade.pyqrack import PyQrack

test_qasmRz = """// Generated from Cirq v1.5.0
OPENQASM 2.0;
include "qelib1.inc";
// Qubits: [q_0, q_1, q_2]
qreg q[3];
h q[0];
cx q[0],q[1];
cx q[1],q[2];
rz(pi*0.1) q[2];
cx q[1],q[2];
cx q[0],q[1];
h q[0];
"""

test_qasmRy = """// Generated from Cirq v1.5.0
OPENQASM 2.0;
include "qelib1.inc";
// Qubits: [q_0, q_1, q_2]
qreg q[3];
h q[0];
cx q[0],q[1];
cx q[1],q[2];
ry(pi*0.1) q[2];
cx q[1],q[2];
cx q[0],q[1];
h q[0];
"""

def Direct_pyqrack_sim(qasm_str,qubitCount=3):
    sim = pyqrack.QrackSimulator(qubitCount=qubitCount)
    sim.run_qiskit_circuit(QuantumCircuit.from_qasm_str(qasm_str))

    return sim.out_ket()

def bloqade_pyqrack_sim(qasm_str):
    entry = QASM2(qasm2.main.add(qasm2.inline_)).loads(qasm_str, "entry", returns="q")
    result_pyqrack = PyQrack(dynamic_qubits=True).multi_run(entry, _shots=1)
    psi_bloqade = result_pyqrack[0][0].sim_reg.out_ket()

    return psi_bloqade


#pyqrack simulations
psi_pyqrack_Rz = Direct_pyqrack_sim(test_qasmRz)
psi_pyqrack_Ry = Direct_pyqrack_sim(test_qasmRy)

psi_bloqade_Rz = bloqade_pyqrack_sim(test_qasmRz)
psi_bloqade_Ry = bloqade_pyqrack_sim(test_qasmRy)

print("Overlap between bloqade-simulated and pyqrack simulated Rz circuit is:",np.abs(np.vdot(psi_pyqrack_Rz,psi_bloqade_Rz)))
print("Overlap between bloqade-simulated and pyqrack simulated Ry circuit is:",np.abs(np.vdot(psi_pyqrack_Ry,psi_bloqade_Ry)))

Simulation of test_qasmRz yields well below 1 fidelity. Removing any of the gates in test_qasmRz yields fidelity 1 after comparing with direct pyqrack simulation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions