-
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.
Move default_qubits to separate file Move instructions to subfolders Add set instructions to backends
- Loading branch information
1 parent
8bf41d0
commit 587239a
Showing
23 changed files
with
500 additions
and
83 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
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 |
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
# 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) |
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
Oops, something went wrong.