def test_transpile_line_circuit(self):
     c = cirq.Circuit()
     qubits = [cirq.LineQubit(0), cirq.LineQubit(1)]
     c.append(cirq.H.on(qubits[0]))
     c.append(cirq.CNOT(*qubits))
     ic = cirq.ConvertToIonGates().convert_circuit(c)
     ic.append(
         cirq.measure_each(*qubits),
         strategy=cirq.circuits.InsertStrategy.NEW_THEN_INLINE,
     )
     jc = jaqal_circuit_from_cirq_circuit(ic)
     jcirc = CircuitBuilder()
     reg = jcirc.register("allqubits", 2)
     jcirc.gate("prepare_all")
     jcirc.gate("R", reg[0], pi, pi)
     jcirc.gate("MS", reg[0], reg[1], 0, pi / 2)
     block = jcirc.block(True)
     block.gate("R", reg[0], -1.5707963267948972, pi / 2)
     # Last few digits are off if we just use -pi/2
     block.gate("R", reg[1], pi, pi / 2)
     jcirc.gate("Rz", reg[0], -pi / 2)
     jcirc.gate("measure_all")
     self.assertEqual(
         generate_jaqal_program(jcirc.build()), generate_jaqal_program(jc)
     )
 def test_transpile_2q_circuit(self):
     qr = QuantumRegister(2)
     cr = ClassicalRegister(4)
     circ = QuantumCircuit(qr, cr)
     circ.x(qr[0])
     circ.measure(qr[0], cr[0])
     circ.measure(qr[1], cr[1])
     circ.barrier()
     circ.reset(qr[0])
     circ.reset(qr[1])
     circ.barrier()
     circ.y(qr[0])
     dag = circuit_to_dag(circ)
     jcirc = CircuitBuilder()
     reg1 = jcirc.register("baseregister", 2)
     reg2 = jcirc.map(qr.name, reg1, slice(0, 2, 1))
     block = jcirc.block()
     block.gate("prepare_all")
     block.gate("Px", reg2[0])
     block.gate("measure_all")
     block = jcirc.block()
     block.gate("prepare_all")
     block = jcirc.block()
     block.gate("Py", reg2[0])
     block.gate("measure_all")
     self.assertEqual(
         generate_jaqal_program(jcirc.build()),
         generate_jaqal_program(jaqal_circuit_from_dag_circuit(dag)),
     )
Ejemplo n.º 3
0
 def test_2_ion_compilation(self):
     p = Program()
     ro = p.declare("ro", "BIT", 6)
     p += X(0)
     p += MEASURE(0, ro[0])
     p += MEASURE(1, ro[1])
     p += RESET(0)
     p += RESET(1)
     p += X(1)
     p += MEASURE(1, ro[3])
     p += MEASURE(0, ro[2])
     p += RESET()
     p += X(0)
     p += MEASURE(0, ro[4])
     p += MEASURE(1, ro[5])
     qc = get_ion_qc(2)
     circ = qc.compile(p)
     jcirc = CircuitBuilder()
     reg = jcirc.register("qreg", 2)
     block = jcirc.block()
     block.gate("prepare_all")
     block.gate("Px", reg[0])
     block.gate("measure_all")
     block.gate("prepare_all")
     block.gate("Px", reg[1])
     block.gate("measure_all")
     block.gate("prepare_all")
     block.gate("Px", reg[0])
     block.gate("measure_all")
     self.assertEqual(generate_jaqal_program(jcirc.build()),
                      generate_jaqal_program(circ))
 def test_transpile_grid_circuit(self):
     c = Circuit()
     qb = pytket._tket.circuit.Qubit("grid", 0, 0)
     c.add_qubit(qb)
     c.Rz(1, qb)
     qsc = jaqal_circuit_from_tket_circuit(c)
     jcirc = CircuitBuilder()
     reg = jcirc.register("baseregister", 1)
     reg2 = jcirc.map("grid0_0", reg, slice(0, 1, 1))
     block = jcirc.block()
     block.gate("prepare_all")
     block.gate("Rz", reg2[0], pi)
     block.gate("measure_all")
     self.assertEqual(generate_jaqal_program(jcirc.build()),
                      generate_jaqal_program(qsc))
 def test_transpile_1q_circuit(self):
     c = Circuit(1, 1)
     c.Rz(1, 0)
     c.add_barrier([0])
     c.Measure(0, 0)
     qsc = jaqal_circuit_from_tket_circuit(c)
     jcirc = CircuitBuilder()
     reg = jcirc.register("baseregister", 1)
     reg2 = jcirc.map("q", reg, slice(0, 1, 1))
     block = jcirc.block()
     block.gate("prepare_all")
     block.gate("Rz", reg2[0], pi)
     block = jcirc.block()
     block.gate("measure_all")
     self.assertEqual(generate_jaqal_program(jcirc.build()),
                      generate_jaqal_program(qsc))
Ejemplo n.º 6
0
 def test_native_gates(self):
     gates = quil_gates()
     p = Program()
     ro = p.declare("ro", "BIT", 1)
     p += gates["SX"](0)
     p += MEASURE(0, ro[0])
     qc = get_ion_qc(1)
     circ = qc.compile(p)
     jcirc = CircuitBuilder()
     reg = jcirc.register("qreg", 1)
     block = jcirc.block()
     block.gate("prepare_all")
     block.gate("Sx", reg[0])
     block.gate("measure_all")
     self.assertEqual(generate_jaqal_program(jcirc.build()),
                      generate_jaqal_program(circ))
 def test_transpile_circuit(self):
     backend = JaqalBackend()
     engine_list = get_engine_list()
     eng = MainEngine(backend, engine_list, verbose=True)
     q1 = eng.allocate_qubit()
     q2 = eng.allocate_qubit()
     SqrtX | q1
     SqrtX | q2
     Barrier | (q1, q2)
     Rxx(1.0) | (q1, q2)
     All(Measure) | [q1, q2]
     eng.flush()
     circ = backend.circuit
     jcirc = CircuitBuilder()
     reg = jcirc.register("q", 2)
     block = jcirc.block()
     block.gate("prepare_all")
     block.gate("Sx", reg[0])
     block.gate("Sx", reg[1])
     block = jcirc.block()
     block.gate("MS", reg[0], reg[1], 0, 1.0)
     block.gate("measure_all")
     self.assertEqual(generate_jaqal_program(jcirc.build()),
                      generate_jaqal_program(circ))
Ejemplo n.º 8
0
    def receive(self, command_list):
        """
        Converts each instruction in the input into its Jaqal equivalent and saves it.
        This should rarely be called directly by users; usually it will be called by
        ``projectq.cengines.MainEngine``.

        :param command_list: The ProjectQ program to convert.
        :type command_list: list(projectq.ops.Command)
        """
        for cmd in command_list:
            if cmd.gate == FlushGate():
                if self.outfile is not None:
                    from jaqalpaq.generator import generate_jaqal_program

                    with open(self.outfile, "w+") as f:
                        f.write(generate_jaqal_program(self.circuit))
            else:
                self._store(cmd)
Ejemplo n.º 9
0
    def setUp(self):

        builder = CircuitBuilder(native_gates.NATIVE_GATES)

        pi2 = builder.let("pi2", np.pi / 2)
        q = builder.register("q", 3)

        builder.gate("prepare_all")
        builder.gate("MS", q[1], q[0], pi2, pi2)
        builder.gate("measure_all")

        self.c = builder.build()

        self.jaqal_string = generate_jaqal_program(self.c)

        self.jaqal_c = jaqalpaq.parser.parse_jaqal_string(
            self.jaqal_string,
            inject_pulses=normalize_native_gates(native_gates.NATIVE_GATES),
        )
Ejemplo n.º 10
0
import jaqalpaq
from jaqalpaq.parser import parse_jaqal_file
from jaqalpaq.emulator import run_jaqal_circuit
from jaqalpaq.generator import generate_jaqal_program

JaqalCircuitObject = parse_jaqal_file("jaqal/Sxx_circuit.jaqal")
JaqalCircuitResults = run_jaqal_circuit(JaqalCircuitObject)
print(
    f"Probabilities: {JaqalCircuitResults.subcircuits[0].probability_by_str}")
JaqalProgram = generate_jaqal_program(JaqalCircuitObject)
Ejemplo n.º 11
0
 def run_test_string(self, text):
     circuit1 = parse_jaqal_string(text, autoload_pulses=False)
     generated = generate_jaqal_program(circuit1)
     circuit2 = parse_jaqal_string(generated, autoload_pulses=False)
     self.assertEqual(circuit1, circuit2)