qiskit-aer 0.17.2__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qiskit_aer/VERSION.txt +1 -0
- qiskit_aer/__init__.py +89 -0
- qiskit_aer/aererror.py +30 -0
- qiskit_aer/aerprovider.py +119 -0
- qiskit_aer/backends/__init__.py +20 -0
- qiskit_aer/backends/aer_compiler.py +1085 -0
- qiskit_aer/backends/aer_simulator.py +1025 -0
- qiskit_aer/backends/aerbackend.py +679 -0
- qiskit_aer/backends/backend_utils.py +567 -0
- qiskit_aer/backends/backendconfiguration.py +395 -0
- qiskit_aer/backends/backendproperties.py +590 -0
- qiskit_aer/backends/compatibility.py +287 -0
- qiskit_aer/backends/controller_wrappers.cp314-win_amd64.pyd +0 -0
- qiskit_aer/backends/libopenblas.dll +0 -0
- qiskit_aer/backends/name_mapping.py +306 -0
- qiskit_aer/backends/qasm_simulator.py +925 -0
- qiskit_aer/backends/statevector_simulator.py +330 -0
- qiskit_aer/backends/unitary_simulator.py +316 -0
- qiskit_aer/jobs/__init__.py +35 -0
- qiskit_aer/jobs/aerjob.py +143 -0
- qiskit_aer/jobs/utils.py +66 -0
- qiskit_aer/library/__init__.py +204 -0
- qiskit_aer/library/control_flow_instructions/__init__.py +16 -0
- qiskit_aer/library/control_flow_instructions/jump.py +47 -0
- qiskit_aer/library/control_flow_instructions/mark.py +30 -0
- qiskit_aer/library/control_flow_instructions/store.py +29 -0
- qiskit_aer/library/default_qubits.py +44 -0
- qiskit_aer/library/instructions_table.csv +21 -0
- qiskit_aer/library/save_instructions/__init__.py +44 -0
- qiskit_aer/library/save_instructions/save_amplitudes.py +168 -0
- qiskit_aer/library/save_instructions/save_clifford.py +63 -0
- qiskit_aer/library/save_instructions/save_data.py +129 -0
- qiskit_aer/library/save_instructions/save_density_matrix.py +91 -0
- qiskit_aer/library/save_instructions/save_expectation_value.py +257 -0
- qiskit_aer/library/save_instructions/save_matrix_product_state.py +71 -0
- qiskit_aer/library/save_instructions/save_probabilities.py +156 -0
- qiskit_aer/library/save_instructions/save_stabilizer.py +70 -0
- qiskit_aer/library/save_instructions/save_state.py +79 -0
- qiskit_aer/library/save_instructions/save_statevector.py +120 -0
- qiskit_aer/library/save_instructions/save_superop.py +62 -0
- qiskit_aer/library/save_instructions/save_unitary.py +63 -0
- qiskit_aer/library/set_instructions/__init__.py +19 -0
- qiskit_aer/library/set_instructions/set_density_matrix.py +78 -0
- qiskit_aer/library/set_instructions/set_matrix_product_state.py +83 -0
- qiskit_aer/library/set_instructions/set_stabilizer.py +77 -0
- qiskit_aer/library/set_instructions/set_statevector.py +78 -0
- qiskit_aer/library/set_instructions/set_superop.py +78 -0
- qiskit_aer/library/set_instructions/set_unitary.py +78 -0
- qiskit_aer/noise/__init__.py +265 -0
- qiskit_aer/noise/device/__init__.py +25 -0
- qiskit_aer/noise/device/models.py +397 -0
- qiskit_aer/noise/device/parameters.py +202 -0
- qiskit_aer/noise/errors/__init__.py +30 -0
- qiskit_aer/noise/errors/base_quantum_error.py +119 -0
- qiskit_aer/noise/errors/pauli_error.py +283 -0
- qiskit_aer/noise/errors/pauli_lindblad_error.py +363 -0
- qiskit_aer/noise/errors/quantum_error.py +451 -0
- qiskit_aer/noise/errors/readout_error.py +355 -0
- qiskit_aer/noise/errors/standard_errors.py +498 -0
- qiskit_aer/noise/noise_model.py +1231 -0
- qiskit_aer/noise/noiseerror.py +30 -0
- qiskit_aer/noise/passes/__init__.py +18 -0
- qiskit_aer/noise/passes/local_noise_pass.py +160 -0
- qiskit_aer/noise/passes/relaxation_noise_pass.py +137 -0
- qiskit_aer/primitives/__init__.py +44 -0
- qiskit_aer/primitives/estimator.py +751 -0
- qiskit_aer/primitives/estimator_v2.py +159 -0
- qiskit_aer/primitives/sampler.py +361 -0
- qiskit_aer/primitives/sampler_v2.py +256 -0
- qiskit_aer/quantum_info/__init__.py +32 -0
- qiskit_aer/quantum_info/states/__init__.py +16 -0
- qiskit_aer/quantum_info/states/aer_densitymatrix.py +313 -0
- qiskit_aer/quantum_info/states/aer_state.py +525 -0
- qiskit_aer/quantum_info/states/aer_statevector.py +302 -0
- qiskit_aer/utils/__init__.py +44 -0
- qiskit_aer/utils/noise_model_inserter.py +66 -0
- qiskit_aer/utils/noise_transformation.py +431 -0
- qiskit_aer/version.py +86 -0
- qiskit_aer-0.17.2.dist-info/METADATA +209 -0
- qiskit_aer-0.17.2.dist-info/RECORD +83 -0
- qiskit_aer-0.17.2.dist-info/WHEEL +5 -0
- qiskit_aer-0.17.2.dist-info/licenses/LICENSE.txt +203 -0
- qiskit_aer-0.17.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2019.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
|
|
13
|
+
# pylint: disable=arguments-differ
|
|
14
|
+
|
|
15
|
+
"""This module implements the job class used for AerBackend objects."""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
|
|
19
|
+
from qiskit.providers import JobV1 as Job
|
|
20
|
+
from qiskit.providers import JobStatus, JobError
|
|
21
|
+
from .utils import DEFAULT_EXECUTOR, requires_submit
|
|
22
|
+
|
|
23
|
+
LOGGER = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AerJob(Job):
|
|
27
|
+
"""AerJob class for Aer Simulators."""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
backend,
|
|
32
|
+
job_id,
|
|
33
|
+
fn,
|
|
34
|
+
circuits=None,
|
|
35
|
+
parameter_binds=None,
|
|
36
|
+
run_options=None,
|
|
37
|
+
executor=None,
|
|
38
|
+
):
|
|
39
|
+
"""Initializes the asynchronous job.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
backend(AerBackend): the backend used to run the job.
|
|
43
|
+
job_id(str): a unique id in the context of the backend used to run the job.
|
|
44
|
+
fn(function): a callable function to execute qobj on backend.
|
|
45
|
+
This should usually be a bound :meth:`AerBackend._run()` method,
|
|
46
|
+
with the signature `(qobj: QasmQobj, job_id: str) -> Result`.
|
|
47
|
+
circuits(list of QuantumCircuit): circuits to execute.
|
|
48
|
+
parameter_binds(list): parameters for circuits.
|
|
49
|
+
run_options(dict): run_options to execute.
|
|
50
|
+
executor(ThreadPoolExecutor):
|
|
51
|
+
The executor to be used to submit the job.
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
JobError: if no qobj and no circuits.
|
|
55
|
+
"""
|
|
56
|
+
super().__init__(backend, job_id)
|
|
57
|
+
self._fn = fn
|
|
58
|
+
self._circuits = circuits
|
|
59
|
+
self._parameter_binds = parameter_binds
|
|
60
|
+
self._run_options = run_options
|
|
61
|
+
self._executor = executor or DEFAULT_EXECUTOR
|
|
62
|
+
self._future = None
|
|
63
|
+
|
|
64
|
+
def submit(self):
|
|
65
|
+
"""Submit the job to the backend for execution.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
QobjValidationError: if the JSON serialization of the Qobj passed
|
|
69
|
+
during construction does not validate against the Qobj schema.
|
|
70
|
+
JobError: if trying to re-submit the job.
|
|
71
|
+
"""
|
|
72
|
+
if self._future is not None:
|
|
73
|
+
raise JobError("Aer job has already been submitted.")
|
|
74
|
+
self._future = self._executor.submit(
|
|
75
|
+
self._fn, self._circuits, self._parameter_binds, self._run_options, self._job_id
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
@requires_submit
|
|
79
|
+
def result(self, timeout=None):
|
|
80
|
+
# pylint: disable=arguments-differ
|
|
81
|
+
"""Get job result. The behavior is the same as the underlying
|
|
82
|
+
concurrent Future objects,
|
|
83
|
+
|
|
84
|
+
https://docs.python.org/3/library/concurrent.futures.html#future-objects
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
timeout (float): number of seconds to wait for results.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
qiskit.Result: Result object
|
|
91
|
+
|
|
92
|
+
Raises:
|
|
93
|
+
concurrent.futures.TimeoutError: if timeout occurred.
|
|
94
|
+
concurrent.futures.CancelledError: if job cancelled before completed.
|
|
95
|
+
"""
|
|
96
|
+
return self._future.result(timeout=timeout)
|
|
97
|
+
|
|
98
|
+
@requires_submit
|
|
99
|
+
def cancel(self):
|
|
100
|
+
"""Attempt to cancel the job."""
|
|
101
|
+
return self._future.cancel()
|
|
102
|
+
|
|
103
|
+
@requires_submit
|
|
104
|
+
def status(self):
|
|
105
|
+
"""Gets the status of the job by querying the Python's future
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
JobStatus: The current JobStatus
|
|
109
|
+
|
|
110
|
+
Raises:
|
|
111
|
+
JobError: If the future is in unexpected state
|
|
112
|
+
concurrent.futures.TimeoutError: if timeout occurred.
|
|
113
|
+
"""
|
|
114
|
+
# The order is important here
|
|
115
|
+
if self._future.running():
|
|
116
|
+
_status = JobStatus.RUNNING
|
|
117
|
+
elif self._future.cancelled():
|
|
118
|
+
_status = JobStatus.CANCELLED
|
|
119
|
+
elif self._future.done():
|
|
120
|
+
_status = JobStatus.DONE if self._future.exception() is None else JobStatus.ERROR
|
|
121
|
+
else:
|
|
122
|
+
# Note: There is an undocumented Future state: PENDING, that seems to show up when
|
|
123
|
+
# the job is enqueued, waiting for someone to pick it up. We need to deal with this
|
|
124
|
+
# state but there's no public API for it, so we are assuming that if the job is not
|
|
125
|
+
# in any of the previous states, is PENDING, ergo INITIALIZING for us.
|
|
126
|
+
_status = JobStatus.INITIALIZING
|
|
127
|
+
return _status
|
|
128
|
+
|
|
129
|
+
def backend(self):
|
|
130
|
+
"""Return the instance of the backend used for this job."""
|
|
131
|
+
return self._backend
|
|
132
|
+
|
|
133
|
+
def circuits(self):
|
|
134
|
+
"""Return the list of QuantumCircuit submitted for this job.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
list of QuantumCircuit: the list of QuantumCircuit submitted for this job.
|
|
138
|
+
"""
|
|
139
|
+
return self._circuits
|
|
140
|
+
|
|
141
|
+
def executor(self):
|
|
142
|
+
"""Return the executor for this job"""
|
|
143
|
+
return self._executor
|
qiskit_aer/jobs/utils.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2017, 2019.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
|
|
13
|
+
"""Utility functions for Aer job management."""
|
|
14
|
+
from functools import singledispatch, update_wrapper, wraps
|
|
15
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
16
|
+
|
|
17
|
+
from qiskit.providers import JobError
|
|
18
|
+
|
|
19
|
+
DEFAULT_EXECUTOR = ThreadPoolExecutor(max_workers=1)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def requires_submit(func):
|
|
23
|
+
"""
|
|
24
|
+
Decorator to ensure that a submit has been performed before
|
|
25
|
+
calling the method.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
func (callable): test function to be decorated.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
callable: the decorated function.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
@wraps(func)
|
|
35
|
+
def _wrapper(self, *args, **kwargs):
|
|
36
|
+
if self._future is None:
|
|
37
|
+
raise JobError("Job not submitted yet!. You have to .submit() first!")
|
|
38
|
+
return func(self, *args, **kwargs)
|
|
39
|
+
|
|
40
|
+
return _wrapper
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def methdispatch(func):
|
|
44
|
+
"""
|
|
45
|
+
Returns a wrapper function that selects which registered function
|
|
46
|
+
to call based on the type of args[2]
|
|
47
|
+
"""
|
|
48
|
+
dispatcher = singledispatch(func)
|
|
49
|
+
|
|
50
|
+
def wrapper(*args, **kw):
|
|
51
|
+
return dispatcher.dispatch(args[2].__class__)(*args, **kw)
|
|
52
|
+
|
|
53
|
+
wrapper.register = dispatcher.register
|
|
54
|
+
update_wrapper(wrapper, func)
|
|
55
|
+
return wrapper
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _check_custom_instruction(experiments, optypes=None):
|
|
59
|
+
"""Return True if circuits contain instructions that cant be split"""
|
|
60
|
+
# Check via optype list if available
|
|
61
|
+
if optypes is not None:
|
|
62
|
+
# Optypes store class names as strings
|
|
63
|
+
return any({"SaveData"}.intersection(optype) for optype in optypes)
|
|
64
|
+
|
|
65
|
+
# Otherwise iterate over instruction names
|
|
66
|
+
return any("save_" in inst.name for exp in experiments for inst in exp.instructions)
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""
|
|
13
|
+
=========================================================
|
|
14
|
+
Instruction Library (:mod:`qiskit_aer.library`)
|
|
15
|
+
=========================================================
|
|
16
|
+
|
|
17
|
+
.. currentmodule:: qiskit_aer.library
|
|
18
|
+
|
|
19
|
+
This library contains custom qiskit :class:`~qiskit.QuantumCircuit`
|
|
20
|
+
:class:`~qiskit.circuit.Instruction` subclasses that can be used
|
|
21
|
+
with the Aer circuit simulator backends.
|
|
22
|
+
|
|
23
|
+
Setting a Custom Simulator State
|
|
24
|
+
================================
|
|
25
|
+
|
|
26
|
+
The following instruction classes can be used to set the specific
|
|
27
|
+
simulator methods to a custom state. Note that these instructions
|
|
28
|
+
are only valid when applied to all qubits in a circuit. Applying
|
|
29
|
+
to a subset of qubits will raise an exception during execution.
|
|
30
|
+
|
|
31
|
+
Instruction Classes
|
|
32
|
+
-------------------
|
|
33
|
+
|
|
34
|
+
.. autosummary::
|
|
35
|
+
:toctree: ../stubs/
|
|
36
|
+
|
|
37
|
+
SetStatevector
|
|
38
|
+
SetDensityMatrix
|
|
39
|
+
SetStabilizer
|
|
40
|
+
SetSuperOp
|
|
41
|
+
SetUnitary
|
|
42
|
+
SetMatrixProductState
|
|
43
|
+
|
|
44
|
+
QuantumCircuit Methods
|
|
45
|
+
----------------------
|
|
46
|
+
|
|
47
|
+
The set instructions can also be added to circuits by using the
|
|
48
|
+
following ``QuantumCircuit`` methods which are patched when importing Aer.
|
|
49
|
+
|
|
50
|
+
.. autosummary::
|
|
51
|
+
:toctree: ../stubs/
|
|
52
|
+
|
|
53
|
+
set_statevector
|
|
54
|
+
set_density_matrix
|
|
55
|
+
set_stabilizer
|
|
56
|
+
set_unitary
|
|
57
|
+
set_superop
|
|
58
|
+
set_matrix_product_state
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Saving Simulator Data
|
|
62
|
+
=====================
|
|
63
|
+
|
|
64
|
+
Simulator State Save Instruction Classes
|
|
65
|
+
----------------------------------------
|
|
66
|
+
|
|
67
|
+
The following instructions can be used to save the state of the simulator
|
|
68
|
+
into the returned result object. The :class:`SaveState` instruction will
|
|
69
|
+
automatically select the format based on the simulation method (eg.
|
|
70
|
+
:class:`SaveStatevector` for statevector method, :class:`SaveDensityMatrix`
|
|
71
|
+
for density matrix method etc.).
|
|
72
|
+
|
|
73
|
+
.. autosummary::
|
|
74
|
+
:toctree: ../stubs/
|
|
75
|
+
|
|
76
|
+
SaveState
|
|
77
|
+
SaveStatevector
|
|
78
|
+
SaveStatevectorDict
|
|
79
|
+
SaveDensityMatrix
|
|
80
|
+
SaveMatrixProductState
|
|
81
|
+
SaveClifford
|
|
82
|
+
SaveStabilizer
|
|
83
|
+
SaveSuperOp
|
|
84
|
+
SaveUnitary
|
|
85
|
+
|
|
86
|
+
.. note::
|
|
87
|
+
The :class:`SaveDensityMatrix` instruction can be used to save the
|
|
88
|
+
reduced densit matrix of a subset of qubits for supported simulation
|
|
89
|
+
methods, however all other save state instructions must be applied
|
|
90
|
+
to all qubits in a run circuit.
|
|
91
|
+
|
|
92
|
+
.. note::
|
|
93
|
+
The :class:`~qiskit_aer.StatevectorSimulator` (and
|
|
94
|
+
:class:`~qiskit_aer.UnitarySimulator`) backend automatically
|
|
95
|
+
append every run circuit with the a :func:`SaveStatevector``
|
|
96
|
+
(:func:`SaveUnitary``) instruction using the default label. Hence adding
|
|
97
|
+
any additional save instructions of that type will require specifying a
|
|
98
|
+
custom label for those instructions.
|
|
99
|
+
|
|
100
|
+
Simulator Derived Data Save Instruction Classes
|
|
101
|
+
-----------------------------------------------
|
|
102
|
+
|
|
103
|
+
The following classes can be used to directly save data derived from the
|
|
104
|
+
simulator state to the returned result object. One some are compatible
|
|
105
|
+
with certain simulation methods.
|
|
106
|
+
|
|
107
|
+
For convenience the save instructions can be accessed using
|
|
108
|
+
custom ``QuantumCircuit`` methods
|
|
109
|
+
|
|
110
|
+
.. autosummary::
|
|
111
|
+
:toctree: ../stubs/
|
|
112
|
+
|
|
113
|
+
SaveExpectationValue
|
|
114
|
+
SaveExpectationValueVariance
|
|
115
|
+
SaveProbabilities
|
|
116
|
+
SaveProbabilitiesDict
|
|
117
|
+
SaveAmplitudes
|
|
118
|
+
SaveAmplitudesSquared
|
|
119
|
+
|
|
120
|
+
.. note ::
|
|
121
|
+
When saving pershot data by using the ``pershot=True`` kwarg
|
|
122
|
+
in the above instructions, the resulting list may only contain
|
|
123
|
+
a single value rather than the number of shots. This
|
|
124
|
+
happens when a run circuit supports measurement sampling because
|
|
125
|
+
it is either
|
|
126
|
+
|
|
127
|
+
1. An ideal simulation with all measurements at the end.
|
|
128
|
+
|
|
129
|
+
2. A noisy simulation using the density matrix method with all
|
|
130
|
+
measurements at the end.
|
|
131
|
+
|
|
132
|
+
In both these cases only a single shot is actually simulated and
|
|
133
|
+
measurement samples for all shots are calculated from the final
|
|
134
|
+
state.
|
|
135
|
+
|
|
136
|
+
QuantumCircuit Methods
|
|
137
|
+
----------------------
|
|
138
|
+
|
|
139
|
+
The save instructions can also be added to circuits by using the
|
|
140
|
+
following ``QuantumCircuit`` methods which are patched when importing Aer.
|
|
141
|
+
|
|
142
|
+
.. note ::
|
|
143
|
+
Each save method has a default label for accessing from the
|
|
144
|
+
circuit result data, however duplicate labels in results will result
|
|
145
|
+
in an exception being raised. If you use more than 1 instance of a
|
|
146
|
+
specific save instruction you must set a custom label for the
|
|
147
|
+
additional instructions.
|
|
148
|
+
|
|
149
|
+
.. autosummary::
|
|
150
|
+
:toctree: ../stubs/
|
|
151
|
+
|
|
152
|
+
save_amplitudes
|
|
153
|
+
save_amplitudes_squared
|
|
154
|
+
save_clifford
|
|
155
|
+
save_density_matrix
|
|
156
|
+
save_expectation_value
|
|
157
|
+
save_expectation_value_variance
|
|
158
|
+
save_matrix_product_state
|
|
159
|
+
save_probabilities
|
|
160
|
+
save_probabilities_dict
|
|
161
|
+
save_stabilizer
|
|
162
|
+
save_state
|
|
163
|
+
save_statevector
|
|
164
|
+
save_statevector_dict
|
|
165
|
+
save_superop
|
|
166
|
+
save_unitary
|
|
167
|
+
|
|
168
|
+
Method Compatibility
|
|
169
|
+
====================
|
|
170
|
+
|
|
171
|
+
The following table summarizes which instructions are compatible with
|
|
172
|
+
which simulation methods
|
|
173
|
+
|
|
174
|
+
.. csv-table::
|
|
175
|
+
:file: instructions_table.csv
|
|
176
|
+
:header-rows: 1
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
__all__ = [
|
|
180
|
+
"SaveAmplitudes",
|
|
181
|
+
"SaveAmplitudesSquared",
|
|
182
|
+
"SaveClifford",
|
|
183
|
+
"SaveDensityMatrix",
|
|
184
|
+
"SaveExpectationValue",
|
|
185
|
+
"SaveExpectationValueVariance",
|
|
186
|
+
"SaveMatrixProductState",
|
|
187
|
+
"SaveProbabilities",
|
|
188
|
+
"SaveProbabilitiesDict",
|
|
189
|
+
"SaveStabilizer",
|
|
190
|
+
"SaveState",
|
|
191
|
+
"SaveStatevector",
|
|
192
|
+
"SaveStatevectorDict",
|
|
193
|
+
"SaveSuperOp",
|
|
194
|
+
"SaveUnitary",
|
|
195
|
+
"SetDensityMatrix",
|
|
196
|
+
"SetStabilizer",
|
|
197
|
+
"SetStatevector",
|
|
198
|
+
"SetSuperOp",
|
|
199
|
+
"SetUnitary",
|
|
200
|
+
"SetMatrixProductState",
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
from .save_instructions import *
|
|
204
|
+
from .set_instructions import *
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""Instructions to support control-flow for the Aer simulator"""
|
|
13
|
+
|
|
14
|
+
from .jump import AerJump
|
|
15
|
+
from .mark import AerMark
|
|
16
|
+
from .store import AerStore
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""
|
|
13
|
+
Simulator instruction to set a program counter
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import Instruction
|
|
17
|
+
from qiskit.circuit.classical.expr import Expr
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AerJump(Instruction):
|
|
21
|
+
"""
|
|
22
|
+
Jump instruction
|
|
23
|
+
|
|
24
|
+
This instruction sets a program counter to specified mark instruction.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
_directive = True
|
|
28
|
+
|
|
29
|
+
def __init__(self, jump_to, num_qubits, num_clbits=0):
|
|
30
|
+
super().__init__("jump", num_qubits, num_clbits, [jump_to])
|
|
31
|
+
self.condition_expr = None
|
|
32
|
+
self.condition = None
|
|
33
|
+
|
|
34
|
+
def set_conditional(self, cond):
|
|
35
|
+
"""Set condition to perform this jump instruction.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
cond (Expr or tuple): `Expr` to call `eval_bool` or tuple for `c_if`
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
AerJump: jump instruction added specified condition
|
|
42
|
+
"""
|
|
43
|
+
if isinstance(cond, Expr):
|
|
44
|
+
self.condition_expr = cond
|
|
45
|
+
else:
|
|
46
|
+
self.condition = cond
|
|
47
|
+
return self
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""
|
|
13
|
+
Simulator instruction to set a program counter
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import Instruction
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AerMark(Instruction):
|
|
20
|
+
"""
|
|
21
|
+
Mark instruction
|
|
22
|
+
|
|
23
|
+
This instruction is a destination of jump instruction.
|
|
24
|
+
Conditional is not allowed in Aer controller.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
_directive = True
|
|
28
|
+
|
|
29
|
+
def __init__(self, name, num_qubits, num_clbits=0):
|
|
30
|
+
super().__init__("mark", num_qubits, num_clbits, [name])
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""
|
|
13
|
+
Simulator instruction to set a program counter
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import Instruction
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AerStore(Instruction):
|
|
20
|
+
"""
|
|
21
|
+
Store instruction for Aer to work around transpilation issue
|
|
22
|
+
of qiskit.circuit.Store
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
_directive = True
|
|
26
|
+
|
|
27
|
+
def __init__(self, num_qubits, num_clbits, store):
|
|
28
|
+
super().__init__("aer_store", num_qubits, num_clbits, [store.lvalue, store.rvalue])
|
|
29
|
+
self.store = store
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""
|
|
13
|
+
Helper function
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumRegister
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def default_qubits(circuit, qubits=None):
|
|
20
|
+
"""Helper method to return list of qubits.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
circuit (QuantumCircuit): a quantum circuit.
|
|
24
|
+
qubits (list or QuantumRegister): Optional, qubits argument,
|
|
25
|
+
If None the returned list will be all qubits in the circuit.
|
|
26
|
+
[Default: None]
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
ValueError: if default qubits fails.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
list: qubits list.
|
|
33
|
+
"""
|
|
34
|
+
# Convert label to string for backwards compatibility
|
|
35
|
+
# If no qubits are specified we add all qubits so it acts as a barrier
|
|
36
|
+
# This is needed for full register snapshots like statevector
|
|
37
|
+
if isinstance(qubits, QuantumRegister):
|
|
38
|
+
qubits = qubits[:]
|
|
39
|
+
if qubits is None:
|
|
40
|
+
qubits = list(circuit.qubits)
|
|
41
|
+
if len(qubits) == 0:
|
|
42
|
+
raise ValueError("no qubits for snapshot")
|
|
43
|
+
|
|
44
|
+
return qubits
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Instruction,Automatic,Statevector,Density Matrix,MPS,Stabilizer,Ext. Stabilizer,Unitary,SuperOp
|
|
2
|
+
:class:`SaveAmplitudes`,✔,✔,✘,✔,✘,✘,✘,✘
|
|
3
|
+
:class:`SaveAmplitudesSquared`,✔,✔,✔,✔,✔,✘,✘,✘
|
|
4
|
+
:class:`SaveClifford`,✔,✘,✘,✘,✔,✘,✘,✘
|
|
5
|
+
:class:`SaveDensityMatrix`,✔,✔,✔,✔,✘,✘,✘,✘
|
|
6
|
+
:class:`SaveExpectationValue`,✔,✔,✔,✔,✔,✘,✘,✘
|
|
7
|
+
:class:`SaveExpectationValueVariance`,✔,✔,✔,✔,✔,✘,✘,✘
|
|
8
|
+
:class:`SaveMatrixProductState`,✘,✘,✘,✔,✘,✘,✘,✘
|
|
9
|
+
:class:`SaveProbabilities`,✔,✔,✔,✔,✔,✘,✘,✘
|
|
10
|
+
:class:`SaveProbabilitiesDict`,✔,✔,✔,✔,✔,✘,✘,✘
|
|
11
|
+
:class:`SaveStabilizer`,✔,✘,✘,✘,✔,✘,✘,✘
|
|
12
|
+
:class:`SaveState`,✔,✔,✔,✔,✔,✔,✔,✔
|
|
13
|
+
:class:`SaveStatevector`,✔,✔,✘,✔,✘,✔,✘,✘
|
|
14
|
+
:class:`SaveStatevectorDict`,✔,✔,✘,✘,✘,✘,✘,✘
|
|
15
|
+
:class:`SaveSuperOp`,✘,✘,✘,✘,✘,✘,✘,✔
|
|
16
|
+
:class:`SaveUnitary`,✘,✘,✘,✘,✘,✘,✔,✘
|
|
17
|
+
:class:`SetDensityMatrix`,✔,✘,✔,✘,✘,✘,✘,✘
|
|
18
|
+
:class:`SetStabilizer`,✔,✘,✘,✘,✔,✘,✘,✘
|
|
19
|
+
:class:`SetStatevector`,✔,✔,✘,✘,✘,✘,✘,✘
|
|
20
|
+
:class:`SetUnitary`,✘,✘,✘,✘,✘,✘,✔,✘
|
|
21
|
+
,,,,,,,,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2021.
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""Save directive instructions for the Aer simulator"""
|
|
13
|
+
|
|
14
|
+
from .save_state import SaveState, save_state
|
|
15
|
+
from .save_expectation_value import (
|
|
16
|
+
SaveExpectationValue,
|
|
17
|
+
save_expectation_value,
|
|
18
|
+
SaveExpectationValueVariance,
|
|
19
|
+
save_expectation_value_variance,
|
|
20
|
+
)
|
|
21
|
+
from .save_probabilities import (
|
|
22
|
+
SaveProbabilities,
|
|
23
|
+
save_probabilities,
|
|
24
|
+
SaveProbabilitiesDict,
|
|
25
|
+
save_probabilities_dict,
|
|
26
|
+
)
|
|
27
|
+
from .save_statevector import (
|
|
28
|
+
SaveStatevector,
|
|
29
|
+
save_statevector,
|
|
30
|
+
SaveStatevectorDict,
|
|
31
|
+
save_statevector_dict,
|
|
32
|
+
)
|
|
33
|
+
from .save_density_matrix import SaveDensityMatrix, save_density_matrix
|
|
34
|
+
from .save_amplitudes import (
|
|
35
|
+
SaveAmplitudes,
|
|
36
|
+
save_amplitudes,
|
|
37
|
+
SaveAmplitudesSquared,
|
|
38
|
+
save_amplitudes_squared,
|
|
39
|
+
)
|
|
40
|
+
from .save_stabilizer import SaveStabilizer, save_stabilizer
|
|
41
|
+
from .save_clifford import SaveClifford, save_clifford
|
|
42
|
+
from .save_unitary import SaveUnitary, save_unitary
|
|
43
|
+
from .save_matrix_product_state import SaveMatrixProductState, save_matrix_product_state
|
|
44
|
+
from .save_superop import SaveSuperOp, save_superop
|