var QuantumCircuit = require("../../lib/debug.js");
var circ = new QuantumCircuit();
circ.addGate("cr2", -1, [0, 1, 2]);
circ.addMeasure(1, "c", 3);
circ.run();
console.log("");
console.log(circ.exportCirq());
The exported cirq program is as follows:
import cirq
import numpy as np
q = [cirq.NamedQubit('q' + str(i)) for i in range(3)]
circuit = cirq.Circuit.from_ops(
cu1(np.pi / 2)(q[0], q[1], q[2]),
cirq.measure(q[1], key='c3')
)
simulator = cirq.google.XmonSimulator()
result = simulator.run(circuit)
print(result)
The gate cu1 does not belong to cirq's gate set and hence will result in an error if I try to run this program in cirq. cu1 or better still crz with an angle pi/2 (since cr2 is a controlled-RZ rotation with angle pi/2) needs to be defined in order to make the program work. Same goes for cr4 and cr8.
Another issue I came across was with the gate crz. If I have the following program:
var QuantumCircuit = require("../../lib/debug.js");
var circ = new QuantumCircuit();
circ.addGate("crz", -1, [0, 1], {
params: {
phi: "pi/2"
}
});
circ.addMeasure(1, "c", 3);
This outputs the following cirq program:
import cirq
import numpy as np
def crz(p_phi):
return cirq.TwoQubitMatrixGate(np.array([ [1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0, np.exp(1j * p_phi)] ]))
q = [cirq.NamedQubit('q' + str(i)) for i in range(2)]
circuit = cirq.Circuit.from_ops(
cu1(np.pi / 2)(q[0], q[1]),
cirq.measure(q[1], key='c3')
)
simulator = cirq.google.XmonSimulator()
result = simulator.run(circuit)
print(result)
The used gate is crz which is also defined but the circuit is created with cu1. I think the circuit should be created with crz.
I will raise a PR with changes that I think will solve these issues. :)
Till then, please let me know if I am missing something or if there could be some other workaround. :)
Hi! I have the following program :
The exported cirq program is as follows:
The gate
cu1
does not belong to cirq's gate set and hence will result in an error if I try to run this program in cirq.cu1
or better stillcrz
with an anglepi/2
(sincecr2
is a controlled-RZ rotation with anglepi/2
) needs to be defined in order to make the program work. Same goes forcr4
andcr8
.Another issue I came across was with the gate
crz
. If I have the following program:This outputs the following cirq program:
The used gate is
crz
which is also defined but thecircuit
is created withcu1
. I think the circuit should be created withcrz
.I will raise a PR with changes that I think will solve these issues. :) Till then, please let me know if I am missing something or if there could be some other workaround. :)