-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instructions to set simulator state (#1163)
- Loading branch information
1 parent
4f615be
commit 25a6d91
Showing
43 changed files
with
972 additions
and
167 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
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 2018, 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. | ||
""" | ||
Helper function | ||
""" | ||
|
||
from qiskit.circuit import QuantumCircuit, QuantumRegister | ||
from qiskit.extensions.exceptions import ExtensionError | ||
|
||
|
||
def default_qubits(circuit, qubits=None): | ||
"""Helper method to return list of qubits. | ||
Args: | ||
circuit (QuantumCircuit): a quantum circuit. | ||
qubits (list or QuantumRegister): Optional, qubits argument, | ||
If None the returned list will be all qubits in the circuit. | ||
[Default: None] | ||
Raises: | ||
ExtensionError: if default qubits fails. | ||
Returns: | ||
list: qubits list. | ||
""" | ||
# Convert label to string for backwards compatibility | ||
# If no qubits are specified we add all qubits so it acts as a barrier | ||
# This is needed for full register snapshots like statevector | ||
if isinstance(qubits, QuantumRegister): | ||
qubits = qubits[:] | ||
if not qubits: | ||
tuples = [] | ||
if isinstance(circuit, QuantumCircuit): | ||
for register in circuit.qregs: | ||
tuples.append(register) | ||
if not tuples: | ||
raise ExtensionError('no qubits for snapshot') | ||
qubits = [] | ||
for tuple_element in tuples: | ||
if isinstance(tuple_element, QuantumRegister): | ||
for j in range(tuple_element.size): | ||
qubits.append(tuple_element[j]) | ||
else: | ||
qubits.append(tuple_element) | ||
|
||
return qubits |
30 changes: 30 additions & 0 deletions
30
qiskit/providers/aer/library/save_instructions/__init__.py
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,30 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2018, 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. | ||
"""Save directive instructions for the Aer simulator""" | ||
|
||
from .save_state import (SaveState, save_state) | ||
from .save_expectation_value import (SaveExpectationValue, | ||
save_expectation_value, | ||
SaveExpectationValueVariance, | ||
save_expectation_value_variance) | ||
from .save_probabilities import (SaveProbabilities, save_probabilities, | ||
SaveProbabilitiesDict, | ||
save_probabilities_dict) | ||
from .save_statevector import (SaveStatevector, save_statevector, | ||
SaveStatevectorDict, save_statevector_dict) | ||
from .save_density_matrix import SaveDensityMatrix, save_density_matrix | ||
from .save_amplitudes import (SaveAmplitudes, save_amplitudes, | ||
SaveAmplitudesSquared, save_amplitudes_squared) | ||
from .save_stabilizer import (SaveStabilizer, save_stabilizer) | ||
from .save_unitary import (SaveUnitary, save_unitary) | ||
from .save_matrix_product_state import ( | ||
SaveMatrixProductState, save_matrix_product_state) |
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
File renamed without changes.
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
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,17 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2018, 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. | ||
"""Set state directive instructions for the Aer simulator""" | ||
|
||
from .set_statevector import SetStatevector, set_statevector | ||
from .set_density_matrix import SetDensityMatrix, set_density_matrix | ||
from .set_unitary import SetUnitary, set_unitary | ||
from .set_stabilizer import SetStabilizer, set_stabilizer |
Oops, something went wrong.