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.
Files changed (83) hide show
  1. qiskit_aer/VERSION.txt +1 -0
  2. qiskit_aer/__init__.py +89 -0
  3. qiskit_aer/aererror.py +30 -0
  4. qiskit_aer/aerprovider.py +119 -0
  5. qiskit_aer/backends/__init__.py +20 -0
  6. qiskit_aer/backends/aer_compiler.py +1085 -0
  7. qiskit_aer/backends/aer_simulator.py +1025 -0
  8. qiskit_aer/backends/aerbackend.py +679 -0
  9. qiskit_aer/backends/backend_utils.py +567 -0
  10. qiskit_aer/backends/backendconfiguration.py +395 -0
  11. qiskit_aer/backends/backendproperties.py +590 -0
  12. qiskit_aer/backends/compatibility.py +287 -0
  13. qiskit_aer/backends/controller_wrappers.cp314-win_amd64.pyd +0 -0
  14. qiskit_aer/backends/libopenblas.dll +0 -0
  15. qiskit_aer/backends/name_mapping.py +306 -0
  16. qiskit_aer/backends/qasm_simulator.py +925 -0
  17. qiskit_aer/backends/statevector_simulator.py +330 -0
  18. qiskit_aer/backends/unitary_simulator.py +316 -0
  19. qiskit_aer/jobs/__init__.py +35 -0
  20. qiskit_aer/jobs/aerjob.py +143 -0
  21. qiskit_aer/jobs/utils.py +66 -0
  22. qiskit_aer/library/__init__.py +204 -0
  23. qiskit_aer/library/control_flow_instructions/__init__.py +16 -0
  24. qiskit_aer/library/control_flow_instructions/jump.py +47 -0
  25. qiskit_aer/library/control_flow_instructions/mark.py +30 -0
  26. qiskit_aer/library/control_flow_instructions/store.py +29 -0
  27. qiskit_aer/library/default_qubits.py +44 -0
  28. qiskit_aer/library/instructions_table.csv +21 -0
  29. qiskit_aer/library/save_instructions/__init__.py +44 -0
  30. qiskit_aer/library/save_instructions/save_amplitudes.py +168 -0
  31. qiskit_aer/library/save_instructions/save_clifford.py +63 -0
  32. qiskit_aer/library/save_instructions/save_data.py +129 -0
  33. qiskit_aer/library/save_instructions/save_density_matrix.py +91 -0
  34. qiskit_aer/library/save_instructions/save_expectation_value.py +257 -0
  35. qiskit_aer/library/save_instructions/save_matrix_product_state.py +71 -0
  36. qiskit_aer/library/save_instructions/save_probabilities.py +156 -0
  37. qiskit_aer/library/save_instructions/save_stabilizer.py +70 -0
  38. qiskit_aer/library/save_instructions/save_state.py +79 -0
  39. qiskit_aer/library/save_instructions/save_statevector.py +120 -0
  40. qiskit_aer/library/save_instructions/save_superop.py +62 -0
  41. qiskit_aer/library/save_instructions/save_unitary.py +63 -0
  42. qiskit_aer/library/set_instructions/__init__.py +19 -0
  43. qiskit_aer/library/set_instructions/set_density_matrix.py +78 -0
  44. qiskit_aer/library/set_instructions/set_matrix_product_state.py +83 -0
  45. qiskit_aer/library/set_instructions/set_stabilizer.py +77 -0
  46. qiskit_aer/library/set_instructions/set_statevector.py +78 -0
  47. qiskit_aer/library/set_instructions/set_superop.py +78 -0
  48. qiskit_aer/library/set_instructions/set_unitary.py +78 -0
  49. qiskit_aer/noise/__init__.py +265 -0
  50. qiskit_aer/noise/device/__init__.py +25 -0
  51. qiskit_aer/noise/device/models.py +397 -0
  52. qiskit_aer/noise/device/parameters.py +202 -0
  53. qiskit_aer/noise/errors/__init__.py +30 -0
  54. qiskit_aer/noise/errors/base_quantum_error.py +119 -0
  55. qiskit_aer/noise/errors/pauli_error.py +283 -0
  56. qiskit_aer/noise/errors/pauli_lindblad_error.py +363 -0
  57. qiskit_aer/noise/errors/quantum_error.py +451 -0
  58. qiskit_aer/noise/errors/readout_error.py +355 -0
  59. qiskit_aer/noise/errors/standard_errors.py +498 -0
  60. qiskit_aer/noise/noise_model.py +1231 -0
  61. qiskit_aer/noise/noiseerror.py +30 -0
  62. qiskit_aer/noise/passes/__init__.py +18 -0
  63. qiskit_aer/noise/passes/local_noise_pass.py +160 -0
  64. qiskit_aer/noise/passes/relaxation_noise_pass.py +137 -0
  65. qiskit_aer/primitives/__init__.py +44 -0
  66. qiskit_aer/primitives/estimator.py +751 -0
  67. qiskit_aer/primitives/estimator_v2.py +159 -0
  68. qiskit_aer/primitives/sampler.py +361 -0
  69. qiskit_aer/primitives/sampler_v2.py +256 -0
  70. qiskit_aer/quantum_info/__init__.py +32 -0
  71. qiskit_aer/quantum_info/states/__init__.py +16 -0
  72. qiskit_aer/quantum_info/states/aer_densitymatrix.py +313 -0
  73. qiskit_aer/quantum_info/states/aer_state.py +525 -0
  74. qiskit_aer/quantum_info/states/aer_statevector.py +302 -0
  75. qiskit_aer/utils/__init__.py +44 -0
  76. qiskit_aer/utils/noise_model_inserter.py +66 -0
  77. qiskit_aer/utils/noise_transformation.py +431 -0
  78. qiskit_aer/version.py +86 -0
  79. qiskit_aer-0.17.2.dist-info/METADATA +209 -0
  80. qiskit_aer-0.17.2.dist-info/RECORD +83 -0
  81. qiskit_aer-0.17.2.dist-info/WHEEL +5 -0
  82. qiskit_aer-0.17.2.dist-info/licenses/LICENSE.txt +203 -0
  83. qiskit_aer-0.17.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,30 @@
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
+ """
14
+ Exception for errors raised by Aer noise module.
15
+ """
16
+
17
+ from qiskit import QiskitError
18
+
19
+
20
+ class NoiseError(QiskitError):
21
+ """Class for errors raised in qiskit_aer.noise package."""
22
+
23
+ def __init__(self, *message):
24
+ """Set the error message."""
25
+ super().__init__(*message)
26
+ self.message = " ".join(message)
27
+
28
+ def __str__(self):
29
+ """Return the message."""
30
+ return repr(self.message)
@@ -0,0 +1,18 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 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
+ Passes for adding noises.
15
+ """
16
+
17
+ from .local_noise_pass import LocalNoisePass
18
+ from .relaxation_noise_pass import RelaxationNoisePass
@@ -0,0 +1,160 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 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
+ Local noise addition pass.
14
+ """
15
+ from typing import Optional, Union, Sequence, Callable, Iterable
16
+
17
+ from qiskit.circuit import Instruction, QuantumCircuit
18
+ from qiskit.dagcircuit import DAGCircuit
19
+ from qiskit.converters import circuit_to_dag
20
+ from qiskit.transpiler import TransformationPass
21
+ from qiskit.transpiler.exceptions import TranspilerError
22
+ from ..errors import QuantumError, ReadoutError
23
+
24
+ InstructionLike = Union[Instruction, QuantumError, QuantumCircuit]
25
+
26
+
27
+ class LocalNoisePass(TransformationPass):
28
+ """Transpiler pass to insert noise into a circuit.
29
+
30
+ The noise in this pass is defined by a noise function or callable with signature
31
+
32
+ .. code:: python
33
+
34
+ def func(
35
+ inst: Instruction,
36
+ qubits: Optional[List[int]] = None
37
+ ) -> InstructionLike:
38
+
39
+ For every instance of one of the reference instructions in a circuit the
40
+ supplied function is called on that instruction and the returned noise
41
+ is added to the circuit. This noise can depend on properties of the
42
+ instruction it is called on (for example parameters or duration) to
43
+ allow inserting parameterized noise models.
44
+
45
+ Several methods for adding the constructed errors to circuits are supported
46
+ and can be set by using the ``method`` kwarg. The supported methods are
47
+
48
+ * ``"append"``: add the return of the callable after the instruction.
49
+ * ``"prepend"``: add the return of the callable before the instruction.
50
+ * ``"replace"``: replace the instruction with the return of the callable.
51
+ If the return is None, the instruction will be removed.
52
+
53
+ """
54
+
55
+ def __init__(
56
+ self,
57
+ func: Callable[[Instruction, Sequence[int]], Optional[InstructionLike]],
58
+ op_types: Optional[Union[type, Iterable[type]]] = None,
59
+ method: str = "append",
60
+ ):
61
+ """Initialize noise pass.
62
+
63
+ Args:
64
+ func: noise function `func(inst, qubits) -> InstructionLike`.
65
+ op_types: Optional, single or list of instruction types to apply the
66
+ noise function to. If None the noise function will be
67
+ applied to all instructions in the circuit.
68
+ method: method for inserting noise. Allow methods are
69
+ 'append', 'prepend', 'replace'.
70
+ Raises:
71
+ TranspilerError: if an invalid option is specified.
72
+ """
73
+ if method not in {"append", "prepend", "replace"}:
74
+ raise TranspilerError(
75
+ f'Invalid method: {method}, it must be "append", "prepend" or "replace"'
76
+ )
77
+ if isinstance(op_types, type):
78
+ op_types = (op_types,)
79
+ super().__init__()
80
+ self._func = func
81
+ self._ops = tuple(op_types) if op_types else tuple()
82
+ self._method = method
83
+ if not all(isinstance(op, type) for op in self._ops):
84
+ raise TranspilerError(
85
+ f"Invalid ops: '{op_types}', expecting single or list of operation types (or None)"
86
+ )
87
+
88
+ def run(self, dag: DAGCircuit) -> DAGCircuit:
89
+ """Run the LocalNoisePass pass on `dag`.
90
+ Args:
91
+ dag: DAG to be changed.
92
+ Returns:
93
+ A changed DAG.
94
+ Raises:
95
+ TranspilerError: if generated operation is not valid.
96
+ """
97
+ qubit_indices = {qubit: idx for idx, qubit in enumerate(dag.qubits)}
98
+ for node in dag.topological_op_nodes():
99
+ if self._ops and not isinstance(node.op, self._ops):
100
+ continue
101
+
102
+ qubits = [qubit_indices[q] for q in node.qargs]
103
+ new_op = self._func(node.op, qubits)
104
+
105
+ if new_op is None:
106
+ # Edge case where we are replacing a node with nothing (removing node)
107
+ if self._method == "replace":
108
+ dag.remove_op_node(node)
109
+ continue
110
+
111
+ if isinstance(new_op, ReadoutError):
112
+ raise TranspilerError("Insertions of ReadoutError is not yet supported.")
113
+
114
+ # Initialize new node dag
115
+ new_dag = DAGCircuit()
116
+ new_dag.add_qubits(node.qargs)
117
+ new_dag.add_clbits(node.cargs)
118
+
119
+ # If appending re-apply original op node first
120
+ if self._method == "append":
121
+ new_dag.apply_operation_back(node.op, qargs=node.qargs, cargs=node.cargs)
122
+
123
+ # If the new op is not a QuantumCircuit or Instruction, attempt
124
+ # to conver to an Instruction
125
+ if not isinstance(new_op, (QuantumCircuit, Instruction)):
126
+ try:
127
+ new_op = new_op.to_instruction()
128
+ except AttributeError as att_err:
129
+ raise TranspilerError(
130
+ "Function must return an object implementing 'to_instruction' method."
131
+ ) from att_err
132
+
133
+ if new_op.num_clbits > 0:
134
+ raise TranspilerError("Noise must be an instruction without clbits.")
135
+
136
+ # Validate the instruction matches the number of qubits and clbits of the node
137
+ if new_op.num_qubits != len(node.qargs):
138
+ raise TranspilerError(
139
+ f"Number of qubits of generated op {new_op.num_qubits} != "
140
+ f"{len(node.qargs)} that of a reference op {node.name}"
141
+ )
142
+
143
+ # Add the noise op returned by the function
144
+ if isinstance(new_op, QuantumCircuit):
145
+ # If the new op is a quantum circuit, compose its DAG with the new dag
146
+ # so that it is unrolled rather than added as an opaque instruction
147
+ new_dag.compose(
148
+ circuit_to_dag(new_op), qubits=list(node.qargs)
149
+ ) # never touch clbits
150
+ else:
151
+ # Otherwise append the instruction returned by the function
152
+ new_dag.apply_operation_back(new_op, qargs=node.qargs) # never touch cargs
153
+
154
+ # If prepending reapply original op node last
155
+ if self._method == "prepend":
156
+ new_dag.apply_operation_back(node.op, qargs=node.qargs, cargs=node.cargs)
157
+
158
+ dag.substitute_node_with_dag(node, new_dag)
159
+
160
+ return dag
@@ -0,0 +1,137 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 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
+ Thermal relaxation noise pass.
14
+ """
15
+ import warnings
16
+ from typing import Optional, Union, Sequence, List
17
+
18
+ import numpy as np
19
+
20
+ from qiskit.circuit import Instruction, QuantumCircuit
21
+ from qiskit.transpiler import Target
22
+ from qiskit.utils.units import apply_prefix
23
+ from .local_noise_pass import LocalNoisePass
24
+ from ..errors.standard_errors import thermal_relaxation_error
25
+ from ..noiseerror import NoiseError
26
+
27
+
28
+ class RelaxationNoisePass(LocalNoisePass):
29
+ """Add duration dependent thermal relaxation noise after instructions."""
30
+
31
+ def __init__(
32
+ self,
33
+ t1s: List[float],
34
+ t2s: List[float],
35
+ dt: Optional[float] = None,
36
+ op_types: Optional[Union[type, Sequence[type]]] = None,
37
+ excited_state_populations: Optional[List[float]] = None,
38
+ target: Target = None,
39
+ ):
40
+ """Initialize RelaxationNoisePass.
41
+
42
+ Args:
43
+ t1s: List of T1 times in seconds for each qubit.
44
+ t2s: List of T2 times in seconds for each qubit.
45
+ dt: Backend sample time (resolution) in seconds. This is required
46
+ for converting dt-unit op durations to times in scheduled circuits.
47
+ op_types: Optional, the operation types to add relaxation to. If None
48
+ relaxation will be added to all operations.
49
+ excited_state_populations: Optional, list of excited state populations
50
+ for each qubit at thermal equilibrium. If not supplied or obtained
51
+ from the backend this will be set to 0 for each qubit.
52
+ target: Optional, target instance with instruction duration information.
53
+ """
54
+ self._t1s = np.asarray(t1s)
55
+ self._t2s = np.asarray(t2s)
56
+ if excited_state_populations is not None:
57
+ self._p1s = np.asarray(excited_state_populations)
58
+ else:
59
+ self._p1s = np.zeros(len(t1s))
60
+ self._dt = dt
61
+ self._target = target
62
+ super().__init__(self._thermal_relaxation_error, op_types=op_types, method="append")
63
+
64
+ def _thermal_relaxation_error(self, op: Instruction, qubits: Sequence[int]):
65
+ """Return thermal relaxation error on each operand qubit"""
66
+
67
+ duration = None
68
+
69
+ if self._target is not None:
70
+ if op.name == "delay":
71
+ duration = op.duration
72
+ if duration is not None:
73
+ # Convert op duration to seconds
74
+ if op.unit == "dt":
75
+ if self._dt is None:
76
+ raise NoiseError(
77
+ "RelaxationNoisePass cannot apply noise to a 'dt' unit duration"
78
+ " without a dt time set."
79
+ )
80
+ duration = op.duration * self._dt
81
+ else:
82
+ duration = apply_prefix(op.duration, op.unit)
83
+ else:
84
+ op_props = self._target.get(op.name)
85
+ if op_props is not None:
86
+ inst_props = op_props.get(tuple(qubits))
87
+ if inst_props is not None:
88
+ # get duration in seconds
89
+ duration = getattr(inst_props, "duration")
90
+ else:
91
+ try:
92
+ duration = op.duration
93
+ if duration is not None:
94
+ # Convert op duration to seconds
95
+ if op.unit == "dt":
96
+ if self._dt is None:
97
+ raise NoiseError(
98
+ "RelaxationNoisePass cannot apply noise to a 'dt' unit duration"
99
+ " without a dt time set."
100
+ )
101
+ duration = op.duration * self._dt
102
+ else:
103
+ duration = apply_prefix(op.duration, op.unit)
104
+
105
+ except AttributeError:
106
+ duration = None
107
+
108
+ if duration is None:
109
+ warnings.warn(
110
+ f"Instruction duration not found for {op.name}. RelaxationNoisePass ignores "
111
+ "instructions without duration. "
112
+ "To avoid this warning, provide the corresponding duration information via `target`.",
113
+ UserWarning,
114
+ )
115
+ return None
116
+
117
+ t1s = self._t1s[qubits]
118
+ t2s = self._t2s[qubits]
119
+ p1s = self._p1s[qubits]
120
+
121
+ # pylint: disable=invalid-name
122
+ if op.num_qubits == 1:
123
+ t1, t2, p1 = t1s[0], t2s[0], p1s[0]
124
+ if t1 == np.inf and t2 == np.inf:
125
+ return None
126
+ return thermal_relaxation_error(t1, t2, duration, p1)
127
+
128
+ # General multi-qubit case
129
+ noise = QuantumCircuit(op.num_qubits)
130
+ for qubit, (t1, t2, p1) in enumerate(zip(t1s, t2s, p1s)):
131
+ if t1 == np.inf and t2 == np.inf:
132
+ # No relaxation on this qubit
133
+ continue
134
+ error = thermal_relaxation_error(t1, t2, duration, p1)
135
+ noise.append(error.to_instruction(), [qubit])
136
+
137
+ return noise
@@ -0,0 +1,44 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2022.
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
+ ===================================================
15
+ Primitives (:mod:`qiskit_aer.primitives`)
16
+ ===================================================
17
+
18
+ .. currentmodule:: qiskit_aer.primitives
19
+
20
+ This module is Aer implementation of primitives.
21
+ See the docs https://quantum.cloud.ibm.com/docs/api/qiskit/primitives for general descriptions.
22
+
23
+
24
+ Classes
25
+ =======
26
+
27
+ .. autosummary::
28
+ :toctree: ../stubs/
29
+
30
+ Sampler
31
+ Estimator
32
+ SamplerV2
33
+ EstimatorV2
34
+
35
+ """
36
+
37
+ import qiskit
38
+
39
+ from .estimator import Estimator
40
+ from .sampler import Sampler
41
+
42
+ if not qiskit.__version__.startswith("0."):
43
+ from .estimator_v2 import EstimatorV2
44
+ from .sampler_v2 import SamplerV2