Skip to content

Commit

Permalink
Update tests and docs
Browse files Browse the repository at this point in the history
Several tests and docs were relying on the pulse data being present in
the fake backends. This commit updates the tests and docs to avoid this
and either rely on different fake backends that use parametric pulses or
not rely on a fake backend at all. In one case a bug is fixed the
assembler which was causing the tests to incorrectly pass because the
use of pulse backends without parametric pulses was masking incorrect
behavior.
  • Loading branch information
mtreinish committed Sep 12, 2022
1 parent 1d98488 commit 9ac25a9
Show file tree
Hide file tree
Showing 8 changed files with 1,940 additions and 152 deletions.
14 changes: 8 additions & 6 deletions qiskit/compiler/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,15 @@ def _parse_circuit_args(
parameter_binds = parameter_binds or []
# create run configuration and populate
run_config_dict = dict(parameter_binds=parameter_binds, **run_config)
if backend:
run_config_dict["parametric_pulses"] = getattr(
backend.configuration(), "parametric_pulses", []
)
if parametric_pulses:
if parametric_pulses is None:
if backend:
run_config_dict["parametric_pulses"] = getattr(
backend.configuration(), "parametric_pulses", []
)
else:
run_config_dict["parametric_pulses"] = []
else:
run_config_dict["parametric_pulses"] = parametric_pulses

if meas_level:
run_config_dict["meas_level"] = meas_level
# only enable `meas_return` if `meas_level` isn't classified
Expand Down
26 changes: 13 additions & 13 deletions qiskit/visualization/pulse_v2/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,50 +312,50 @@ def draw(
from qiskit import QuantumCircuit, transpile, schedule
from qiskit.visualization.pulse_v2 import draw
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
qc = transpile(qc, FakeAlmaden(), layout_method='trivial')
sched = schedule(qc, FakeAlmaden())
qc = transpile(qc, FakeBoeblingen(), layout_method='trivial')
sched = schedule(qc, FakeBoeblingen())
draw(sched, backend=FakeAlmaden())
draw(sched, backend=FakeBoeblingen())
Drawing with the stylesheet suited for publication.
.. jupyter-execute::
from qiskit import QuantumCircuit, transpile, schedule
from qiskit.visualization.pulse_v2 import draw, IQXSimple
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
qc = transpile(qc, FakeAlmaden(), layout_method='trivial')
sched = schedule(qc, FakeAlmaden())
qc = transpile(qc, FakeBoeblingen(), layout_method='trivial')
sched = schedule(qc, FakeBoeblingen())
draw(sched, style=IQXSimple(), backend=FakeAlmaden())
draw(sched, style=IQXSimple(), backend=FakeBoeblingen())
Drawing with the stylesheet suited for program debugging.
.. jupyter-execute::
from qiskit import QuantumCircuit, transpile, schedule
from qiskit.visualization.pulse_v2 import draw, IQXDebugging
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
qc = transpile(qc, FakeAlmaden(), layout_method='trivial')
sched = schedule(qc, FakeAlmaden())
qc = transpile(qc, FakeBoeblingen(), layout_method='trivial')
sched = schedule(qc, FakeBoeblingen())
draw(sched, style=IQXDebugging(), backend=FakeAlmaden())
draw(sched, style=IQXDebugging(), backend=FakeBoeblingen())
You can partially customize a preset stylesheet when initializing it.
Expand All @@ -368,7 +368,7 @@ def draw(
}
style = IQXStandard(**my_style)
# draw
draw(sched, style=style, backend=FakeAlmaden())
draw(sched, style=style, backend=FakeBoeblingen())
In the same way as above, you can create custom generator or layout functions
and update the existing stylesheet with custom functions.
Expand Down
8 changes: 4 additions & 4 deletions qiskit/visualization/pulse_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def pulse_drawer(
import numpy as np
import qiskit
from qiskit import pulse
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
inst_map = FakeAlmaden().defaults().instruction_schedule_map
inst_map = FakeBoeblingen().defaults().instruction_schedule_map
sched = pulse.Schedule()
sched += inst_map.get('u3', 0, np.pi, 0, np.pi)
Expand All @@ -117,9 +117,9 @@ def pulse_drawer(
import numpy as np
import qiskit
from qiskit import pulse
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
inst_map = FakeAlmaden().defaults().instruction_schedule_map
inst_map = FakeBoeblingen().defaults().instruction_schedule_map
sched = pulse.Schedule()
sched += inst_map.get('u3', 0, np.pi, 0, np.pi)
Expand Down
12 changes: 6 additions & 6 deletions qiskit/visualization/timeline/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ def draw(
from qiskit import QuantumCircuit, transpile, schedule
from qiskit.visualization.timeline import draw
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc = transpile(qc, FakeAlmaden(), scheduling_method='alap', layout_method='trivial')
qc = transpile(qc, FakeBoeblingen(), scheduling_method='alap', layout_method='trivial')
draw(qc)
Drawing with the simple stylesheet.
Expand All @@ -306,13 +306,13 @@ def draw(
from qiskit import QuantumCircuit, transpile, schedule
from qiskit.visualization.timeline import draw, IQXSimple
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc = transpile(qc, FakeAlmaden(), scheduling_method='alap', layout_method='trivial')
qc = transpile(qc, FakeBoeblingen(), scheduling_method='alap', layout_method='trivial')
draw(qc, style=IQXSimple())
Drawing with the stylesheet suited for program debugging.
Expand All @@ -321,13 +321,13 @@ def draw(
from qiskit import QuantumCircuit, transpile, schedule
from qiskit.visualization.timeline import draw, IQXDebugging
from qiskit.providers.fake_provider import FakeAlmaden
from qiskit.providers.fake_provider import FakeBoeblingen
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc = transpile(qc, FakeAlmaden(), scheduling_method='alap', layout_method='trivial')
qc = transpile(qc, FakeBoeblingen(), scheduling_method='alap', layout_method='trivial')
draw(qc, style=IQXDebugging())
You can partially customize a preset stylesheet when call it::
Expand Down
13 changes: 8 additions & 5 deletions test/python/compiler/test_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
FakeOpenPulse2Q,
FakeOpenPulse3Q,
FakeYorktown,
FakeAlmaden,
FakeHanoi,
)


Expand Down Expand Up @@ -1194,7 +1194,8 @@ def test_pulse_name_conflicts(self):

def test_pulse_name_conflicts_in_other_schedule(self):
"""Test two pulses with the same name in different schedule can be resolved."""
backend = FakeAlmaden()
backend = FakeHanoi()
defaults = backend.defaults()

schedules = []
ch_d0 = pulse.DriveChannel(0)
Expand All @@ -1204,7 +1205,9 @@ def test_pulse_name_conflicts_in_other_schedule(self):
sched += measure(qubits=[0], backend=backend) << 100
schedules.append(sched)

qobj = assemble(schedules, backend)
qobj = assemble(
schedules, qubit_lo_freq=defaults.qubit_freq_est, meas_lo_freq=defaults.meas_freq_est
)

# two user pulses and one measurement pulse should be contained
self.assertEqual(len(qobj.config.pulse_library), 3)
Expand Down Expand Up @@ -1330,7 +1333,7 @@ def test_assemble_parametric_unsupported(self):

def test_assemble_parametric_pulse_kwarg_with_backend_setting(self):
"""Test that parametric pulses respect the kwarg over backend"""
backend = FakeAlmaden()
backend = FakeHanoi()

qc = QuantumCircuit(1, 1)
qc.x(0)
Expand All @@ -1345,7 +1348,7 @@ def test_assemble_parametric_pulse_kwarg_with_backend_setting(self):

def test_assemble_parametric_pulse_kwarg_empty_list_with_backend_setting(self):
"""Test that parametric pulses respect the kwarg as empty list over backend"""
backend = FakeAlmaden()
backend = FakeHanoi()

qc = QuantumCircuit(1, 1)
qc.x(0)
Expand Down
27 changes: 16 additions & 11 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
from qiskit.circuit.library import CXGate, U3Gate, U2Gate, U1Gate, RXGate, RYGate, RZGate, UGate
from qiskit.circuit.measure import Measure
from qiskit.test import QiskitTestCase
from qiskit.providers.fake_provider import FakeMelbourne, FakeRueschlikon, FakeAlmaden, FakeMumbaiV2
from qiskit.providers.fake_provider import (
FakeMelbourne,
FakeRueschlikon,
FakeBoeblingen,
FakeMumbaiV2,
)
from qiskit.transpiler import Layout, CouplingMap
from qiskit.transpiler import PassManager
from qiskit.transpiler.target import Target
Expand Down Expand Up @@ -1047,7 +1052,7 @@ def test_transpiled_custom_gates_calibration(self):
circ.add_calibration(custom_180, [0], q0_x180)
circ.add_calibration(custom_90, [1], q1_y90)

backend = FakeAlmaden()
backend = FakeBoeblingen()
transpiled_circuit = transpile(
circ,
backend=backend,
Expand All @@ -1068,7 +1073,7 @@ def test_transpiled_basis_gates_calibrations(self):
# Add calibration
circ.add_calibration("h", [0], q0_x180)

backend = FakeAlmaden()
backend = FakeBoeblingen()
transpiled_circuit = transpile(
circ,
backend=backend,
Expand All @@ -1088,7 +1093,7 @@ def test_transpile_calibrated_custom_gate_on_diff_qubit(self):
# Add calibration
circ.add_calibration(custom_180, [1], q0_x180)

backend = FakeAlmaden()
backend = FakeBoeblingen()
with self.assertRaises(QiskitError):
transpile(circ, backend=backend, layout_method="trivial")

Expand All @@ -1105,7 +1110,7 @@ def test_transpile_calibrated_nonbasis_gate_on_diff_qubit(self):
# Add calibration
circ.add_calibration("h", [1], q0_x180)

backend = FakeAlmaden()
backend = FakeBoeblingen()
transpiled_circuit = transpile(
circ,
backend=backend,
Expand All @@ -1129,7 +1134,7 @@ def test_transpile_subset_of_calibrated_gates(self):
circ.add_calibration(x_180, [0], q0_x180)
circ.add_calibration("h", [1], q0_x180) # 'h' is calibrated on qubit 1

transpiled_circ = transpile(circ, FakeAlmaden(), layout_method="trivial")
transpiled_circ = transpile(circ, FakeBoeblingen(), layout_method="trivial")
self.assertEqual(set(transpiled_circ.count_ops().keys()), {"u2", "mycustom", "h"})

def test_parameterized_calibrations_transpile(self):
Expand All @@ -1146,10 +1151,10 @@ def q0_rxt(tau):

circ.add_calibration("rxt", [0], q0_rxt(tau), [2 * 3.14 * tau])

transpiled_circ = transpile(circ, FakeAlmaden(), layout_method="trivial")
transpiled_circ = transpile(circ, FakeBoeblingen(), layout_method="trivial")
self.assertEqual(set(transpiled_circ.count_ops().keys()), {"rxt"})
circ = circ.assign_parameters({tau: 1})
transpiled_circ = transpile(circ, FakeAlmaden(), layout_method="trivial")
transpiled_circ = transpile(circ, FakeBoeblingen(), layout_method="trivial")
self.assertEqual(set(transpiled_circ.count_ops().keys()), {"rxt"})

def test_inst_durations_from_calibrations(self):
Expand All @@ -1176,7 +1181,7 @@ def test_multiqubit_gates_calibrations(self, opt_level):
custom_gate = Gate("my_custom_gate", 5, [])
circ.append(custom_gate, [0, 1, 2, 3, 4])
circ.measure_all()
backend = FakeAlmaden()
backend = FakeBoeblingen()
with pulse.build(backend, name="custom") as my_schedule:
pulse.play(
pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)
Expand Down Expand Up @@ -1331,9 +1336,9 @@ def test_transpile_optional_registers(self, optimization_level):

qc.measure(qubits, clbits)

out = transpile(qc, FakeAlmaden(), optimization_level=optimization_level)
out = transpile(qc, FakeBoeblingen(), optimization_level=optimization_level)

self.assertEqual(len(out.qubits), FakeAlmaden().configuration().num_qubits)
self.assertEqual(len(out.qubits), FakeBoeblingen().configuration().num_qubits)
self.assertEqual(out.clbits, clbits)

@data(0, 1, 2, 3)
Expand Down
Loading

0 comments on commit 9ac25a9

Please sign in to comment.