Skip to content

Commit

Permalink
Deprecate BackendProperties support in NoiseModel.from_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
itoko committed Dec 8, 2021
1 parent e959be8 commit 2e50162
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 118 deletions.
22 changes: 15 additions & 7 deletions qiskit/providers/aer/noise/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def from_backend(cls, backend,
If non-default values are used gate_lengths should be a list
Args:
backend (Backend or BackendProperties): backend properties.
backend (Backend): backend.
gate_error (bool): Include depolarizing gate errors (Default: True).
readout_error (Bool): Include readout errors in model
(Default: True).
Expand Down Expand Up @@ -306,15 +306,24 @@ def from_backend(cls, backend,
if isinstance(backend, (BaseBackend, Backend)):
properties = backend.properties()
basis_gates = backend.configuration().basis_gates
num_qubits = backend.configuration().num_qubits
dt = backend.configuration().dt
if not properties:
raise NoiseError('Qiskit backend {} does not have a '
'BackendProperties'.format(backend))
elif isinstance(backend, BackendProperties):
warn(
'Accepting BackendProperties object for "backend" option'
' has been deprecated as of qiskit-aer 0.10.0 and'
' will be removed no earlier than 3 months from that release date.',
DeprecationWarning, stacklevel=2)
properties = backend
basis_gates = set()
for prop in properties.gates:
basis_gates.add(prop.gate)
basis_gates = list(basis_gates)
num_qubits = len(properties.qubits)
dt = 1 # dummy value (may cause unrealistic noises)
else:
raise NoiseError('{} is not a Qiskit backend or'
' BackendProperties'.format(backend))
Expand Down Expand Up @@ -350,17 +359,16 @@ def from_backend(cls, backend,
noise_model.add_quantum_error(error, name, qubits, warnings=warnings)
# Add delay errors
if thermal_relaxation:
qubits = list(range(backend.configuration().num_qubits))
delay_pass = RelaxationNoisePass(
t1s=[backend.properties().t1(q) for q in qubits],
t2s=[backend.properties().t2(q) for q in qubits],
instruction_durations=InstructionDurations.from_backend(backend),
t1s=[properties.t1(q) for q in range(num_qubits)],
t2s=[properties.t2(q) for q in range(num_qubits)],
instruction_durations=InstructionDurations(dt=dt),
op_types=Delay,
excited_state_populations=[
_excited_population(
freq=backend.properties().frequency(q),
freq=properties.frequency(q),
temperature=temperature
) for q in qubits
) for q in range(num_qubits)
]
)
noise_model._custom_noise_passes.append(delay_pass)
Expand Down
116 changes: 7 additions & 109 deletions test/terra/backends/aer_simulator/test_truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
AerSimulator Integration Tests
"""
from ddt import ddt
import json
from qiskit import transpile, QuantumRegister, ClassicalRegister, QuantumCircuit, Aer
from qiskit.providers.aer import noise
from qiskit import transpile, QuantumCircuit, Aer
from qiskit.providers.aer.noise import NoiseModel
from qiskit.providers.aer.noise.errors import ReadoutError, depolarizing_error
from qiskit.providers.models import BackendProperties
from qiskit.test import mock
from test.terra.backends.simulator_test_case import (
SimulatorTestCase, supported_methods)

Expand Down Expand Up @@ -43,106 +40,8 @@ def create_circuit_for_truncate(self):
circuit.measure(1, 1)
return circuit


def device_properties(self):
properties = {"general": [],
"last_update_date": "2019-04-22T03:26:08+00:00",
"gates": [
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [0]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [0]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [0]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [1]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [1]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [1]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [2]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [2]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [2]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [3]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [3]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [3]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [4]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [4]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [4]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [5]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [5]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [5]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [6]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [6]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [6]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [7]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [7]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [7]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [8]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [8]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [8]},
{"gate": "u1", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [9]},
{"gate": "u2", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [9]},
{"gate": "u3", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-23T01:45:04+00:00", "unit": ""}], "qubits": [9]},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:26:00+00:00", "unit": ""}], "qubits": [0, 1], "name": "CX0_1"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:29:15+00:00", "unit": ""}], "qubits": [1, 2], "name": "CX1_2"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:32:48+00:00", "unit": ""}], "qubits": [2, 3], "name": "CX2_3"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:26:00+00:00", "unit": ""}], "qubits": [3, 4], "name": "CX3_4"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:29:15+00:00", "unit": ""}], "qubits": [4, 5], "name": "CX4_5"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:32:48+00:00", "unit": ""}], "qubits": [5, 6], "name": "CX5_6"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:26:00+00:00", "unit": ""}], "qubits": [6, 7], "name": "CX6_7"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:29:15+00:00", "unit": ""}], "qubits": [7, 8], "name": "CX7_8"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:32:48+00:00", "unit": ""}], "qubits": [8, 9], "name": "CX8_9"},
{"gate": "cx", "parameters": [{"name": "gate_error", "value": 0.001, "date": "2019-04-22T02:26:00+00:00", "unit": ""}], "qubits": [9, 0], "name": "CX9_0"}],
"qubits": [
[
{"name": "T1", "value": 23.809868955712616, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 43.41142418044261, "date": "2019-04-22T01:33:33+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.032871440179164, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.03489999999999993, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 68.14048367144501, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 56.95903203933663, "date": "2019-04-22T01:34:36+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 4.896209948700639, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.19589999999999996, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 83.26776276928099, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 23.49615795695734, "date": "2019-04-22T01:31:32+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.100093544085939, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.09050000000000002, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 57.397746445609975, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 98.47976889309517, "date": "2019-04-22T01:32:32+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.238526396839902, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.24350000000000005, "date": "2019-04-20T15:31:39+00:00", "unit": ""}],
[
{"name": "T1", "value": 23.809868955712616, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 43.41142418044261, "date": "2019-04-22T01:33:33+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.032871440179164, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.03489999999999993, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 68.14048367144501, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 56.95903203933663, "date": "2019-04-22T01:34:36+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 4.896209948700639, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.19589999999999996, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 83.26776276928099, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 23.49615795695734, "date": "2019-04-22T01:31:32+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.100093544085939, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.09050000000000002, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 57.397746445609975, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 98.47976889309517, "date": "2019-04-22T01:32:32+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.238526396839902, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.24350000000000005, "date": "2019-04-20T15:31:39+00:00", "unit": ""}],
[
{"name": "T1", "value": 23.809868955712616, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 43.41142418044261, "date": "2019-04-22T01:33:33+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 5.032871440179164, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.03489999999999993, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
[
{"name": "T1", "value": 68.14048367144501, "date": "2019-04-22T01:30:15+00:00", "unit": "\u00b5s"},
{"name": "T2", "value": 56.95903203933663, "date": "2019-04-22T01:34:36+00:00", "unit": "\u00b5s"},
{"name": "frequency", "value": 4.896209948700639, "date": "2019-04-22T03:26:08+00:00", "unit": "GHz"},
{"name": "readout_error", "value": 0.19589999999999996, "date": "2019-04-22T01:29:47+00:00", "unit": ""}],
],
"backend_name": "mock_4q",
"backend_version": "1.0.0"}
return BackendProperties.from_dict(properties)
def deveice_backend(self):
return mock.FakeQuito()

def test_truncate_ideal_sparse_circuit(self):
"""Test qubit truncation for large circuit with unused qubits."""
Expand All @@ -157,7 +56,6 @@ def test_truncate_ideal_sparse_circuit(self):

result = backend.run(circuit, shots=1).result()
metadata = result.results[0].metadata
metadata = result.results[0].metadata
self.assertEqual(metadata["num_qubits"], 2, msg="wrong number of truncated qubits.")
self.assertEqual(metadata["active_input_qubits"], [10, 20], msg="incorrect truncated qubits.")

Expand All @@ -167,7 +65,7 @@ def test_truncate_default(self):
[0, 1], [1, 2], [2, 3], [3, 4], [4, 5],
[5, 6], [6, 7], [7, 8], [8, 9], [9, 0]
]
noise_model = NoiseModel.from_backend(self.device_properties())
noise_model = NoiseModel.from_backend(self.deveice_backend())
backend = self.backend(noise_model=noise_model)
circuit = transpile(
self.create_circuit_for_truncate(),
Expand All @@ -180,7 +78,7 @@ def test_truncate_default(self):

def test_truncate_non_measured_qubits(self):
"""Test truncation of non-measured uncoupled qubits."""
noise_model = NoiseModel.from_backend(self.device_properties())
noise_model = NoiseModel.from_backend(self.deveice_backend())
backend = self.backend(noise_model=noise_model)
circuit = transpile(
self.create_circuit_for_truncate(),
Expand All @@ -197,7 +95,7 @@ def test_truncate_disable_noise(self):
[0, 1], [1, 2], [2, 3], [3, 4], [4, 5],
[5, 6], [6, 7], [7, 8], [8, 9], [9, 0]
]
noise_model = NoiseModel.from_backend(self.device_properties())
noise_model = NoiseModel.from_backend(self.deveice_backend())
backend = self.backend(noise_model=noise_model, enable_truncation=False)
circuit = transpile(
self.create_circuit_for_truncate(),
Expand Down
4 changes: 2 additions & 2 deletions test/terra/noise/test_noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ def test_noise_model_from_backend_almaden(self):
result = AerSimulator().run(circ, noise_model=noise_model).result()
self.assertTrue(result.success)

def test_noise_model_from_rochester(self):
def test_noise_model_from_mumbai(self):
circ = QuantumCircuit(2)
circ.x(0)
circ.x(1)
circ.measure_all()

backend = mock.FakeRochester()
backend = mock.FakeMumbai()
noise_model = NoiseModel.from_backend(backend)
circ = transpile(circ, backend, optimization_level=0)
result = AerSimulator().run(circ, noise_model=noise_model).result()
Expand Down

0 comments on commit 2e50162

Please sign in to comment.