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,120 @@
|
|
|
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 save statevector.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit
|
|
17
|
+
from .save_data import SaveSingleData
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SaveStatevector(SaveSingleData):
|
|
22
|
+
"""Save statevector"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, num_qubits, label="statevector", pershot=False, conditional=False):
|
|
25
|
+
"""Create new instruction to save the simulator statevector.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
num_qubits (int): the number of qubits
|
|
29
|
+
label (str): the key for retrieving saved data from results.
|
|
30
|
+
pershot (bool): if True save a list of statevectors for each
|
|
31
|
+
shot of the simulation rather than a single
|
|
32
|
+
statevector [Default: False].
|
|
33
|
+
conditional (bool): if True save data conditional on the current
|
|
34
|
+
classical register values [Default: False].
|
|
35
|
+
|
|
36
|
+
.. note::
|
|
37
|
+
|
|
38
|
+
This save instruction must always be performed on the full width of
|
|
39
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
40
|
+
simulation.
|
|
41
|
+
"""
|
|
42
|
+
super().__init__(
|
|
43
|
+
"save_statevector", num_qubits, label, pershot=pershot, conditional=conditional
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SaveStatevectorDict(SaveSingleData):
|
|
48
|
+
"""Save statevector as ket-form dictionary."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, num_qubits, label="statevector_dict", pershot=False, conditional=False):
|
|
51
|
+
"""Create new instruction to save the simulator statevector as a dict.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
num_qubits (int): the number of qubits
|
|
55
|
+
label (str): the key for retrieving saved data from results.
|
|
56
|
+
pershot (bool): if True save a list of statevectors for each
|
|
57
|
+
shot of the simulation rather than a single
|
|
58
|
+
statevector [Default: False].
|
|
59
|
+
conditional (bool): if True save data conditional on the current
|
|
60
|
+
classical register values [Default: False].
|
|
61
|
+
|
|
62
|
+
.. note::
|
|
63
|
+
|
|
64
|
+
This save instruction must always be performed on the full width of
|
|
65
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
66
|
+
simulation.
|
|
67
|
+
"""
|
|
68
|
+
super().__init__(
|
|
69
|
+
"save_statevector_dict", num_qubits, label, pershot=pershot, conditional=conditional
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def save_statevector(self, label="statevector", pershot=False, conditional=False):
|
|
74
|
+
"""Save the current simulator quantum state as a statevector.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
pershot (bool): if True save a list of statevectors for each
|
|
78
|
+
shot of the simulation [Default: False].
|
|
79
|
+
label (str): the key for retrieving saved data from results.
|
|
80
|
+
conditional (bool): if True save pershot data conditional on the
|
|
81
|
+
current classical register values
|
|
82
|
+
[Default: False].
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
QuantumCircuit: with attached instruction.
|
|
86
|
+
|
|
87
|
+
.. note::
|
|
88
|
+
|
|
89
|
+
This instruction is always defined across all qubits in a circuit.
|
|
90
|
+
"""
|
|
91
|
+
qubits = default_qubits(self)
|
|
92
|
+
instr = SaveStatevector(len(qubits), label=label, pershot=pershot, conditional=conditional)
|
|
93
|
+
return self.append(instr, qubits)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def save_statevector_dict(self, label="statevector", pershot=False, conditional=False):
|
|
97
|
+
"""Save the current simulator quantum state as a statevector as a dict.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
label (str): the key for retrieving saved data from results.
|
|
101
|
+
pershot (bool): if True save a list of statevectors for each
|
|
102
|
+
shot of the simulation [Default: False].
|
|
103
|
+
conditional (bool): if True save pershot data conditional on the
|
|
104
|
+
current classical register values
|
|
105
|
+
[Default: False].
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
QuantumCircuit: with attached instruction.
|
|
109
|
+
|
|
110
|
+
.. note::
|
|
111
|
+
|
|
112
|
+
This instruction is always defined across all qubits in a circuit.
|
|
113
|
+
"""
|
|
114
|
+
qubits = default_qubits(self)
|
|
115
|
+
instr = SaveStatevectorDict(len(qubits), label=label, pershot=pershot, conditional=conditional)
|
|
116
|
+
return self.append(instr, qubits)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
QuantumCircuit.save_statevector = save_statevector
|
|
120
|
+
QuantumCircuit.save_statevector_dict = save_statevector_dict
|
|
@@ -0,0 +1,62 @@
|
|
|
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 save a SuperOp matrix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit
|
|
17
|
+
from .save_data import SaveSingleData
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SaveSuperOp(SaveSingleData):
|
|
22
|
+
"""Save a SuperOp matrix."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, num_qubits, label="superop", pershot=False):
|
|
25
|
+
"""Create new instruction to save the superop simulator state.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
num_qubits (int): the number of qubits for the save instruction.
|
|
29
|
+
label (str): the key for retrieving saved data from results.
|
|
30
|
+
pershot (bool): if True save a list of SuperOp matrices for each shot
|
|
31
|
+
of the simulation [Default: False].
|
|
32
|
+
|
|
33
|
+
.. note::
|
|
34
|
+
|
|
35
|
+
This save instruction must always be performed on the full width of
|
|
36
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
37
|
+
simulation.
|
|
38
|
+
"""
|
|
39
|
+
super().__init__("save_superop", num_qubits, label, pershot=pershot)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def save_superop(self, label="superop", pershot=False):
|
|
43
|
+
"""Save the current state of the superop simulator.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
label (str): the key for retrieving saved data from results.
|
|
47
|
+
pershot (bool): if True save a list of SuperOp matrices for each shot
|
|
48
|
+
of the simulation [Default: False].
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
QuantumCircuit: with attached instruction.
|
|
52
|
+
|
|
53
|
+
.. note::
|
|
54
|
+
|
|
55
|
+
This instruction is always defined across all qubits in a circuit.
|
|
56
|
+
"""
|
|
57
|
+
qubits = default_qubits(self)
|
|
58
|
+
instr = SaveSuperOp(len(qubits), label=label, pershot=pershot)
|
|
59
|
+
return self.append(instr, qubits)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
QuantumCircuit.save_superop = save_superop
|
|
@@ -0,0 +1,63 @@
|
|
|
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 save unitary matrix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit
|
|
17
|
+
from .save_data import SaveSingleData
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SaveUnitary(SaveSingleData):
|
|
22
|
+
"""Save Unitary"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, num_qubits, label="unitary", pershot=False):
|
|
25
|
+
"""Create new instruction to save the unitary simulator state.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
num_qubits (int): the number of qubits of the
|
|
29
|
+
label (str): the key for retrieving saved data from results.
|
|
30
|
+
pershot (bool): if True save a list of unitaries for each
|
|
31
|
+
shot of the simulation rather than a single
|
|
32
|
+
statevector [Default: False].
|
|
33
|
+
|
|
34
|
+
.. note::
|
|
35
|
+
|
|
36
|
+
This save instruction must always be performed on the full width of
|
|
37
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
38
|
+
simulation.
|
|
39
|
+
"""
|
|
40
|
+
super().__init__("save_unitary", num_qubits, label, pershot=pershot)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def save_unitary(self, label="unitary", pershot=False):
|
|
44
|
+
"""Save the current state of the unitary simulator.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
label (str): the key for retrieving saved data from results.
|
|
48
|
+
pershot (bool): if True save a list of unitaries for each
|
|
49
|
+
shot of the simulation [Default: False].
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
QuantumCircuit: with attached instruction.
|
|
53
|
+
|
|
54
|
+
.. note::
|
|
55
|
+
|
|
56
|
+
This instruction is always defined across all qubits in a circuit.
|
|
57
|
+
"""
|
|
58
|
+
qubits = default_qubits(self)
|
|
59
|
+
instr = SaveUnitary(len(qubits), label=label, pershot=pershot)
|
|
60
|
+
return self.append(instr, qubits)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
QuantumCircuit.save_unitary = save_unitary
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
"""Set state directive instructions for the Aer simulator"""
|
|
13
|
+
|
|
14
|
+
from .set_statevector import SetStatevector, set_statevector
|
|
15
|
+
from .set_density_matrix import SetDensityMatrix, set_density_matrix
|
|
16
|
+
from .set_unitary import SetUnitary, set_unitary
|
|
17
|
+
from .set_stabilizer import SetStabilizer, set_stabilizer
|
|
18
|
+
from .set_superop import SetSuperOp, set_superop
|
|
19
|
+
from .set_matrix_product_state import SetMatrixProductState, set_matrix_product_state
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
Instruction to set the density matrix simulator state to a matrix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit, Instruction
|
|
17
|
+
from qiskit.quantum_info import DensityMatrix
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SetDensityMatrix(Instruction):
|
|
22
|
+
"""Set density matrix state of the simulator"""
|
|
23
|
+
|
|
24
|
+
_directive = True
|
|
25
|
+
|
|
26
|
+
def __init__(self, state):
|
|
27
|
+
"""Create new instruction to set the density matrix state of the simulator.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
state (DensityMatrix): a density matrix.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
ValueError: if the input density matrix is not valid.
|
|
34
|
+
|
|
35
|
+
.. note::
|
|
36
|
+
|
|
37
|
+
This set instruction must always be performed on the full width of
|
|
38
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
39
|
+
simulation.
|
|
40
|
+
"""
|
|
41
|
+
if not isinstance(state, DensityMatrix):
|
|
42
|
+
state = DensityMatrix(state)
|
|
43
|
+
if not state.num_qubits or not state.is_valid():
|
|
44
|
+
raise ValueError("The input state is not valid")
|
|
45
|
+
super().__init__("set_density_matrix", state.num_qubits, 0, [state.data])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def set_density_matrix(self, state):
|
|
49
|
+
"""Set the density matrix state of the simulator.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
state (DensityMatrix): a density matrix.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
QuantumCircuit: with attached instruction.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the density matrix is the incorrect size for the
|
|
59
|
+
current circuit.
|
|
60
|
+
|
|
61
|
+
.. note:
|
|
62
|
+
|
|
63
|
+
This instruction is always defined across all qubits in a circuit.
|
|
64
|
+
"""
|
|
65
|
+
qubits = default_qubits(self)
|
|
66
|
+
if not isinstance(state, DensityMatrix):
|
|
67
|
+
state = DensityMatrix(state)
|
|
68
|
+
if not state.num_qubits or state.num_qubits != len(qubits):
|
|
69
|
+
raise ValueError(
|
|
70
|
+
"The size of the density matrix for the set state"
|
|
71
|
+
" instruction must be equal to the number of qubits"
|
|
72
|
+
f" in the circuit (state.num_qubits ({state.num_qubits})"
|
|
73
|
+
f" != QuantumCircuit.num_qubits ({self.num_qubits}))."
|
|
74
|
+
)
|
|
75
|
+
return self.append(SetDensityMatrix(state), qubits)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
QuantumCircuit.set_density_matrix = set_density_matrix
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
Instruction to set the state simulator state to a matrix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit, Instruction
|
|
17
|
+
from ..default_qubits import default_qubits
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SetMatrixProductState(Instruction):
|
|
21
|
+
"""Set the matrix product state of the simulator"""
|
|
22
|
+
|
|
23
|
+
_directive = True
|
|
24
|
+
|
|
25
|
+
def __init__(self, state):
|
|
26
|
+
"""Create new instruction to set the matrix product state of the simulator.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
state (Tuple[List[Tuple[np.array[complex_t]]]], List[List[float]]):
|
|
30
|
+
A matrix_product_state.
|
|
31
|
+
|
|
32
|
+
.. note::
|
|
33
|
+
|
|
34
|
+
This set instruction must always be performed on the full width of
|
|
35
|
+
qubits in a circuit.
|
|
36
|
+
The matrix_product_state consists of a pair of vectors. The first is a
|
|
37
|
+
vector of pairs of matrices of complex numbers. The second is a vector of
|
|
38
|
+
vectors of double.
|
|
39
|
+
"""
|
|
40
|
+
super().__init__("set_matrix_product_state", len(state[0]), 0, [state])
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def set_matrix_product_state(self, state):
|
|
44
|
+
"""Set the matrix product state of the simulator.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
state (Tuple[List[Tuple[np.array[complex_t]]]], List[List[float]]):
|
|
48
|
+
A matrix_product_state.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
QuantumCircuit: with attached instruction.
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
ValueError: If the structure of the state is incorrect
|
|
55
|
+
|
|
56
|
+
.. note:
|
|
57
|
+
|
|
58
|
+
This instruction is always defined across all qubits in a circuit.
|
|
59
|
+
"""
|
|
60
|
+
qubits = default_qubits(self)
|
|
61
|
+
if not isinstance(state, tuple) or len(state) != 2:
|
|
62
|
+
raise ValueError(
|
|
63
|
+
"The input matrix product state is not valid. Should be a list of 2 elements"
|
|
64
|
+
)
|
|
65
|
+
if not isinstance(state[0], list) or not isinstance(state[1], list):
|
|
66
|
+
raise ValueError(
|
|
67
|
+
"The first element of the input matrix product state is not valid. Should be a list."
|
|
68
|
+
)
|
|
69
|
+
if len(state[0]) != len(state[1]) + 1:
|
|
70
|
+
raise ValueError(
|
|
71
|
+
"The input matrix product state is not valid. "
|
|
72
|
+
"Length of q_reg vector should be 1 more than length of lambda_reg"
|
|
73
|
+
)
|
|
74
|
+
for elem in state[0]:
|
|
75
|
+
if not isinstance(elem, tuple) or len(elem) != 2:
|
|
76
|
+
raise ValueError(
|
|
77
|
+
"The input matrix product state is not valid."
|
|
78
|
+
"The first element should be a list of length 2"
|
|
79
|
+
)
|
|
80
|
+
return self.append(SetMatrixProductState(state), qubits)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
QuantumCircuit.set_matrix_product_state = set_matrix_product_state
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
Instruction to set the simulator state to a stabilizer state.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit, Instruction
|
|
17
|
+
from qiskit.quantum_info import StabilizerState, Clifford
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SetStabilizer(Instruction):
|
|
22
|
+
"""Set the Clifford stabilizer state of the simulator"""
|
|
23
|
+
|
|
24
|
+
_directive = True
|
|
25
|
+
|
|
26
|
+
def __init__(self, state):
|
|
27
|
+
"""Create new instruction to set the Clifford stabilizer state of the simulator.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
state (StabilizerState or Clifford): A clifford operator.
|
|
31
|
+
|
|
32
|
+
.. note::
|
|
33
|
+
|
|
34
|
+
This set instruction must always be performed on the full width of
|
|
35
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
36
|
+
simulation.
|
|
37
|
+
"""
|
|
38
|
+
if isinstance(state, StabilizerState):
|
|
39
|
+
state = state.clifford
|
|
40
|
+
elif not isinstance(state, Clifford):
|
|
41
|
+
state = Clifford(state)
|
|
42
|
+
super().__init__("set_stabilizer", state.num_qubits, 0, [state.to_dict()])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def set_stabilizer(self, state):
|
|
46
|
+
"""Set the Clifford stabilizer state of the simulator.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
state (Clifford): A clifford operator.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
QuantumCircuit: with attached instruction.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
ValueError: If the state is the incorrect size for the
|
|
56
|
+
current circuit.
|
|
57
|
+
|
|
58
|
+
.. note:
|
|
59
|
+
|
|
60
|
+
This instruction is always defined across all qubits in a circuit.
|
|
61
|
+
"""
|
|
62
|
+
qubits = default_qubits(self)
|
|
63
|
+
if isinstance(state, StabilizerState):
|
|
64
|
+
state = state.clifford
|
|
65
|
+
if not isinstance(state, Clifford):
|
|
66
|
+
state = Clifford(state)
|
|
67
|
+
if state.num_qubits != len(qubits):
|
|
68
|
+
raise ValueError(
|
|
69
|
+
"The size of the Clifford for the set_stabilizer"
|
|
70
|
+
" instruction must be equal to the number of qubits"
|
|
71
|
+
f" in the circuit (state.num_qubits ({state.num_qubits})"
|
|
72
|
+
f" != QuantumCircuit.num_qubits ({self.num_qubits}))."
|
|
73
|
+
)
|
|
74
|
+
return self.append(SetStabilizer(state), qubits)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
QuantumCircuit.set_stabilizer = set_stabilizer
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
Instruction to set the state simulator state to a matrix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit, Instruction
|
|
17
|
+
from qiskit.quantum_info import Statevector
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SetStatevector(Instruction):
|
|
22
|
+
"""Set the statevector state of the simulator"""
|
|
23
|
+
|
|
24
|
+
_directive = True
|
|
25
|
+
|
|
26
|
+
def __init__(self, state):
|
|
27
|
+
"""Create new instruction to set the statevector state of the simulator.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
state (Statevector): a statevector.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
ValueError: if the input is not a valid state.
|
|
34
|
+
|
|
35
|
+
.. note::
|
|
36
|
+
|
|
37
|
+
This set instruction must always be performed on the full width of
|
|
38
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
39
|
+
simulation.
|
|
40
|
+
"""
|
|
41
|
+
if not isinstance(state, Statevector):
|
|
42
|
+
state = Statevector(state)
|
|
43
|
+
if not state.num_qubits or not state.is_valid():
|
|
44
|
+
raise ValueError("The input statevector is not valid")
|
|
45
|
+
super().__init__("set_statevector", state.num_qubits, 0, [state.data])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def set_statevector(self, state):
|
|
49
|
+
"""Set the statevector state of the simulator.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
state (Statevector): A state matrix.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
QuantumCircuit: with attached instruction.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the state is the incorrect size for the
|
|
59
|
+
current circuit.
|
|
60
|
+
|
|
61
|
+
.. note:
|
|
62
|
+
|
|
63
|
+
This instruction is always defined across all qubits in a circuit.
|
|
64
|
+
"""
|
|
65
|
+
qubits = default_qubits(self)
|
|
66
|
+
if not isinstance(state, Statevector):
|
|
67
|
+
state = Statevector(state)
|
|
68
|
+
if not state.num_qubits or state.num_qubits != len(qubits):
|
|
69
|
+
raise ValueError(
|
|
70
|
+
"The size of the statevector for the set_statevector"
|
|
71
|
+
" instruction must be equal to the number of qubits"
|
|
72
|
+
f" in the circuit (state.num_qubits ({state.num_qubits})"
|
|
73
|
+
f" != QuantumCircuit.num_qubits ({self.num_qubits}))."
|
|
74
|
+
)
|
|
75
|
+
return self.append(SetStatevector(state), qubits)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
QuantumCircuit.set_statevector = set_statevector
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
Instruction to set the state simulator state to a superop matrix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit, Instruction
|
|
17
|
+
from qiskit.quantum_info import SuperOp
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SetSuperOp(Instruction):
|
|
22
|
+
"""Set superop state of the simulator"""
|
|
23
|
+
|
|
24
|
+
_directive = True
|
|
25
|
+
|
|
26
|
+
def __init__(self, state):
|
|
27
|
+
"""Create new instruction to set the superop simulator state.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
state (QuantumChannel): A CPTP quantum channel.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
ValueError: if the input QuantumChannel is not CPTP.
|
|
34
|
+
|
|
35
|
+
.. note::
|
|
36
|
+
|
|
37
|
+
This set instruction must always be performed on the full width of
|
|
38
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
39
|
+
simulation.
|
|
40
|
+
"""
|
|
41
|
+
if not isinstance(state, SuperOp):
|
|
42
|
+
state = SuperOp(state)
|
|
43
|
+
if not state.num_qubits or not state.is_cptp():
|
|
44
|
+
raise ValueError("The input quantum channel is not CPTP")
|
|
45
|
+
super().__init__("set_superop", state.num_qubits, 0, [state.data])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def set_superop(self, state):
|
|
49
|
+
"""Set the superop state of the simulator.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
state (QuantumChannel): A CPTP quantum channel.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
QuantumCircuit: with attached instruction.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the state is the incorrect size for the current circuit.
|
|
59
|
+
ValueError: if the input QuantumChannel is not CPTP.
|
|
60
|
+
|
|
61
|
+
.. note:
|
|
62
|
+
|
|
63
|
+
This instruction is always defined across all qubits in a circuit.
|
|
64
|
+
"""
|
|
65
|
+
qubits = default_qubits(self)
|
|
66
|
+
if not isinstance(state, SuperOp):
|
|
67
|
+
state = SuperOp(state)
|
|
68
|
+
if not state.num_qubits or state.num_qubits != len(qubits):
|
|
69
|
+
raise ValueError(
|
|
70
|
+
"The size of the quantum channel for the set_superop"
|
|
71
|
+
" instruction must be equal to the number of qubits"
|
|
72
|
+
f" in the circuit (state.num_qubits ({state.num_qubits})"
|
|
73
|
+
f" != QuantumCircuit.num_qubits ({self.num_qubits}))."
|
|
74
|
+
)
|
|
75
|
+
return self.append(SetSuperOp(state), qubits)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
QuantumCircuit.set_superop = set_superop
|