Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" -c constraints.txt
python setup.py build_ext --inplace
sudo apt install -y graphviz
displayName: 'Install dependencies'
Expand Down Expand Up @@ -190,7 +190,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" -c constraints.txt
python setup.py build_ext --inplace
displayName: 'Install dependencies'
- bash: |
Expand Down Expand Up @@ -244,7 +244,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" -c constraints.txt
python setup.py build_ext --inplace
displayName: 'Install dependencies'
- bash: |
Expand Down Expand Up @@ -303,7 +303,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" -c constraints.txt
python setup.py build_ext --inplace
displayName: 'Install dependencies'
- bash: |
Expand Down Expand Up @@ -357,7 +357,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" -c constraints.txt
python setup.py build_ext --inplace
sudo apt install -y graphviz
displayName: 'Install dependencies'
Expand Down Expand Up @@ -412,7 +412,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" -c constraints.txt
python setup.py build_ext --inplace
displayName: 'Install dependencies'
- bash: |
Expand Down
2 changes: 2 additions & 0 deletions qiskit/qobj/qasm_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ def __init__(self, qobj_id=None, config=None, experiments=None,
self.config = config or QasmQobjConfig()
self.experiments = experiments or []
self.qobj_id = qobj_id
self.type = 'QASM'
self.schema_version = '1.1.0'

def to_dict(self, validate=False):
"""Return a dictionary format representation of the QASM Qobj.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/test/mock/backends/yorktown/props_yorktown.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions qiskit/test/mock/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ def run(self, qobj):
job = sim.run(qobj, system_model)
else:
sim = Aer.get_backend('qasm_simulator')
from qiskit.providers.aer.noise import NoiseModel
noise_model = NoiseModel.from_backend(self)
job = sim.run(qobj, noise_model=noise_model)
if self.properties():
from qiskit.providers.aer.noise import NoiseModel
noise_model = NoiseModel.from_backend(self)
job = sim.run(qobj, noise_model=noise_model)
else:
job = sim.run(qobj)
else:
if qobj.type == 'PULSE':
raise QiskitError("Unable to run pulse schedules without "
Expand Down
6 changes: 3 additions & 3 deletions qiskit/test/mock/fake_openpulse_2q.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ def __init__(self):
gates=[
Gate(gate='u1', name='u1_0', qubits=[0],
parameters=[
Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
Nduv(date=mock_time, name='gate_error', unit='', value=0.06),
Nduv(date=mock_time, name='gate_length', unit='ns', value=0.)]),
Gate(gate='u3', name='u3_0', qubits=[0],
parameters=[
Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
Nduv(date=mock_time, name='gate_error', unit='', value=0.06),
Nduv(date=mock_time, name='gate_length', unit='ns', value=2 * dt)]),
Gate(gate='u3', name='u3_1', qubits=[1],
parameters=[
Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
Nduv(date=mock_time, name='gate_error', unit='', value=0.06),
Nduv(date=mock_time, name='gate_length', unit='ns', value=4 * dt)]),
Gate(gate='cx', name='cx0_1', qubits=[0, 1],
parameters=[
Expand Down
7 changes: 4 additions & 3 deletions qiskit/test/mock/fake_qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def __init__(self):
backend_name='fake_qasm_simulator',
backend_version='0.0.0',
n_qubits=5,
basis_gates=['u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z',
'h', 's', 'sdg', 't', 'tdg', 'ccx', 'swap',
'snapshot', 'unitary'],
basis_gates=['u1', 'u2', 'u3', 'cx', 'id', 'unitary'],
coupling_map=None,
simulator=True,
local=True,
Expand All @@ -42,3 +40,6 @@ def __init__(self):
)

super().__init__(configuration)

def properties(self):
return None
61 changes: 61 additions & 0 deletions test/python/providers/test_fake_backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# pylint: disable=missing-class-docstring,missing-function-docstring
# pylint: disable=missing-module-docstring

import operator

from test import combine
from ddt import ddt

from qiskit.circuit import QuantumCircuit
from qiskit.execute import execute
from qiskit.test.base import QiskitTestCase
from qiskit.test.mock import FakeProvider
from qiskit.test.mock.fake_backend import HAS_AER


FAKE_PROVIDER = FakeProvider()


@ddt
class TestFakeBackends(QiskitTestCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.circuit = QuantumCircuit(2)
cls.circuit.h(0)
cls.circuit.h(1)
cls.circuit.h(0)
cls.circuit.h(1)
cls.circuit.x(0)
cls.circuit.x(1)
cls.circuit.measure_all()

@combine(backend=FAKE_PROVIDER.backends(),
optimization_level=[0, 1, 2, 3])
def test_circuit_on_fake_backend(self, backend, optimization_level):
if not HAS_AER and backend.configuration().n_qubits > 20:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unfortunate that we need to use (and install) Aer for these tests (though I understand why its necessary). Maybe it makes sense to update the BasicAer n_qubits check to be number of used qubits.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't happy with adding aer to the testing. But to do this well it was needed.

The issue with adjusting basicaer to avoid this is that it's looking at the transpiled qobj to determine the number of qubits required: https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/providers/basicaer/qasm_simulator.py#L622. With the fake backends (and specifically in this case for FakeRochester), the physical circuit will have an ancilla with no operations set for all the unused qubits since it's pulling that from the fake backend. To workaround this we'd have to disassemble the qobj and determine that 51 qubits are idle. It's not too much work, but definitely outside the scope of this PR.

self.skipTest(
'Unable to run fake_backend %s without qiskit-aer' %
backend.configuration().backend_name)
job = execute(self.circuit, backend,
optimization_level=optimization_level,
seed_simulator=42, seed_transpiler=42)
result = job.result()
counts = result.get_counts()
max_count = max(counts.items(), key=operator.itemgetter(1))[0]
self.assertEqual(max_count, '11')