def setUp(self) -> None: super().setUp() style = stylesheet.QiskitPulseStyle() self.formatter = style.formatter self.device = device_info.OpenPulseBackendInfo( name='test', dt=1, channel_frequency_map={ pulse.DriveChannel(0): 5.0e9, pulse.DriveChannel(1): 5.1e9, pulse.MeasureChannel(0): 7.0e9, pulse.MeasureChannel(1): 7.1e9, pulse.ControlChannel(0): 5.0e9, pulse.ControlChannel(1): 5.1e9 }, qubit_channel_map={ 0: [ pulse.DriveChannel(0), pulse.MeasureChannel(0), pulse.AcquireChannel(0), pulse.ControlChannel(0) ], 1: [ pulse.DriveChannel(1), pulse.MeasureChannel(1), pulse.AcquireChannel(1), pulse.ControlChannel(1) ] })
def test_gen_barrier(self): """Test gen_barrier.""" inst_data = types.BarrierInstruction( 5, 0.1, [pulse.DriveChannel(0), pulse.ControlChannel(0)]) obj = barrier.gen_barrier(inst_data, formatter=self.formatter, device=self.device)[0] # type check self.assertEqual(type(obj), drawings.LineData) # data check self.assertListEqual(obj.channels, [pulse.DriveChannel(0), pulse.ControlChannel(0)]) ref_x = [5, 5] ref_y = [types.AbstractCoordinate.BOTTOM, types.AbstractCoordinate.TOP] self.assertListEqual(list(obj.xvals), ref_x) self.assertListEqual(list(obj.yvals), ref_y) # style check ref_style = { 'alpha': self.formatter['alpha.barrier'], 'zorder': self.formatter['layer.barrier'], 'linewidth': self.formatter['line_width.barrier'], 'linestyle': self.formatter['line_style.barrier'], 'color': self.formatter['color.barrier'] } self.assertDictEqual(obj.styles, ref_style)
def test_delay_qubits(self): """Test delaying on multiple qubits to make sure we don't insert delays twice.""" with pulse.build(self.backend) as schedule: pulse.delay_qubits(10, 0, 1) d0 = pulse.DriveChannel(0) d1 = pulse.DriveChannel(1) m0 = pulse.MeasureChannel(0) m1 = pulse.MeasureChannel(1) a0 = pulse.AcquireChannel(0) a1 = pulse.AcquireChannel(1) u0 = pulse.ControlChannel(0) u1 = pulse.ControlChannel(1) reference = pulse.Schedule() reference += instructions.Delay(10, d0) reference += instructions.Delay(10, d1) reference += instructions.Delay(10, m0) reference += instructions.Delay(10, m1) reference += instructions.Delay(10, a0) reference += instructions.Delay(10, a1) reference += instructions.Delay(10, u0) reference += instructions.Delay(10, u1) self.assertEqual(schedule, reference)
def test_channel_index_sort_grouped_control(self): """Test channel_index_grouped_sort_u.""" out_layout = layouts.channel_index_grouped_sort_u( self.channels, formatter=self.formatter, device=self.device) ref_channels = [ [pulse.DriveChannel(0)], [pulse.DriveChannel(1)], [pulse.MeasureChannel(1)], [pulse.AcquireChannel(1)], [pulse.DriveChannel(2)], [pulse.MeasureChannel(2)], [pulse.AcquireChannel(2)], [pulse.ControlChannel(0)], [pulse.ControlChannel(2)], [pulse.ControlChannel(5)], ] ref_names = [ "D0", "D1", "M1", "A1", "D2", "M2", "A2", "U0", "U2", "U5" ] ref = list(zip(ref_names, ref_channels)) self.assertListEqual(list(out_layout), ref)
def test_cx_cz_case(self): """Test the case where the coupling map has CX and CZ on different qubits. We use FakeBelem which has a linear coupling map and will restrict ourselves to qubits 0, 1, and 2. The Cals will define a template schedule for CX and CZ. We will mock this with GaussianSquare and Gaussian pulses since the nature of the schedules is irrelevant here. The parameters for CX will only have values for qubis 0 and 1 while the parameters for CZ will only have values for qubis 1 and 2. We therefore will have a CX on qubits 0, 1 in the inst. map and a CZ on qubits 1, 2. """ cals = BackendCalibrations(FakeBelem()) sig = Parameter("σ") dur = Parameter("duration") width = Parameter("width") amp_cx = Parameter("amp") amp_cz = Parameter("amp") uchan = Parameter("ch1.0") with pulse.build(name="cx") as cx: pulse.play( pulse.GaussianSquare(duration=dur, amp=amp_cx, sigma=sig, width=width), pulse.ControlChannel(uchan), ) with pulse.build(name="cz") as cz: pulse.play( pulse.Gaussian(duration=dur, amp=amp_cz, sigma=sig), pulse.ControlChannel(uchan) ) cals.add_schedule(cx, num_qubits=2) cals.add_schedule(cz, num_qubits=2) cals.add_parameter_value(640, "duration", schedule="cx") cals.add_parameter_value(64, "σ", schedule="cx") cals.add_parameter_value(320, "width", qubits=(0, 1), schedule="cx") cals.add_parameter_value(320, "width", qubits=(1, 0), schedule="cx") cals.add_parameter_value(0.1, "amp", qubits=(0, 1), schedule="cx") cals.add_parameter_value(0.8, "amp", qubits=(1, 0), schedule="cx") cals.add_parameter_value(0.1, "amp", qubits=(2, 1), schedule="cz") cals.add_parameter_value(0.8, "amp", qubits=(1, 2), schedule="cz") # CX only defined for qubits (0, 1) and (1,0)? self.assertTrue(cals.default_inst_map.has("cx", (0, 1))) self.assertTrue(cals.default_inst_map.has("cx", (1, 0))) self.assertFalse(cals.default_inst_map.has("cx", (2, 1))) self.assertFalse(cals.default_inst_map.has("cx", (1, 2))) # CZ only defined for qubits (2, 1) and (1,2)? self.assertTrue(cals.default_inst_map.has("cz", (2, 1))) self.assertTrue(cals.default_inst_map.has("cz", (1, 2))) self.assertFalse(cals.default_inst_map.has("cz", (0, 1))) self.assertFalse(cals.default_inst_map.has("cz", (1, 0)))
def test_qubit_channels(self): """Test getting the qubit channels of the active builder's backend.""" with pulse.build(self.backend): qubit_channels = pulse.qubit_channels(0) self.assertEqual(qubit_channels, {pulse.DriveChannel(0), pulse.MeasureChannel(0), pulse.AcquireChannel(0), pulse.ControlChannel(0), pulse.ControlChannel(1)})
def test_gen_iqx_latex_waveform_name_cr(self): """Test gen_iqx_latex_waveform_name with CR waveform.""" iqx_pulse = pulse.Waveform(samples=[0, 0, 0, 0], name='CR90p_u0_1234567') play = pulse.Play(iqx_pulse, pulse.ControlChannel(0)) inst_data = self.create_instruction(play, 0, 0, 0, 0.1) obj = generators.gen_iqx_latex_waveform_name(inst_data)[0] # type check self.assertEqual(type(obj), drawing_objects.TextData) # data check self.assertEqual(obj.channel, pulse.ControlChannel(0)) self.assertEqual(obj.text, 'CR90p_u0_1234567') self.assertEqual(obj.latex, r'{\rm CR}(\frac{\pi}{4})')
def test_barrier_on_qubits(self): """Test barrier directive on qubits.""" with pulse.build(self.backend) as schedule: pulse.barrier(0, 1) reference = pulse.Schedule() reference += directives.RelativeBarrier(pulse.DriveChannel(0), pulse.DriveChannel(1), pulse.MeasureChannel(0), pulse.MeasureChannel(1), pulse.ControlChannel(0), pulse.ControlChannel(1), pulse.AcquireChannel(0), pulse.AcquireChannel(1)) self.assertEqual(schedule, reference)
def test_instruction_schedule_map_export(self): """Test that exporting the inst map works as planned.""" backend = FakeBelem() cals = BackendCalibrations( backend, library=FixedFrequencyTransmon(basis_gates=["sx"]), ) u_chan = pulse.ControlChannel(Parameter("ch0.1")) with pulse.build(name="cr") as cr: pulse.play(pulse.GaussianSquare(640, 0.5, 64, 384), u_chan) cals.add_schedule(cr, num_qubits=2) cals.update_inst_map({"cr"}) for qubit in range(backend.configuration().num_qubits): self.assertTrue(cals.default_inst_map.has("sx", (qubit,))) # based on coupling map of Belem to keep the test robust. expected_pairs = [(0, 1), (1, 0), (1, 2), (2, 1), (1, 3), (3, 1), (3, 4), (4, 3)] coupling_map = set(tuple(pair) for pair in backend.configuration().coupling_map) for pair in expected_pairs: self.assertTrue(pair in coupling_map) self.assertTrue(cals.default_inst_map.has("cr", pair), pair)
def test_gen_barrier(self): """Test gen_barrier.""" barrier = pulse.instructions.RelativeBarrier(pulse.DriveChannel(0), pulse.ControlChannel(0)) inst_data = types.NonPulseTuple(5, 0.1, barrier) lines = generators.gen_barrier(inst_data) self.assertEqual(len(lines), 2) # type check self.assertEqual(type(lines[0]), drawing_objects.LineData) self.assertEqual(type(lines[1]), drawing_objects.LineData) # data check self.assertEqual(lines[0].channel, pulse.channels.DriveChannel(0)) self.assertEqual(lines[1].channel, pulse.channels.ControlChannel(0)) self.assertEqual(lines[0].x, 5) self.assertEqual(lines[0].y, None) # style check ref_style = { 'alpha': self.style['formatter.alpha.barrier'], 'zorder': self.style['formatter.layer.barrier'], 'linewidth': self.style['formatter.line_width.barrier'], 'linestyle': self.style['formatter.line_style.barrier'], 'color': self.style['formatter.color.barrier'] } self.assertDictEqual(lines[0].styles, ref_style)
def test_channel_type_grouped_sort(self): """Test channel_type_grouped_sort.""" out_layout = layouts.channel_type_grouped_sort( self.channels, formatter=self.formatter, device=self.device) ref_channels = [[pulse.DriveChannel(0)], [pulse.DriveChannel(1)], [pulse.DriveChannel(2)], [pulse.ControlChannel(0)], [pulse.ControlChannel(2)], [pulse.ControlChannel(5)], [pulse.MeasureChannel(1)], [pulse.MeasureChannel(2)], [pulse.AcquireChannel(1)], [pulse.AcquireChannel(2)]] ref_names = [ 'D0', 'D1', 'D2', 'U0', 'U2', 'U5', 'M1', 'M2', 'A1', 'A2' ] ref = list(zip(ref_names, ref_channels)) self.assertListEqual(list(out_layout), ref)
def test_channel_qubit_index_sort(self): """Test qubit_index_sort.""" out_layout = layouts.qubit_index_sort(self.channels, formatter=self.formatter, device=self.device) ref_channels = [[pulse.DriveChannel(0), pulse.ControlChannel(0)], [pulse.DriveChannel(1), pulse.MeasureChannel(1)], [pulse.DriveChannel(2), pulse.MeasureChannel(2), pulse.ControlChannel(2)], [pulse.ControlChannel(5)]] ref_names = [ 'Q0', 'Q1', 'Q2', 'Q3' ] ref = list(zip(ref_names, ref_channels)) self.assertListEqual(list(out_layout), ref)
def test_gen_iqx_latex_waveform_name_cr(self): """Test gen_iqx_latex_waveform_name with CR waveform.""" iqx_pulse = pulse.Waveform(samples=[0, 0, 0, 0], name='CR90p_u0_1234567') play = pulse.Play(iqx_pulse, pulse.ControlChannel(0)) inst_data = create_instruction(play, 0, 0, 0, 0.1) obj = waveform.gen_ibmq_latex_waveform_name(inst_data, formatter=self.formatter, device=self.device)[0] # type check self.assertEqual(type(obj), drawings.TextData) # data check self.assertListEqual(obj.channels, [pulse.ControlChannel(0)]) self.assertEqual(obj.text, 'CR90p_u0_1234567') self.assertEqual(obj.latex, r'{\rm CR}(\pi/4)')
def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: pulse.delay_qubits(10, 0) d0 = pulse.DriveChannel(0) m0 = pulse.MeasureChannel(0) a0 = pulse.AcquireChannel(0) u0 = pulse.ControlChannel(0) u1 = pulse.ControlChannel(1) reference = pulse.Schedule() reference += instructions.Delay(10, d0) reference += instructions.Delay(10, m0) reference += instructions.Delay(10, a0) reference += instructions.Delay(10, u0) reference += instructions.Delay(10, u1) self.assertEqual(schedule, reference)
def setUp(self) -> None: super().setUp() self.style = stylesheet.QiskitPulseStyle() self.device = device_info.OpenPulseBackendInfo( name="test", dt=1, channel_frequency_map={ pulse.DriveChannel(0): 5.0, pulse.MeasureChannel(0): 7.0, pulse.ControlChannel(0): 5.0, }, qubit_channel_map={ 0: [ pulse.DriveChannel(0), pulse.MeasureChannel(0), pulse.AcquireChannel(0), pulse.ControlChannel(0), ] }, ) # objects self.short_pulse = drawings.LineData( data_type=types.WaveformType.REAL, xvals=[0, 0, 1, 4, 5, 5], yvals=[0, 0.5, 0.5, 0.5, 0.5, 0], channels=[pulse.DriveChannel(0)], ) self.long_pulse = drawings.LineData( data_type=types.WaveformType.REAL, xvals=[8, 8, 9, 19, 20, 20], yvals=[0, 0.3, 0.3, 0.3, 0.3, 0], channels=[pulse.DriveChannel(1)], ) self.abstract_hline = drawings.LineData( data_type=types.LineType.BASELINE, xvals=[ types.AbstractCoordinate.LEFT, types.AbstractCoordinate.RIGHT ], yvals=[0, 0], channels=[pulse.DriveChannel(0)], )
def test_used_in_calls(self): """Test that we can identify schedules by name when calls are present.""" with pulse.build(name="xp") as xp: pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(1)) with pulse.build(name="xp2") as xp2: pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(1)) with pulse.build(name="call_xp") as xp_call: pulse.call(xp) with pulse.build(name="call_call_xp") as xp_call_call: pulse.play(pulse.Drag(160, 0.5, 40, 0.2), pulse.DriveChannel(1)) pulse.call(xp_call) self.assertSetEqual(used_in_calls("xp", [xp_call]), {"call_xp"}) self.assertSetEqual(used_in_calls("xp", [xp2]), set()) self.assertSetEqual(used_in_calls("xp", [xp_call, xp_call_call]), {"call_xp", "call_call_xp"}) with pulse.build(name="xp") as xp: pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(2)) cr_tone_p = pulse.GaussianSquare(640, 0.2, 64, 500) rotary_p = pulse.GaussianSquare(640, 0.1, 64, 500) cr_tone_m = pulse.GaussianSquare(640, -0.2, 64, 500) rotary_m = pulse.GaussianSquare(640, -0.1, 64, 500) with pulse.build(name="cr") as cr: with pulse.align_sequential(): with pulse.align_left(): pulse.play(rotary_p, pulse.DriveChannel(3)) # Rotary tone pulse.play(cr_tone_p, pulse.ControlChannel(2)) # CR tone. pulse.call(xp) with pulse.align_left(): pulse.play(rotary_m, pulse.DriveChannel(3)) pulse.play(cr_tone_m, pulse.ControlChannel(2)) pulse.call(xp) self.assertSetEqual(used_in_calls("xp", [cr]), {"cr"})
def setUp(self) -> None: super().setUp() self.style = stylesheet.QiskitPulseStyle() self.device = device_info.OpenPulseBackendInfo( name="test", dt=1, channel_frequency_map={ pulse.DriveChannel(0): 5.0, pulse.MeasureChannel(0): 7.0, pulse.ControlChannel(0): 5.0, }, qubit_channel_map={ 0: [ pulse.DriveChannel(0), pulse.MeasureChannel(0), pulse.AcquireChannel(0), pulse.ControlChannel(0), ] }, ) self.sched = pulse.Schedule() self.sched.insert( 0, pulse.Play(pulse.Waveform([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]), pulse.DriveChannel(0)), inplace=True, ) self.sched.insert( 10, pulse.Play(pulse.Waveform([0.5, 0.4, 0.3, 0.2, 0.1, 0.0]), pulse.DriveChannel(0)), inplace=True, ) self.sched.insert( 0, pulse.Play(pulse.Waveform([0.3, 0.3, 0.3, 0.3, 0.3, 0.3]), pulse.DriveChannel(1)), inplace=True, )
def create_from_backend(cls, backend: BaseBackend): """Initialize a class with backend information provided by provider. Args: backend: Backend object. Returns: OpenPulseBackendInfo: New configured instance. """ configuration = backend.configuration() defaults = backend.defaults() # load name name = backend.name() # load cycle time dt = configuration.dt # load frequencies chan_freqs = dict() chan_freqs.update({ pulse.DriveChannel(qind): freq for qind, freq in enumerate(defaults.qubit_freq_est) }) chan_freqs.update({ pulse.MeasureChannel(qind): freq for qind, freq in enumerate(defaults.meas_freq_est) }) for qind, u_lo_mappers in enumerate(configuration.u_channel_lo): temp_val = .0 + .0j for u_lo_mapper in u_lo_mappers: temp_val += defaults.qubit_freq_est[ u_lo_mapper.q] * u_lo_mapper.scale chan_freqs[pulse.ControlChannel(qind)] = temp_val.real # load qubit channel mapping qubit_channel_map = defaultdict(list) for qind in range(configuration.n_qubits): qubit_channel_map[qind].append(configuration.drive(qubit=qind)) qubit_channel_map[qind].append(configuration.measure(qubit=qind)) for tind in range(configuration.n_qubits): try: qubit_channel_map[qind].extend( configuration.control(qubits=(qind, tind))) except BackendConfigurationError: pass return OpenPulseBackendInfo(name=name, dt=dt, channel_frequency_map=chan_freqs, qubit_channel_map=qubit_channel_map)
def _build_cr_schedule(self, flat_top_width: float) -> pulse.ScheduleBlock: """GaussianSquared cross resonance pulse. Args: flat_top_width: Total length of flat top part of the pulse in units of dt. Returns: A schedule definition for the cross resonance pulse to measure. """ opt = self.experiment_options # Compute valid integer duration duration = flat_top_width + 2 * opt.sigma * opt.risefall valid_duration = int(self._granularity * np.floor(duration / self._granularity)) with pulse.build(default_alignment="left", name="cr") as cross_resonance: # add cross resonance tone pulse.play( pulse.GaussianSquare( duration=valid_duration, amp=opt.amp, sigma=opt.sigma, width=flat_top_width, ), pulse.ControlChannel(self._cr_channel), ) # add cancellation tone if not np.isclose(opt.amp_t, 0.0): pulse.play( pulse.GaussianSquare( duration=valid_duration, amp=opt.amp_t, sigma=opt.sigma, width=flat_top_width, ), pulse.DriveChannel(self.physical_qubits[1]), ) else: pulse.delay(valid_duration, pulse.DriveChannel(self.physical_qubits[1])) # place holder for empty drive channels. this is necessary due to known pulse gate bug. pulse.delay(valid_duration, pulse.DriveChannel(self.physical_qubits[0])) return cross_resonance
def channel_finder( channel_string: str ) -> Union[pulse.DriveChannel, pulse.ControlChannel]: """Convert a channel string to a real channel Raises: NotImplementedError: If there is some other channel like a measurement channel, which we have not implemented, we raise NotImplementedError. Returns: (Union[pulse.DriveChannel, pulse.ControlChannel]): The resulting channel. """ channel_type = channel_string[0] qubit = int(channel_string[1:]) if channel_type == 'D': channel = pulse.DriveChannel(qubit) elif channel_type == 'U': channel = pulse.ControlChannel(qubit) else: raise NotImplementedError("Unknown channel type encountered.") return channel
def cr_drive_experiments(drive_idx, target_idx, flip_drive_qubit = False, #cr_drive_amps=np.linspace(0, 0.9, 16), #cr_drive_samples=800, #cr_drive_sigma=4, #pi_drive_samples=128, #pi_drive_sigma=16 #meas_amp = Dims/128*0.025/2 #meas_width = int(rows/128*1150/2) cr_drive_amps=np.linspace(0, 0.9, meas_width**2), cr_drive_samples=sum(label1[:] == label2[:]), cr_drive_sigma=meas_sigma, pi_drive_samples=sum((label1[:] ==1)*(label2[:] ==1)), #label1[:] ==1 and label2[:] ==1 pi_drive_sigma=cr_drive_sigma**2): """Generate schedules corresponding to CR drive experiments. Args: drive_idx (int): label of driven qubit target_idx (int): label of target qubit flip_drive_qubit (bool): whether or not to start the driven qubit in the ground or excited state cr_drive_amps (array): list of drive amplitudes to use cr_drive_samples (int): number samples for each CR drive signal cr_drive_sigma (float): standard deviation of CR Gaussian pulse pi_drive_samples (int): number samples for pi pulse on drive pi_drive_sigma (float): standard deviation of Gaussian pi pulse on drive Returns: list[Schedule]: A list of Schedule objects for each experiment """ # Construct measurement commands to be used for all schedules #meas_amp = 0.025 #meas_samples = 1200 #meas_sigma = 4 #meas_width = 1150 meas_amp = 0.025 meas_sigma = 4 ni = int(np.ceil(cols/meas_sigma)) print(ni) meas_samples = rows*ni meas_width = int(rows*ni*23/24) meas_pulse = GaussianSquare(duration=meas_samples, amp=meas_amp/np.linalg.norm(meas_amp), sigma=meas_sigma, width=meas_width) acq_sched = pulse.Acquire(meas_samples, pulse.AcquireChannel(0), pulse.MemorySlot(0)) acq_sched += pulse.Acquire(meas_samples, pulse.AcquireChannel(1), pulse.MemorySlot(1)) # create measurement schedule measure_sched = (pulse.Play(meas_pulse, pulse.MeasureChannel(0)) | pulse.Play(meas_pulse, pulse.MeasureChannel(1))| acq_sched) # Create schedule schedules = [] for ii, cr_drive_amp in enumerate(cr_drive_amps): # pulse for flipping drive qubit if desired pi_pulse = Gaussian(duration=pi_drive_samples, amp=pi_amps[drive_idx], sigma=pi_drive_sigma) # cr drive pulse cr_width = cr_drive_samples - 2*cr_drive_sigma*4 cr_rabi_pulse = GaussianSquare(duration=cr_drive_samples, amp=cr_drive_amp/np.linalg.norm(cr_drive_amp), sigma=cr_drive_sigma, width=cr_width) # add commands to schedule schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp) #schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp/np.linalg.norm(cr_drive_amp)) # flip drive qubit if desired if flip_drive_qubit: schedule += pulse.Play(pi_pulse, pulse.DriveChannel(drive_idx)) # do cr drive # First, get the ControlChannel index for CR drive from drive to target cr_idx = two_qubit_model.control_channel_index((drive_idx, target_idx)) schedule += pulse.Play(cr_rabi_pulse, pulse.ControlChannel(cr_idx)) << schedule.duration schedule += measure_sched << schedule.duration schedules.append(schedule) return schedules
def test_control_channel(self): """Text context builder control channel.""" with pulse.build(self.backend): self.assertEqual(pulse.control_channels(0, 1)[0], pulse.ControlChannel(0))
def test_circuit_generation_from_sec(self): """Test generated circuits when time unit is sec.""" backend = CrossResonanceHamiltonianBackend() expr = cr_hamiltonian.CrossResonanceHamiltonian( qubits=(0, 1), flat_top_widths=[500], unit="ns", amp=0.1, sigma=20, risefall=2, ) nearlest_16 = 576 with pulse.build(default_alignment="left", name="cr") as ref_cr_sched: pulse.play( pulse.GaussianSquare( nearlest_16, amp=0.1, sigma=20, width=500, ), pulse.ControlChannel(0), ) pulse.delay(nearlest_16, pulse.DriveChannel(0)) pulse.delay(nearlest_16, pulse.DriveChannel(1)) cr_gate = circuit.Gate("cr_gate", num_qubits=2, params=[500]) expr_circs = expr.circuits(backend) x0_circ = QuantumCircuit(2, 1) x0_circ.append(cr_gate, [0, 1]) x0_circ.h(1) x0_circ.measure(1, 0) x1_circ = QuantumCircuit(2, 1) x1_circ.x(0) x1_circ.append(cr_gate, [0, 1]) x1_circ.h(1) x1_circ.measure(1, 0) y0_circ = QuantumCircuit(2, 1) y0_circ.append(cr_gate, [0, 1]) y0_circ.sdg(1) y0_circ.h(1) y0_circ.measure(1, 0) y1_circ = QuantumCircuit(2, 1) y1_circ.x(0) y1_circ.append(cr_gate, [0, 1]) y1_circ.sdg(1) y1_circ.h(1) y1_circ.measure(1, 0) z0_circ = QuantumCircuit(2, 1) z0_circ.append(cr_gate, [0, 1]) z0_circ.measure(1, 0) z1_circ = QuantumCircuit(2, 1) z1_circ.x(0) z1_circ.append(cr_gate, [0, 1]) z1_circ.measure(1, 0) ref_circs = [x0_circ, y0_circ, z0_circ, x1_circ, y1_circ, z1_circ] for c in ref_circs: c.add_calibration(cr_gate, (0, 1), ref_cr_sched) self.assertListEqual(expr_circs, ref_circs)
def __init__( self, t_off: float = 0.0, ix: float = 0.0, iy: float = 0.0, iz: float = 0.0, zx: float = 0.0, zy: float = 0.0, zz: float = 0.0, b: float = 0.0, ): """Initialize fake backend. Args: t_off: Offset of gate duration. ix: IX term coefficient. iy: IY term coefficient. iz: IZ term coefficient. zx: ZX term coefficient. zy: ZY term coefficient. zz: ZZ term coefficient. b: Offset term. """ self.fit_func_args = { "t_off": t_off, "px0": 2 * np.pi * (ix + zx), "px1": 2 * np.pi * (ix - zx), "py0": 2 * np.pi * (iy + zy), "py1": 2 * np.pi * (iy - zy), "pz0": 2 * np.pi * (iz + zz), "pz1": 2 * np.pi * (iz - zz), "b": b, } configuration = PulseBackendConfiguration( backend_name="fake_cr_hamiltonian", backend_version="0.1.0", n_qubits=2, basis_gates=["sx", "rz", "x", "cx"], gates=None, local=True, simulator=True, conditional=False, open_pulse=True, memory=True, max_shots=10000, coupling_map=[[0, 1], [1, 0]], n_uchannels=2, u_channel_lo=[], meas_levels=[2], qubit_lo_range=[], meas_lo_range=[], dt=1, dtm=1, rep_times=[], meas_kernels=[], discriminators=[], channels={ "d0": { "operates": { "qubits": [0] }, "purpose": "drive", "type": "drive" }, "d1": { "operates": { "qubits": [1] }, "purpose": "drive", "type": "drive" }, "u0": { "operates": { "qubits": [0, 1] }, "purpose": "cross-resonance", "type": "control", }, "u1": { "operates": { "qubits": [0, 1] }, "purpose": "cross-resonance", "type": "control", }, }, timing_constraints={ "granularity": 16, "min_length": 64 }, ) super().__init__(configuration) setattr( self._configuration, "_control_channels", { (0, 1): [pulse.ControlChannel(0)], (1, 0): [pulse.ControlChannel(1)], }, )
def test_circuit_generation(self): """Test generated circuits.""" backend = FakeBogota() # Add granularity to check duration optimization logic setattr( backend.configuration(), "timing_constraints", {"granularity": 16}, ) expr = cr_hamiltonian.CrossResonanceHamiltonian( qubits=(0, 1), flat_top_widths=[1000], amp=0.1, sigma=64, risefall=2, ) expr.backend = backend nearlest_16 = 1248 with pulse.build(default_alignment="left", name="cr") as ref_cr_sched: pulse.play( pulse.GaussianSquare( nearlest_16, amp=0.1, sigma=64, width=1000, ), pulse.ControlChannel(0), ) pulse.delay(nearlest_16, pulse.DriveChannel(0)) pulse.delay(nearlest_16, pulse.DriveChannel(1)) cr_gate = cr_hamiltonian.CrossResonanceHamiltonian.CRPulseGate( width=1000) expr_circs = expr.circuits() x0_circ = QuantumCircuit(2, 1) x0_circ.append(cr_gate, [0, 1]) x0_circ.h(1) x0_circ.measure(1, 0) x1_circ = QuantumCircuit(2, 1) x1_circ.x(0) x1_circ.append(cr_gate, [0, 1]) x1_circ.h(1) x1_circ.measure(1, 0) y0_circ = QuantumCircuit(2, 1) y0_circ.append(cr_gate, [0, 1]) y0_circ.sdg(1) y0_circ.h(1) y0_circ.measure(1, 0) y1_circ = QuantumCircuit(2, 1) y1_circ.x(0) y1_circ.append(cr_gate, [0, 1]) y1_circ.sdg(1) y1_circ.h(1) y1_circ.measure(1, 0) z0_circ = QuantumCircuit(2, 1) z0_circ.append(cr_gate, [0, 1]) z0_circ.measure(1, 0) z1_circ = QuantumCircuit(2, 1) z1_circ.x(0) z1_circ.append(cr_gate, [0, 1]) z1_circ.measure(1, 0) ref_circs = [x0_circ, y0_circ, z0_circ, x1_circ, y1_circ, z1_circ] for c in ref_circs: c.add_calibration(cr_gate, (0, 1), ref_cr_sched) self.assertListEqual(expr_circs, ref_circs)
def setUp(self) -> None: super().setUp() self.channels = [ pulse.DriveChannel(0), pulse.DriveChannel(1), pulse.DriveChannel(2), pulse.MeasureChannel(1), pulse.MeasureChannel(2), pulse.AcquireChannel(1), pulse.AcquireChannel(2), pulse.ControlChannel(0), pulse.ControlChannel(2), pulse.ControlChannel(5) ] self.formatter = {'control.show_acquire_channel': True} self.device = device_info.OpenPulseBackendInfo( name='test', dt=1, channel_frequency_map={ pulse.DriveChannel(0): 5.0e9, pulse.DriveChannel(1): 5.1e9, pulse.DriveChannel(2): 5.2e9, pulse.MeasureChannel(1): 7.0e9, pulse.MeasureChannel(1): 7.1e9, pulse.MeasureChannel(2): 7.2e9, pulse.ControlChannel(0): 5.0e9, pulse.ControlChannel(1): 5.1e9, pulse.ControlChannel(2): 5.2e9, pulse.ControlChannel(3): 5.3e9, pulse.ControlChannel(4): 5.4e9, pulse.ControlChannel(5): 5.5e9 }, qubit_channel_map={ 0: [ pulse.DriveChannel(0), pulse.MeasureChannel(0), pulse.AcquireChannel(0), pulse.ControlChannel(0) ], 1: [ pulse.DriveChannel(1), pulse.MeasureChannel(1), pulse.AcquireChannel(1), pulse.ControlChannel(1) ], 2: [ pulse.DriveChannel(2), pulse.MeasureChannel(2), pulse.AcquireChannel(2), pulse.ControlChannel(2), pulse.ControlChannel(3), pulse.ControlChannel(4) ], 3: [ pulse.DriveChannel(3), pulse.MeasureChannel(3), pulse.AcquireChannel(3), pulse.ControlChannel(5) ] })