-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into drop-base-backend
- Loading branch information
Showing
34 changed files
with
603 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021, 2022. | ||
# | ||
# 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. | ||
|
||
"""Quantum Time Evolution package.""" | ||
|
||
from .evolution_result import EvolutionResult | ||
from .evolution_problem import EvolutionProblem | ||
|
||
__all__ = [ | ||
"EvolutionResult", | ||
"EvolutionProblem", | ||
] |
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,58 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2022. | ||
# | ||
# 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. | ||
|
||
"""Evolution problem class.""" | ||
|
||
from typing import Union, Optional, Dict | ||
|
||
from qiskit import QuantumCircuit | ||
from qiskit.circuit import Parameter | ||
from qiskit.opflow import OperatorBase, StateFn | ||
from ..list_or_dict import ListOrDict | ||
|
||
|
||
class EvolutionProblem: | ||
"""Evolution problem class. | ||
This class is the input to time evolution algorithms and contains | ||
information on e.g. the total evolution time and under which Hamiltonian | ||
the state is evolved. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
hamiltonian: OperatorBase, | ||
time: float, | ||
initial_state: Union[StateFn, QuantumCircuit], | ||
aux_operators: Optional[ListOrDict[OperatorBase]] = None, | ||
t_param: Optional[Parameter] = None, | ||
hamiltonian_value_dict: Optional[Dict[Parameter, Union[complex]]] = None, | ||
): | ||
""" | ||
Args: | ||
hamiltonian: The Hamiltonian under which to evolve the system. | ||
time: Total time of evolution. | ||
initial_state: Quantum state to be evolved. | ||
aux_operators: Optional list of auxiliary operators to be evaluated with the | ||
evolved ``initial_state`` and their expectation values returned. | ||
t_param: Time parameter in case of a time-dependent Hamiltonian. This | ||
free parameter must be within the ``hamiltonian``. | ||
hamiltonian_value_dict: If the Hamiltonian contains free parameters, this | ||
dictionary maps all these parameters to values. | ||
""" | ||
|
||
self.hamiltonian = hamiltonian | ||
self.time = time | ||
self.initial_state = initial_state | ||
self.aux_operators = aux_operators | ||
self.t_param = t_param | ||
self.hamiltonian_value_dict = hamiltonian_value_dict |
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,40 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021, 2022. | ||
# | ||
# 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. | ||
|
||
"""Class for holding evolution result.""" | ||
|
||
from typing import Optional, Union, Tuple | ||
|
||
from qiskit import QuantumCircuit | ||
from qiskit.algorithms.list_or_dict import ListOrDict | ||
from qiskit.opflow import StateFn | ||
from ..algorithm_result import AlgorithmResult | ||
|
||
|
||
class EvolutionResult(AlgorithmResult): | ||
"""Class for holding evolution result.""" | ||
|
||
def __init__( | ||
self, | ||
evolved_state: Union[StateFn, QuantumCircuit], | ||
aux_ops_evaluated: Optional[ListOrDict[Tuple[complex, complex]]] = None, | ||
): | ||
""" | ||
Args: | ||
evolved_state: An evolved quantum state. | ||
aux_ops_evaluated: Optional list of observables for which expected values on an evolved | ||
state are calculated. These values are in fact tuples formatted as (mean, standard | ||
deviation). | ||
""" | ||
|
||
self.evolved_state = evolved_state | ||
self.aux_ops_evaluated = aux_ops_evaluated |
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,11 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021, 2022. | ||
# | ||
# 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. |
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,37 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021, 2022. | ||
# | ||
# 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. | ||
|
||
"""Interface for Quantum Imaginary Time Evolution.""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
from ..evolution_problem import EvolutionProblem | ||
from ..evolution_result import EvolutionResult | ||
|
||
|
||
class ImaginaryEvolver(ABC): | ||
"""Interface for Quantum Imaginary Time Evolution.""" | ||
|
||
@abstractmethod | ||
def evolve(self, evolution_problem: EvolutionProblem) -> EvolutionResult: | ||
r"""Perform imaginary time evolution :math:`\exp(-\tau H)|\Psi\rangle`. | ||
Evolves an initial state :math:`|\Psi\rangle` for an imaginary time :math:`\tau` | ||
under a Hamiltonian :math:`H`, as provided in the ``evolution_problem``. | ||
Args: | ||
evolution_problem: The definition of the evolution problem. | ||
Returns: | ||
Evolution result which includes an evolved quantum state. | ||
""" | ||
raise NotImplementedError() |
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,11 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021, 2022. | ||
# | ||
# 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. |
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,37 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021, 2022. | ||
# | ||
# 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. | ||
|
||
"""Interface for Quantum Real Time Evolution.""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
from ..evolution_problem import EvolutionProblem | ||
from ..evolution_result import EvolutionResult | ||
|
||
|
||
class RealEvolver(ABC): | ||
"""Interface for Quantum Real Time Evolution.""" | ||
|
||
@abstractmethod | ||
def evolve(self, evolution_problem: EvolutionProblem) -> EvolutionResult: | ||
r"""Perform real time evolution :math:`\exp(-i t H)|\Psi\rangle`. | ||
Evolves an initial state :math:`|\Psi\rangle` for a time :math:`t` | ||
under a Hamiltonian :math:`H`, as provided in the ``evolution_problem``. | ||
Args: | ||
evolution_problem: The definition of the evolution problem. | ||
Returns: | ||
Evolution result which includes an evolved quantum state. | ||
""" | ||
raise NotImplementedError() |
Oops, something went wrong.