Skip to content

Commit

Permalink
Merge remote-tracking branch 'ibm/main' into lazy-import
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Feb 1, 2022
2 parents 3dbbe56 + 497811a commit d7f1502
Show file tree
Hide file tree
Showing 45 changed files with 654 additions and 946 deletions.
51 changes: 51 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 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.

# EditorConfig sets project-wide editor defaults: https://EditorConfig.org

# top-most EditorConfig file, stop looking higher in the tree
root = true

# Default settings can be overidden by editorconfig file in a subdir
# or by a specific glob later in this file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
trim_trailing_whitespace = true

# Python
[*.py]
indent_size = 4

# Javascript
[*.{js,json}]
indent_style = space
indent_size = 2

## Windows files
# [*.bat]
# end_of_line = crlf

# Makefile
[Makefile]
indent_style = tab

# Markdown
[*.md]
# trailing whitespace is used for <br/> in md (yuck)
trim_trailing_whitespace = false

# YAML
[*.{yaml,yml}]
indent_size = 2
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Qiskit is made up of elements that work together to enable quantum computing. Th

## Installation

We encourage installing Qiskit via the pip tool (a python package manager), which installs all Qiskit elements, including Terra.
We encourage installing Qiskit via the pip tool (a python package manager). The following command installs the core Qiskit components, including Terra.

```bash
pip install qiskit
```

PIP will handle all dependencies automatically and you will always install the latest (and well-tested) version.
Pip will handle all dependencies automatically and you will always install the latest (and well-tested) version.

To install from source, follow the instructions in the [documentation](https://qiskit.org/documentation/contributing_to_qiskit.html#install-install-from-source-label).

Expand Down
25 changes: 15 additions & 10 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ stages:
- bash: |
set -e
python -m pip install --upgrade pip
pip install cibuildwheel==2.2.2
pip install cibuildwheel==2.3.1
pip install -U twine
cibuildwheel --output-dir wheelhouse .
- task: PublishBuildArtifacts@1
Expand Down Expand Up @@ -74,7 +74,7 @@ stages:
- bash: |
set -e
python -m pip install --upgrade pip
pip install cibuildwheel==2.2.2
pip install cibuildwheel==2.3.1
pip install -U twine
cibuildwheel --output-dir wheelhouse .
- task: PublishBuildArtifacts@1
Expand All @@ -96,7 +96,7 @@ stages:
- bash: |
set -e
python -m pip install --upgrade pip
pip install cibuildwheel==2.2.2
pip install cibuildwheel==2.3.1
pip install -U twine
cibuildwheel --output-dir wheelhouse .
- task: PublishBuildArtifacts@1
Expand All @@ -107,7 +107,7 @@ stages:
env:
TWINE_PASSWORD: $(TWINE_PASSWORD)
- job: 'Windows'
pool: {vmImage: 'vs2017-win2016'}
pool: {vmImage: 'windows-latest'}
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags')
variables:
TWINE_USERNAME: qiskit
Expand All @@ -123,7 +123,7 @@ stages:
- bash: |
set -e
python -m pip install --upgrade pip
pip install cibuildwheel==2.2.2
pip install cibuildwheel==2.3.1
pip install -U twine
cibuildwheel --output-dir wheelhouse
- task: PublishBuildArtifacts@1
Expand Down Expand Up @@ -182,7 +182,8 @@ stages:
cp -r test /tmp/terra-tests/.
cp .stestr.conf /tmp/terra-tests/.
cp -r .stestr /tmp/terra-tests/. || :
sudo apt install -y graphviz
sudo apt-get update
sudo apt-get install -y graphviz
pip check
displayName: 'Install dependencies'
- bash: |
Expand Down Expand Up @@ -239,7 +240,8 @@ stages:
image_tests/bin/pip install -U -r requirements.txt -c constraints.txt
image_tests/bin/pip install -U -c constraints.txt -e ".[visualization]"
image_tests/bin/python setup.py build_ext --inplace
sudo apt install -y graphviz pandoc
sudo apt-get update
sudo apt-get install -y graphviz pandoc
image_tests/bin/pip check
displayName: 'Install dependencies'
- bash: image_tests/bin/python -m unittest discover -v test/ipynb
Expand Down Expand Up @@ -313,7 +315,8 @@ stages:
python -m pip install --upgrade pip setuptools wheel
pip install -U tox
python setup.py build_ext --inplace
sudo apt install -y graphviz
sudo apt-get update
sudo apt-get install -y graphviz
displayName: 'Install dependencies'
- bash: |
tox -edocs
Expand Down Expand Up @@ -617,7 +620,8 @@ stages:
pip install -U -c constraints.txt -e .
pip install -U "qiskit-aer" "z3-solver" -c constraints.txt
python setup.py build_ext --inplace
sudo apt install -y graphviz
sudo apt-get update
sudo apt-get install -y graphviz
pip check
displayName: 'Install dependencies'
- bash: |
Expand Down Expand Up @@ -768,7 +772,8 @@ stages:
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" "qiskit-aer" "z3-solver" "qiskit-ignis" "matplotlib>=3.3.0" sphinx nbsphinx sphinx_rtd_theme cvxpy -c constraints.txt
python setup.py build_ext --inplace
sudo apt install -y graphviz pandoc
sudo apt-get update
sudo apt-get install -y graphviz pandoc
pip check
displayName: 'Install dependencies'
- bash: |
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ line-length = 100
target-version = ['py36', 'py37', 'py38', 'py39']

[tool.cibuildwheel]
manylinux-x86_64-image = "manylinux2010"
manylinux-i686-image = "manylinux2010"
manylinux-x86_64-image = "manylinux2014"
manylinux-i686-image = "manylinux2014"
skip = "pp* cp36-* *musllinux*"
test-skip = "cp310-win32 cp310-manylinux_i686"
test-command = "python {project}/examples/python/stochastic_swap.py"
# We need to use pre-built versions of Numpy and Scipy in the tests; they have a
# tendency to crash if they're installed from source by `pip install`, and since
# Numpy 1.22 there are no i686 wheels, so we force pip to use older ones without
# restricting any dependencies that Numpy and Scipy might have.
before-test = "pip install --only-binary=numpy,scipy numpy scipy"
5 changes: 1 addition & 4 deletions qiskit/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@
:toctree: ../stubs/
:nosignatures:
HHL
NumPyLinearSolver
LinearSolver
LinearSolverResult
linear_solvers
Minimum Eigensolvers
Expand Down
77 changes: 75 additions & 2 deletions qiskit/algorithms/linear_solvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,83 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Linear solvers."""
"""
Linear solvers (:mod:`qiskit.algorithms.linear_solvers`)
=========================================================
It contains classical and quantum algorithms to solve systems of linear equations such as
:class:`~qiskit.algorithms.HHL`.
Although the quantum algorithm accepts a general Hermitian matrix as input, Qiskit's default
Hamiltonian evolution is exponential in such cases and therefore the quantum linear solver will
not achieve an exponential speedup.
Furthermore, the quantum algorithm can find a solution exponentially faster in the size of the
system than their classical counterparts (i.e. logarithmic complexity instead of polynomial),
meaning that reading the full solution vector would kill such speedup (since this would take
linear time in the size of the system).
Therefore, to achieve an exponential speedup we can only compute functions from the solution
vector (the so called observables) to learn information about the solution.
Known efficient implementations of Hamiltonian evolutions or observables are contained in the
following subfolders:
`Matrices`_
A placeholder for efficient implementations of the Hamiltonian evolution of particular types of
matrices.
`Observables`_
A placeholder for efficient implementations of functions that can be computed from the solution
vector to a system of linear equations.
.. currentmodule:: qiskit.algorithms.linear_solvers
Linear Solvers
==============
.. autosummary::
:toctree: ../stubs/
:nosignatures:
LinearSolver
LinearSolverResult
HHL
NumPyLinearSolver
Matrices
========
.. autosummary::
:toctree: ../stubs/
:nosignatures:
LinearSystemMatrix
NumPyMatrix
TridiagonalToeplitz
Observables
===========
.. autosummary::
:toctree: ../stubs/
LinearSystemObservable
AbsoluteAverage
MatrixFunctional
"""

from .hhl import HHL
from .numpy_linear_solver import NumPyLinearSolver
from .linear_solver import LinearSolver, LinearSolverResult
from .matrices import LinearSystemMatrix, NumPyMatrix, TridiagonalToeplitz
from .observables import LinearSystemObservable, AbsoluteAverage, MatrixFunctional

__all__ = ["HHL", "NumPyLinearSolver", "LinearSolver", "LinearSolverResult"]
__all__ = [
"HHL",
"NumPyLinearSolver",
"LinearSolver",
"LinearSolverResult",
"LinearSystemMatrix",
"NumPyMatrix",
"TridiagonalToeplitz",
"LinearSystemObservable",
"AbsoluteAverage",
"MatrixFunctional",
]
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class AbsoluteAverage(LinearSystemObservable):
import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms.linear_solvers.observables.absolute_average import
AbsoluteAverage
from qiskit.algorithms.linear_solvers.observables.absolute_average import \
AbsoluteAverage
from qiskit.opflow import StateFn
observable = AbsoluteAverage()
vector = [1.0, -2.1, 3.2, -4.3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class MatrixFunctional(LinearSystemObservable):
import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms.linear_solvers.observables.matrix_functional import
MatrixFunctional
from qiskit.algorithms.linear_solvers.observables.matrix_functional import \
MatrixFunctional
from qiskit.transpiler.passes import RemoveResetInZeroState
from qiskit.opflow import StateFn
tpass = RemoveResetInZeroState()
Expand Down
17 changes: 0 additions & 17 deletions qiskit/circuit/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,6 @@
PauliEvolutionGate
Probability distributions
=========================
.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
UniformDistribution
NormalDistribution
LogNormalDistribution
N-local circuits
================
Expand Down Expand Up @@ -426,11 +414,6 @@
QAOAAnsatz,
)
from .data_preparation import PauliFeatureMap, ZFeatureMap, ZZFeatureMap
from .probability_distributions import (
LogNormalDistribution,
NormalDistribution,
UniformDistribution,
)
from .quantum_volume import QuantumVolume
from .fourier_checking import FourierChecking
from .graph_state import GraphState
Expand Down
23 changes: 21 additions & 2 deletions qiskit/circuit/library/basis_change/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""Quantum Fourier Transform Circuit."""

from typing import Optional
import warnings
import numpy as np

from qiskit.circuit import QuantumCircuit, QuantumRegister
Expand Down Expand Up @@ -229,14 +230,30 @@ def inverse(self) -> "QFT":
inverted._inverse = not self._inverse
return inverted

def _warn_if_precision_loss(self):
"""Issue a warning if constructing the circuit will lose precision.
If we need an angle smaller than ``pi * 2**-1022``, we start to lose precision by going into
the subnormal numbers. We won't lose _all_ precision until an exponent of about 1075, but
beyond 1022 we're using fractional bits to represent leading zeros."""
max_num_entanglements = self.num_qubits - self.approximation_degree - 1
if max_num_entanglements > -np.finfo(float).minexp: # > 1022 for doubles.
warnings.warn(
"precision loss in QFT."
f" The rotation needed to represent {max_num_entanglements} entanglements"
" is smaller than the smallest normal floating-point number.",
category=RuntimeWarning,
stacklevel=3,
)

def _check_configuration(self, raise_on_failure: bool = True) -> bool:
"""Check if the current configuration is valid."""
valid = True
if self.num_qubits is None:
valid = False
if raise_on_failure:
raise AttributeError("The number of qubits has not been set.")

self._warn_if_precision_loss()
return valid

def _build(self) -> None:
Expand All @@ -256,7 +273,9 @@ def _build(self) -> None:
circuit.h(j)
num_entanglements = max(0, j - max(0, self.approximation_degree - (num_qubits - j - 1)))
for k in reversed(range(j - num_entanglements, j)):
lam = np.pi / (2 ** (j - k))
# Use negative exponents so that the angle safely underflows to zero, rather than
# using a temporary variable that overflows to infinity in the worst case.
lam = np.pi * (2.0 ** (k - j))
circuit.cp(lam, j, k)

if self.insert_barriers:
Expand Down
Loading

0 comments on commit d7f1502

Please sign in to comment.