Beispiel #1
0
 def test_maintain_native_gates(self):
     """Make sure the native gates are properly passed through to the new
     circuit."""
     native_gates = {"foo": core.GateDefinition("foo")}
     text = "foo"
     exp_text = "foo"
     self.run_test(text, exp_text, inject_pulses=native_gates)
 def test_use_constant_in_gate(self):
     foo_def = core.GateDefinition("foo", [core.Parameter("p0", None)])
     native_gates = {"foo": foo_def}
     builder = core.circuitbuilder.CircuitBuilder(native_gates=native_gates)
     const = builder.let("x", 1)
     builder.gate("foo", const)
     self.run_test(
         ("circuit", ("let", "x", 1), ("gate", "foo", "x")),
         builder,
         native_gates=native_gates,
     )
 def test_use_qubit_in_gate(self):
     foo_def = core.GateDefinition("foo", [core.Parameter("p0", ParamType.QUBIT)])
     native_gates = {"foo": foo_def}
     builder = core.circuitbuilder.CircuitBuilder(native_gates=native_gates)
     reg = builder.register("r", 3)
     builder.gate("foo", reg[0])
     self.run_test(
         ("circuit", ("register", "r", 3), ("gate", "foo", ("array_item", "r", 0))),
         builder,
         native_gates=native_gates,
     )
 def test_add_macro_to_circuit(self):
     foo_def = core.GateDefinition("foo", parameters=[Parameter("x", None)])
     native_gates = {"foo": foo_def}
     block = core.circuitbuilder.SequentialBlockBuilder()
     block.gate("foo", "a")
     builder = core.circuitbuilder.CircuitBuilder(native_gates=native_gates)
     builder.macro("my_macro", ["a"], body=block)
     self.run_test(
         (
             "circuit",
             ("macro", "my_macro", "a", ("sequential_block", ("gate", "foo", "a"))),
         ),
         builder,
         native_gates=native_gates,
     )
Beispiel #5
0
    def test_macro(self):
        # I started making this a randomized test but things quickly got out of hand.

        # Define a macro that has a statement that uses a fixed qubit and another statement that uses
        # a qubit given as an argument.
        reg = core.Register("r", 3)
        param = core.Parameter("a", core.ParamType.QUBIT)
        gate_def = core.GateDefinition("g", [core.Parameter("p", core.ParamType.QUBIT)])
        g0 = gate_def(reg[0])
        g1 = gate_def(param)
        macro_body = core.BlockStatement(statements=(g0, g1))
        macro = core.Macro("foo", [param], macro_body)
        foo = macro(reg[2])
        exp_qubits = {"r": {0, 2}}
        act_qubits = get_used_qubit_indices(foo)
        self.assertEqual(exp_qubits, act_qubits)
 def test_use_macro_gate(self):
     g_def = core.GateDefinition("g", [Parameter("p0", None)])
     native_gates = {"g": g_def}
     builder = core.circuitbuilder.CircuitBuilder(native_gates=native_gates)
     block = core.circuitbuilder.SequentialBlockBuilder()
     block.gate("g", "a")
     builder.macro("foo", ["a"], block)
     builder.gate("foo", 1)
     self.run_test(
         (
             "circuit",
             ("macro", "foo", "a", ("sequential_block", ("gate", "g", "a"))),
             ("gate", "foo", 1),
         ),
         builder,
         native_gates=native_gates,
     )