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

Inconsistent behavior of Default Insert Strategy #6711

Open
glanzz opened this issue Aug 25, 2024 · 1 comment
Open

Inconsistent behavior of Default Insert Strategy #6711

glanzz opened this issue Aug 25, 2024 · 1 comment
Labels
area/qasm kind/bug-report Something doesn't seem to work. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@glanzz
Copy link

glanzz commented Aug 25, 2024

Description of the issue
The default insert strategy is placing the given list of gates in different positions.
How to reproduce the issue

from cirq.contrib.qasm_import import circuit_from_qasm
from cirq import Simulator, measure_each, X
import cirq as c


circuit = None
with open("mycircuit.qasm", "r") as file:
    circuit = circuit_from_qasm(file.read())


s = Simulator()
qubits = [X(q) for q in circuit.all_qubits()]
circuit.insert(0, qubits)
circuit.append(measure_each(*circuit.all_qubits()))

print(circuit)
REPEATS = 100
result = s.run(circuit,repetitions=REPEATS)

counter = result.multi_measurement_histogram(keys=[key for key in result.measurements])

resultdict = {}
for k in counter:
    key = "".join([str(v) for v in k])
    resultdict[key] = resultdict.get(key, 0) + counter[k]
print(resultdict)

mycircuit.qasm

OPENQASM 2.0;
OPENQASM 2.0;
include "qelib1.inc";
qreg q[7];
id q[6];
h q[4];
cx q[1],q[4];
tdg q[4];
cx q[0],q[4];
t q[4];
cx q[1],q[4];
tdg q[4];
cx q[0],q[4];
t q[1];
t q[4];
cx q[0],q[1];
h q[4];
t q[0];
tdg q[1];
cx q[0],q[1];
h q[3];
cx q[2],q[3];
tdg q[3];
cx q[5],q[3];
t q[3];
cx q[2],q[3];
tdg q[3];
cx q[5],q[3];
t q[2];
t q[3];
cx q[5],q[2];
h q[3];
t q[5];
tdg q[2];
cx q[5],q[2];
ch q[3],q[1];
ch q[0],q[2];
cz q[5],q[6];
ry(3.1383122094800475) q[4];
h q[6];
Run1:
                ┌──┐          ┌──┐       ┌──┐          ┌──┐   ┌──┐          ┌───────────┐   ┌──┐
q_0: ───X──────────────────────@────────────────────────@──────@─────T───────@────────────────@────M───────
                               │                        │      │             │                │
q_1: ───X────────@─────────────┼──────────@─────T───────┼──────X─────T^-1────X───────────────H┼────M───────
                 │             │          │             │                                    ││
q_2: ───X────────┼@────────────┼──────────┼@────T───────┼───────X────T^-1────X───────────────┼H────M───────
                 ││            │          ││            │       │            │               │
q_3: ───X───H────┼X────T^-1────┼X────T────┼X────T^-1────┼X─────T┼────H───────┼───────────────@─────M───────
                 │             ││         │             ││      │            │
q_4: ───X───H────X─────T^-1────X┼────T────X─────T^-1────X┼─────T┼────H───────┼Ry(0.999π)─────M─────────────
                                │                        │      │            │
q_5: ───X───────────────────────@────────────────────────@──────@────T───────@───────────────@─────M───────
                                                                                             │
q_6: ───X───I────────────────────────────────────────────────────────────────────────────────@─────H───M───
                └──┘          └──┘       └──┘          └──┘   └──┘          └───────────┘   └──┘
Counter({(1, 0, 1, 1, 1, 1, 0): 29, (1, 0, 1, 1, 1, 1, 1): 24, (1, 0, 1, 1, 0, 1, 1): 24, (1, 0, 1, 1, 0, 1, 0): 23})
{'1011111': 24, '1011110': 29, '1011010': 23, '1011011': 24}
Run2:
                ┌──┐          ┌──┐       ┌──┐          ┌──┐   ┌──┐          ┌───────────┐   ┌──┐
q_0: ───X──────────────────────@────────────────────────@──────@─────T───────@────────────────@────M───────
                               │                        │      │             │                │
q_1: ───X────────@─────────────┼──────────@─────T───────┼──────X─────T^-1────X───────────────H┼────M───────
                 │             │          │             │                                    ││
q_2: ───X────────┼@────────────┼──────────┼@────T───────┼───────X────T^-1────X───────────────┼H────M───────
                 ││            │          ││            │       │            │               │
q_3: ───H───X────┼X────T^-1────┼X────T────┼X────T^-1────┼X─────T┼────H───────┼───────────────@─────M───────
                 │             ││         │             ││      │            │
q_4: ───H───X────X─────T^-1────X┼────T────X─────T^-1────X┼─────T┼────H───────┼Ry(0.999π)─────M─────────────
                                │                        │      │            │
q_5: ───X───────────────────────@────────────────────────@──────@────T───────@───────────────@─────M───────
                                                                                             │
q_6: ───I───X────────────────────────────────────────────────────────────────────────────────@─────H───M───
                └──┘          └──┘       └──┘          └──┘   └──┘          └───────────┘   └──┘
Counter({(0, 1, 1, 0, 1, 1, 1): 24, (0, 1, 1, 1, 1, 1, 1): 13, (0, 1, 0, 1, 1, 1, 1): 13, (0, 1, 0, 0, 1, 1, 0): 12, (0, 1, 1, 0, 1, 1, 0): 10, (0, 1, 1, 1, 1, 1, 0): 10, (0, 1, 0, 1, 1, 1, 0): 9, (0, 1, 0, 0, 1, 1, 1): 9})
{'0100110': 12, '0101110': 9, '0100111': 9, '0111111': 13, '0110110': 10, '0111110': 10, '0110111': 24, '0101111': 13}

Cirq version
You can get the cirq version by printing cirq.__version__. From the command line:

Cirq Version: 1.4.1
@glanzz glanzz added the kind/bug-report Something doesn't seem to work. label Aug 25, 2024
@pavoljuhas pavoljuhas added the triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on label Sep 4, 2024
@pavoljuhas
Copy link
Collaborator

csynque meeting - H gates for the q_3 and q_4 qubits at the 0 position seem incorrect, indeed it looks like a bug here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qasm kind/bug-report Something doesn't seem to work. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

No branches or pull requests

3 participants