Skip to content

Commit

Permalink
Merge branch 'main' into custom-qpy-serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Mar 11, 2022
2 parents fa6e53a + ec2a2a6 commit b64ffb1
Show file tree
Hide file tree
Showing 66 changed files with 1,686 additions and 588 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ opflow/ @Qiskit/terra-core @manoelmarques @woodsp-ibm @ikkoham
qiskit/utils/ @Qiskit/terra-core @manoelmarques @woodsp-ibm
providers/ @Qiskit/terra-core @jyu00
quantum_info/ @Qiskit/terra-core @ikkoham
qpy/ @Qiskit/terra-core @nkanazawa1989
pulse/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @danpuzzuoli
scheduler/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @danpuzzuoli
visualization/ @Qiskit/terra-core @nonhermitian @nkanazawa1989
Expand Down
22 changes: 18 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ crate-type = ["cdylib"]

[dependencies]
rayon = "1.5"
numpy = "0.16.0"
numpy = "0.16.1"
rand = "0.8"
rand_pcg = "0.3"
rand_distr = "0.4.3"
indexmap = "1.8.0"
ahash = "0.7.6"
num-complex = "0.4"

[dependencies.pyo3]
version = "0.16.1"
features = ["extension-module", "hashbrown"]
features = ["extension-module", "hashbrown", "num-complex"]

[dependencies.ndarray]
version = "^0.15.0"
features = ["rayon"]

[dependencies.hashbrown]
version = "0.12.0"
version = "0.11.2"
features = ["rayon"]

[profile.release]
Expand Down
3 changes: 2 additions & 1 deletion qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
# manually define them on import so people can directly import
# qiskit._accelerate.* submodules and not have to rely on attribute access
sys.modules["qiskit._accelerate.stochastic_swap"] = qiskit._accelerate.stochastic_swap

sys.modules["qiskit._accelerate.pauli_expval"] = qiskit._accelerate.pauli_expval
sys.modules["qiskit._accelerate.dense_layout"] = qiskit._accelerate.dense_layout

# qiskit errors operator
from qiskit.exceptions import QiskitError, MissingOptionalLibraryError
Expand Down
29 changes: 27 additions & 2 deletions qiskit/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2021.
# (C) Copyright IBM 2018, 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
Expand Down Expand Up @@ -47,6 +47,7 @@
:nosignatures:
AmplificationProblem
AmplitudeAmplifier
Grover
GroverResult
Expand Down Expand Up @@ -92,6 +93,22 @@
NumPyEigensolver
Evolvers
--------
Algorithms to evolve quantum states in time. Both real and imaginary time evolution is possible
with algorithms that support them. For machine learning, Quantum Imaginary Time Evolution might be
used to train Quantum Boltzmann Machine Neural Networks for example.
.. autosummary::
:toctree: ../stubs/
:nosignatures:
RealEvolver
ImaginaryEvolver
EvolutionResult
EvolutionProblem
Factorizers
-----------
Expand Down Expand Up @@ -175,8 +192,11 @@
"""

from .algorithm_result import AlgorithmResult
from .evolvers import EvolutionResult, EvolutionProblem
from .evolvers.real.real_evolver import RealEvolver
from .evolvers.imaginary.imaginary_evolver import ImaginaryEvolver
from .variational_algorithm import VariationalAlgorithm, VariationalResult
from .amplitude_amplifiers import Grover, GroverResult, AmplificationProblem
from .amplitude_amplifiers import Grover, GroverResult, AmplificationProblem, AmplitudeAmplifier
from .amplitude_estimators import (
AmplitudeEstimator,
AmplitudeEstimatorResult,
Expand Down Expand Up @@ -215,6 +235,7 @@
"AlgorithmResult",
"VariationalAlgorithm",
"VariationalResult",
"AmplitudeAmplifier",
"AmplificationProblem",
"Grover",
"GroverResult",
Expand All @@ -230,6 +251,10 @@
"MaximumLikelihoodAmplitudeEstimationResult",
"EstimationProblem",
"NumPyEigensolver",
"RealEvolver",
"ImaginaryEvolver",
"EvolutionResult",
"EvolutionProblem",
"LinearSolverResult",
"Eigensolver",
"EigensolverResult",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AmplitudeAmplifier(ABC):
"""The interface for amplification algorithms."""

@abstractmethod
def amplify(self, amplification_problem: AmplificationProblem) -> "AmplificationResult":
def amplify(self, amplification_problem: AmplificationProblem) -> "AmplitudeAmplifierResult":
"""Run the amplification algorithm.
Args:
Expand Down
6 changes: 3 additions & 3 deletions qiskit/algorithms/amplitude_estimators/amplitude_estimator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2020.
# (C) Copyright IBM 2018, 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
Expand All @@ -12,15 +12,15 @@

"""The Amplitude Estimation interface."""

from abc import abstractmethod
from abc import abstractmethod, ABC
from typing import Union, Optional, Dict, Callable, Tuple
import numpy as np

from .estimation_problem import EstimationProblem
from ..algorithm_result import AlgorithmResult


class AmplitudeEstimator:
class AmplitudeEstimator(ABC):
"""The Amplitude Estimation interface."""

@abstractmethod
Expand Down
8 changes: 3 additions & 5 deletions qiskit/algorithms/eigen_solvers/eigen_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
"""The Eigensolver interface"""

from abc import ABC, abstractmethod
from typing import Dict, Optional, List, Union, Tuple, TypeVar
from typing import Optional, List, Tuple

import numpy as np

from qiskit.opflow import OperatorBase
from ..algorithm_result import AlgorithmResult

# Introduced new type to maintain readability.
_T = TypeVar("_T") # Pylint does not allow single character class names.
ListOrDict = Union[List[Optional[_T]], Dict[str, _T]]
from ..list_or_dict import ListOrDict


class Eigensolver(ABC):
Expand Down
3 changes: 2 additions & 1 deletion qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from qiskit.opflow import I, ListOp, OperatorBase, StateFn
from qiskit.utils.validation import validate_min
from ..exceptions import AlgorithmError
from .eigen_solver import Eigensolver, EigensolverResult, ListOrDict
from .eigen_solver import Eigensolver, EigensolverResult
from ..list_or_dict import ListOrDict

logger = logging.getLogger(__name__)

Expand Down
21 changes: 21 additions & 0 deletions qiskit/algorithms/evolvers/__init__.py
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",
]
58 changes: 58 additions & 0 deletions qiskit/algorithms/evolvers/evolution_problem.py
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
40 changes: 40 additions & 0 deletions qiskit/algorithms/evolvers/evolution_result.py
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
Loading

0 comments on commit b64ffb1

Please sign in to comment.