def test_append_schedule(self): """Test appending a schedule to the active builder.""" d0 = pulse.DriveChannel(0) reference = pulse.Schedule() reference += instructions.Delay(10, d0) with pulse.build() as schedule: builder.call(reference) self.assertScheduleEqual(schedule, reference)
def test_transpiler_settings(self): """Test the transpiler settings context. Tests that two cx gates are optimized away with higher optimization level. """ twice_cx_qc = circuit.QuantumCircuit(2) twice_cx_qc.cx(0, 1) twice_cx_qc.cx(0, 1) with pulse.build(self.backend) as schedule: with pulse.transpiler_settings(optimization_level=0): builder.call(twice_cx_qc) self.assertNotEqual(len(schedule.instructions), 0) with pulse.build(self.backend) as schedule: with pulse.transpiler_settings(optimization_level=3): builder.call(twice_cx_qc) self.assertEqual(len(schedule.instructions), 0)
def test_call_circuit(self): """Test calling circuit instruction.""" inst_map = self.inst_map reference = inst_map.get("u1", (0,), 0.0) ref_sched = pulse.Schedule() ref_sched += pulse.instructions.Call(reference) u1_qc = circuit.QuantumCircuit(2) u1_qc.append(circuit.library.U1Gate(0.0), [0]) transpiler_settings = {"optimization_level": 0} with pulse.build(self.backend, default_transpiler_settings=transpiler_settings) as schedule: with pulse.align_right(): builder.call(u1_qc) self.assertScheduleEqual(schedule, ref_sched)
def test_scheduler_settings(self): """Test the circuit scheduler settings context.""" inst_map = pulse.InstructionScheduleMap() d0 = pulse.DriveChannel(0) test_x_sched = pulse.Schedule() test_x_sched += instructions.Delay(10, d0) inst_map.add('x', (0, ), test_x_sched) ref_sched = pulse.Schedule() ref_sched += pulse.instructions.Call(test_x_sched) x_qc = circuit.QuantumCircuit(2) x_qc.x(0) with pulse.build(backend=self.backend) as schedule: with pulse.transpiler_settings(basis_gates=['x']): with pulse.circuit_scheduler_settings(inst_map=inst_map): builder.call(x_qc) self.assertEqual(schedule, ref_sched)
def test_call(self): """Test calling schedule instruction.""" d0 = pulse.DriveChannel(0) d1 = pulse.DriveChannel(1) reference = pulse.Schedule() reference = reference.insert(10, instructions.Delay(10, d0)) reference += instructions.Delay(20, d1) ref_sched = pulse.Schedule() ref_sched += pulse.instructions.Call(reference) with pulse.build() as schedule: with pulse.align_right(): builder.call(reference) self.assertEqual(schedule, ref_sched) with pulse.build() as schedule: with pulse.align_right(): pulse.call(reference) self.assertEqual(schedule, ref_sched)