Closed
Description
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