This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
forked from qiskit-community/qiskit-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warning for composite experiment run options (qiskit-community#159)
* added warning and test * addressed comments * moved base data processor to its own file * run options * black * lint * changed warning message * fixed message * make warning shorter for lint * broke line in two * combined FakeExperiment * changed options checking * fake experiment name * fixed default options * updated default transpile options * removed import
- Loading branch information
1 parent
68a74bd
commit 057d79c
Showing
10 changed files
with
198 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021. | ||
# | ||
# 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. | ||
|
||
"""Data processing tests.""" | ||
from .base_data_processor_test import BaseDataProcessorTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021. | ||
# | ||
# 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. | ||
|
||
"""Fake backend class for tests.""" | ||
from qiskit.providers.backend import BackendV1 | ||
from qiskit.providers.models import QasmBackendConfiguration | ||
from qiskit.providers.options import Options | ||
|
||
from qiskit.result import Result | ||
|
||
from qiskit_experiments.test.mock_job import MockJob | ||
|
||
|
||
class FakeBackend(BackendV1): | ||
""" | ||
Fake backend for test purposes only. | ||
""" | ||
|
||
def __init__(self): | ||
configuration = QasmBackendConfiguration( | ||
backend_name="dummy_backend", | ||
backend_version="0", | ||
n_qubits=int(1e6), | ||
basis_gates=["barrier", "x", "delay", "measure"], | ||
gates=[], | ||
local=True, | ||
simulator=True, | ||
conditional=False, | ||
open_pulse=False, | ||
memory=False, | ||
max_shots=int(1e6), | ||
coupling_map=None, | ||
) | ||
super().__init__(configuration) | ||
|
||
@classmethod | ||
def _default_options(cls): | ||
return Options() | ||
|
||
def run(self, run_input, **options): | ||
result = { | ||
"backend_name": "Dummmy backend", | ||
"backend_version": "0", | ||
"qobj_id": 0, | ||
"job_id": 0, | ||
"success": True, | ||
"results": [], | ||
} | ||
return MockJob(backend=self, result=Result.from_dict(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021. | ||
# | ||
# 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. | ||
|
||
"""A FakeExperiment for testing.""" | ||
|
||
from qiskit.providers.options import Options | ||
|
||
from qiskit_experiments.base_experiment import BaseExperiment | ||
from qiskit_experiments.base_analysis import BaseAnalysis | ||
|
||
|
||
class FakeAnalysis(BaseAnalysis): | ||
""" | ||
Dummy analysis class for test purposes only. | ||
""" | ||
|
||
def _run_analysis(self, experiment_data, **options): | ||
return [], None | ||
|
||
|
||
class FakeExperiment(BaseExperiment): | ||
"""Fake experiment class for testing.""" | ||
|
||
__analysis_class__ = FakeAnalysis | ||
|
||
@classmethod | ||
def _default_experiment_options(cls) -> Options: | ||
return Options(dummyoption=None) | ||
|
||
def __init__(self, qubit=0): | ||
"""Initialise the fake experiment.""" | ||
self._type = None | ||
super().__init__((qubit,), "fake_test_experiment") | ||
|
||
def circuits(self, backend=None): | ||
"""Fake circuits.""" | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021. | ||
# | ||
# 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. | ||
|
||
"""Class to test composite experiments.""" | ||
|
||
from test.fake_backend import FakeBackend | ||
from test.fake_experiment import FakeExperiment | ||
|
||
from qiskit.test import QiskitTestCase | ||
from qiskit.providers.options import Options | ||
|
||
from qiskit_experiments.composite.parallel_experiment import ParallelExperiment | ||
|
||
|
||
class TestComposite(QiskitTestCase): | ||
""" | ||
Test composite experiment behavior. | ||
""" | ||
|
||
def test_parallel_options(self): | ||
""" | ||
Test parallel experiments overriding sub-experiment run and transpile options. | ||
""" | ||
|
||
# These options will all be overridden | ||
exp0 = FakeExperiment(0) | ||
exp0.set_transpile_options(optimization_level=1) | ||
exp2 = FakeExperiment(2) | ||
exp2.set_experiment_options(dummyoption="test") | ||
exp2.set_run_options(shots=2000) | ||
exp2.set_transpile_options(optimization_level=1) | ||
exp2.set_analysis_options(dummyoption="test") | ||
|
||
par_exp = ParallelExperiment([exp0, exp2]) | ||
|
||
with self.assertWarnsRegex( | ||
Warning, | ||
"Sub-experiment run and transpile options" | ||
" are overridden by composite experiment options.", | ||
): | ||
self.assertEqual(par_exp.experiment_options, Options()) | ||
self.assertEqual(par_exp.run_options, Options(meas_level=2)) | ||
self.assertEqual(par_exp.transpile_options, Options(optimization_level=0)) | ||
self.assertEqual(par_exp.analysis_options, Options()) | ||
|
||
par_exp.run(FakeBackend()) |