Commit Graph

146 Commits

Author SHA1 Message Date
Jake Lishman c6cd0d577b
Add structure for multiple Rust crates (#9742)
* Add structure for multiplie Rust extension crates

This is a precursor to adding an entirely separate and self-contained
crate to handle parsing of OpenQASM 2 (not 3 - this is kind of like a
trial run for that).  It could conceivably still live within
`qiskit._accelerate`, but having separate crates helps us enforce more
sane API barriers, and has improvements in the incremental build time
when working on only one of the Rust extensions.

The intent after this commit is still to have `qiskit._accelerate` as an
easy catch-all for accelerators for Python.  Developers should not need
to be concerned with defining a new crate for every new feature, and for
the most part `_accelerate` is still logically interoperative within
itself (for example, `NLayout` is used all over).  This is just laying
out the groundwork so more complex crate additions _can_ also be made.

Some of the niceties to do with Cargo workspaces only became stabilised
in Rust 1.64.  In particular, inheritance from the workspace root for
things like the package version, Rust version, and dependencies only
came in then.  For now, the `workspace.packages` key in the root
`Cargo.toml` is ignored with a small warning during the build, but I've
put it in place mostly to keep track of what we can change once the MSRV
becomes 1.64 or greater (likely not til at least Terra 0.26).

* Add README.md to crates/accelerate

* Correct licence metadata
2023-03-07 23:12:39 +00:00
Matthew Treinish 756bb11e1e
Bump main branch version post 0.23.0rc1 tag (#9396)
* Bump main branch version post 0.23.0rc1 tag

Now that the first release candidate for the 0.23.0 release has been
tagged, the stable branch for the 0.23 series has been created and we
can start developing the 0.24.0 release on main. This commit bumps all
the version strings from 0.23.0 to 0.24.0 (and the backport branch for
mergify to 0.23) accordingly to differentiate the main branch from
0.23.*.

* Bump version number in cargo lock file too

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2023-01-20 14:18:44 +00:00
Matthew Treinish c0961b9247
Set version number to 0.23.0rc1 for first release candidate (#9395)
For the 0.23.0 release we're going to push release candidates
prior to the release to enable testing before we cut the final release.
In preparation for tagging the first release candidate this commit
updates the version string to indicate it's a release candidate. This
commit should be what gets tagged as 0.23.0rc1.
2023-01-19 22:12:48 +00:00
Jake Lishman b2311c4c3d
Add importer for OpenQASM 3 (#9347)
* Add importer for OpenQASM 3

This adds an interface for importing OpenQASM 3 into Qiskit Terra.
Right now, this is provided only as an optional dependency (the
`qasm3-import` optional), using the package `qiskit_qasm3_import`, which
in turn depends on the ANTLR runtime `antlr4-python3-runtime`.

The importer code may in the future be vendored into Terra, and will
likely be replaced completely by a more efficient importer in the
future, once a more concrete strategy has been decided for handling of
classical components in quantum programs.

* Expand capabilities section of release note

* Expand OQ3 import documentation

* Relax exact pin in optional requirement

* Remove superfluous word

* Update link to Qiskit org

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2023-01-19 19:42:20 +00:00
Alexander Ivrii 179c29cdf6
High-level-synthesis for permutations (#9157)
* Adding permutation synthesis algorithm for LNN

* release notes

* Checking that the synthesized permutation adheres to the LNN connectivity and has depth guaranteed by the algorithm

* Adding tests for 15 qubits

Co-authored-by: Nir Gavrielov <nirgavrielov@gmail.com>

* Changing Permutation to be a Gate rather than QuantumCircuit

* Adding the property pattern to Permutation class

* fixing assert

* improving description message for _get_ordered_swap

* applying suggestions from code review

* minor

* attempt to fix docstring

* Another attempt to fix docsting

* another attempt to fix docstring

* temporarily simplifying docstring to see if this passes docs build

* adding blank line

* another attempt

* Restoring docstring

* removing extra line

* adding __array__ method for permutation + tests

* HLS permutation plugin based on the original synthesis algorithm for permutations

* speeding up _get_ordered_swap based on review comments

* Adding depth-2 synthesis algorithm for permutations for all-to-all connectivity; including tests and plugin

* release notes

* Adding example to release notes

* Update documentation of Permutation

* add missing import

* drawing decomposed circuit with permutations

* forgot parenthesis

* restoring qasm for circuits containing Permutations

* Adding permutation method to QuantumCircuit

* Adding test for quantum circuit with permutations

* pylint

* adding inverse() method to permutations

* qpy support for permutations

* tests for quantum circuits with permutations

* checking depth bound on the ACG method

* Adding tests for new Permutation functionality

* black

* Following review, keeping the old Permutation quantum circuit for backward compatibility, and naming the new permutation gate class as PermutationGate

* additional fixes

* updating release notes

* docs fix

* Removing permutation method from QuantumCircuit

* Adding QPY test for circuits with permutation gates

* Update qiskit/circuit/quantumcircuit.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Set default qasm name override to None

Co-authored-by: Nir Gavrielov <nirgavrielov@gmail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2023-01-19 17:38:44 +00:00
LNoorl 9c1c18cea4
Add the Solovay-Kitaev algorithm to the transpiler passes (#5657)
* add sk pass

* add utils

* add sk skeleton

* add example test file

* Add implementations initial version

* make the test run

* fix lint

* fix phase, add test

* fix the phase calculation

* add accuracy test

* cleanup of unused methods, append more efficient

* Add unittests for Solovay Kitaev Utils

* Add unitttests for commutator_decompose

* Remove unittests for non-public functions

* Fix pylint issues

* refactor simplify

* fix the test imports

* improve and add docstrings

* fix lint in testfile

* fix lint in utils

* fix lint in sk

* Add unittests

* fix phase, lint and allow basis gates as strings

* rm print

* fix adjoint and dot

* Fix unittests and add docstring to them

* move to circuit to GateSequence

* Fix assertion

* allow caching the basic approxs

* Fix bug in append from GateSequence

* Remove unnecesssary code

* Fix bug in test setup

* Add unittests for multiqubit QFT-circuit

* Add unittests for QFT with more qubits

* make compatible with current tests

* Remove unnecessary testcases

* Remove unnecessary unittests

* Fix bug in unittests

* Add release notes

* import scipy; scipy.optimize.fsolve() does not work

scipy.optimize has to be imported, since it is not imported when scipy is imported

* numpy

* Update qiskit/transpiler/passes/synthesis/solovay_kitaev_utils.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* document ValueError

* rm unused methods, add GateSequence tests

* fix lint

* try fixing lint and docs

* cleanup

* improve readability of math
* move commutator_decompose into utils
* rm tests that are never run
* rm trailing todos and commented code

* add default dataset, cleanup tests

* rm unused imports

* replace diamond norm by trace distance

* rm unused imports

* fix deprecated use of DAGNode.type

* black

* really black!

* fail nicely

* test

* attempt to fix default approx path

* Move decompositions into py file dict

* speed up the basic approx generation

* add candidate checking by string

further reduces the runtime by a factor of about 1.8!

* use a tree for basic approx generation

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* fix tests

* more speedups!

* use kdtree!

* refactor: generation as sep. function

* remove this masssssive file!

* start plugin work

* first attempt at synthesis plugin

* plugin itself works

-- but not when called via transpile or the UnitarySynthesis

* unitary synth works!

* use class-level method for SolovayKitaev

* docstrings

* add tests which cover still missing feature

* rename to SKSynth and better reno

* re-organize files

- algorithm to qiskit.synthesis
- plugin to qiskit.transpiler.passes.synthesis

* cover sklearn-free case

* missing future import

* move sk pass to transpiler subdirectory

* reno & try fixing slow optional module-level imports

* attempt 2 to fix sklearn import

* comments from Matthew's review

* directly construct dag

* (previous commit incomplete: missed this here)

* add SK to plugin toctree

* try fixing sphinx

* Apply Jake's comments

Removed the SK plugin from the plugin.py docs for now

* Fix doc example

* Update docs

* Fix tests

* Fix docs error

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2022-12-09 22:04:59 +00:00
Matthew Treinish 75d66dd8ba
Add support for Python 3.11 (#9028)
* Add support for Python 3.11

Python 3.11.0 was released on 10-24-2022, this commit marks the start of
support for Python 3.11 in qiskit. It adds the supported Python version in
the package metadata and updates the CI configuration to run test jobs
on Python 3.11 and build Python 3.11 wheels on release.

* Fix inspect.Parameter usage for API change in 3.11

Per the Python 3.11.0 release notes inspect.Parameter now raises a
ValueError if the name argument is a Python identifier. This was causing a
test failure in one case where a parameter named `lambda` was used.
This commit adjusts the parameter name in the tests to be lam to avoid
this issue.

* Set a version cap on the jax dev requirement

Currently jax doesn't publish Python 3.11 wheels which is blocking test
runs with python 3.11. Since jax is an optional package only used for
the gradient package we can just skip it as isn't a full blocker for
using python 3.11. This commit sets an environment marker on the jax
dev requirements to only try to install it on Python < 3.11.

* Set python version cap on cplex in CI

* DNM: Test wheel builds work

* Skip tests on i686/win32 wheel buids with python 3.11

* Revert "DNM: Test wheel builds work"

This reverts commit 725c21b465.

* Run QPY backwards compat tests on trailing edge Python version

This commit moves the qpy backwards compatibility testing from the
leading edge python version, which in this PR branch is Python 3.11, to
the trailing edge Python version which is currently 3.7. Trying to add
support for a new Python version has demonstrated that we can't use the
leading edge version as historical versions of Qiskit used to generate
old QPY payloads are not going to be generally installable with newer
Python versions. So by using the trailing edge version instead we can
install all the older versions of Qiskit as there is Python
compatibility for those Qiskit versions. Eventually we will need to
raise the minimum Qiskit version we use in the QPY tests, when Python
3.9 goes EoL in October 2025 and Qiskit Terra 0.18.0 no longer has any
supported versions of Python it was released for. We probably could
get by another year until Python 3.10 goes EoL in 2026 it just means
we're building 0.18.x and 0.19.x from source for the testing, but when
Python 3.11 becomes our oldest supported version we'll likely have to
bump the minimum version.

This does go a bit counter to the intent of the test matrix to make the
first stage return fast and do a more through check in the second stage.
But, in this case the extra runtime is worth the longer term stability
in the tests.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-11-03 16:58:14 +00:00
Kevin Hartman d56ef8c49c
Use TOQM routing staged pass manager. (#9042)
* Update toqm requirements-dev version.

* Remove toqm special casing.

* Remove unused imports from preset pass managers.

* Add release note.

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-11-01 20:16:43 +00:00
Matthew Treinish af82b4d0e1
Bump main branch version post rc tag (#8850)
* Bump main branch version post rc tag

Now that the first release candidate for the 0.22.0 release has been
tagged, the stable branch for the 0.22 series has been created and we
can start developing the 0.23.0 release on main. This commit bumps all
the version strings from 0.22.0 to 0.23.0 (and the backport branch for
mergify to 0.22) accordingly to differentiate the main branch from
0.22.*.

* Move release notes to dedicated directory too

* Update Cargo too

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-10-07 15:44:33 -04:00
Matthew Treinish ae72c09680
Set version number to 0.22.0rc1 for first release candidate (#8798)
For the 0.22.0 release we're going to push release candidates
prior to the release to enable testing before we cut the final release.
In preparation for tagging the first release candidate this commit
updates the version string to indicate it's a release candidate. This
commit should be what gets tagged as 0.22.0rc1.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-07 16:23:58 +00:00
Alexander Ivrii 389203c929
Implementing pluggable HighLevelSynthesis (#8548)
* Initial implementation of pluggable HighLevelSynthesis

* typo

* black

* fix merge error

* Reorganizing entry points for high-level-synthesis plugins based on the comments

* fixing some typos

* HLSConfig now accepts a list of methods for each operation; also allowing to specify these lists in config's __init__

* running black

* removing hls_config from __str__ in PassManagerConfig

* Adding abc interface for high-level-synthesis plugins

* improving docs and comments

* fix

* adding tests; removing print statements

* removing external test file

* remove redundant print

* Passing HLSConfig in all transpiler optimization levels

* Fix for is_parameterized as Operations don't have to support this

* Replacing node.op.copy by copy.deepcopy(node.op) to avoid Operations implementing copy method

* release notes

* adding a link to HLSConfig class

* Temporarily removing high-level-synthesis from optimization loop

* Adding example from release notes to HighLevelSynthesis documentation

* fixing random typo

* adding references to documentation:

* Further trying to improve documentation following the review comments

* removing usused import

* minor docs changes

* Docs consolidation following review comments

* added test

* fixing title underline in docs

* minor output tweaks

* Update setup.py

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-30 20:08:21 +00:00
Matthew Treinish cef0a8cc43
Add stage plugin interface for transpile (#8305)
* Add stage plugin interface for transpile

This commit adds a new plugin interface to qiskit for enabling external
packages to write plugins that will replace a stage in the transpilation
pipeline. For example, if an external package had a custom layout pass
that they wanted to integrate into transpile() they could export a
plugin using this new interface and then users would just need to run

transpile(.., layout_method=foo)

This adds long asked for extensibility to the transpiler so that to
cleanly integrate new transpiler passes we're no longer required to
merge the features into terra. This should hopefully make it easier for
downstream pass authors to integrate their passes into terra and make it
easier for the terra maintainers to evaluate new transpiler passes.

* Fix docs builds

* Fix doc warning

* Make routing methods all plugins

This commit converts all the built-in routing method options into
separate plugins and also adds a default plugin for the default behavior
at each optimization level. To support using plugins for routing method
adding the optimization_level to the passmanager config was necessary so
that the plugin has sufficient context on how to construct the routing
pass used for the routing stage. As depending on the optimization level
the settings for each pass differs. For example on stochastic swap the
number of stochastic trials increases for level 3 to try and find a
better solution at the cost of more runtime.

* Add plugin usage to level 3

* Add plugin support to level 0 preset pass manager

* Add default plugin to reserved routing methods list

* Add release notes

* Add tests

* Apply suggestions from code review

Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>

* Apply suggestions from code review

Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>

* Remove raise on non-builtin layout method argument

* Fix typo

* Deduplicate code in built-in routing plugins

This commit deduplicates the code in the built-in routing stage plugins.
First it removes the default plugin which was duplicated with the
stochastic and sabre plugins. There was no functional difference between
just setting the implicit default method name and using a per method
plugin and having a standalone default plugin. Secondly all the vf2 call
limit code is abstracted into a helper function which reduces code
duplication.

* Make vf2 call limit function private

* Deduplicate code in stochastic swap plugin

* Expand example plugin documentation to show more complete use case

* Update qiskit/transpiler/preset_passmanagers/level1.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Add missing TODO comment

* Unify vf2 call limit handling

* Remove default plugin from entry points

* Simplify level 3 optimization stage logic

* Update qiskit/transpiler/preset_passmanagers/plugin.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Prefer toqm plugin if one is available

The qiskit-toqm project will be one of the first users of this plugin
interface. Once this is released in qiskit, qiskit-toqm will likely
publish their own plugin soon after and if they do we want that plugin
to be used instead of the hardcoded stage in terra. This commit updates
the logic for toqm handling to only use the built-in toqm if a version
of qiskit-toqm is installed without a plugin present.

* Apply suggestions from code review

Co-authored-by: Kevin Hartman <kevin@hart.mn>
Co-authored-by: Toshinari Itoko <15028342+itoko@users.noreply.github.com>

* Fix lint

* Remove unnecessary elses in builtin plugins

* Apply suggestions from code review

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Make optimization level a plugin argument

* Add test coverage for all built-in routing plugins

* Reorder stage variables to execution order

Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Kevin Hartman <kevin@hart.mn>
Co-authored-by: Toshinari Itoko <15028342+itoko@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-30 18:16:51 +00:00
Matthew Treinish 57540c1697
Bump version strings post pre-release (#8228)
* Bump version strings post pre-release

Now that qiskit-terra 0.21.0rc0 is out the door we should bump the version
string on main to show the source version we're installing is newer
than what's been pre-released.

* Move 0.21 release notes into a separate directory

* Update cargo.toml too
2022-06-23 17:16:28 -04:00
Matthew Treinish 5a6ec94699
Set version number to 0.21.0rc1 for first release candidate (#8200)
* Set version number to 0.21.0rc1 for first release candidate

For the 0.21.0 release we're going to start pushing release candidates
prior to the release to enable testing before we cut the final release.
In preparation for tagging the first release candidate this commit
updates the version string to indicate it's a release candidate.

* Update cargo version to reflect 0.21.0

* Fix qpy handling of prerelease tags

* Fix pre-release handling in qpy compat tests

* Inline version parsing in qpy compat test

* Fix qpy version handling
2022-06-22 16:52:11 +00:00
Kevin Hartman a0b9a846f9
Integrate `qiskit-toqm` as an optional package for layout and routing. (#7825)
* Integrate qiskit-toqm as an optional layout and routing pass.

* Run formatting.

* Add release note.

* S

* Exclude Linux aarch64 for qiskit-toqm in requirements-dev.txt.

This is currently necessary since Qiskit TOQM isn't published to PyPI
for Linux aarch64 due to a bug.

* qiskit-toqm performs layout changes always.

...when configured using one of its optimization strategies. This is because
non-optimal configurations (i.e. anything using GreedyMapper under the
hood) aren't compatible with the layout search parameter, and in fact
break when it is provided. These configurations happen to always perform
layout (without the explicit search) through a different means. To make
everything consistent, it should be assumed that no matter which optimization
strategy is used, layout changes will be made via routing.

qiskit-toqm users can still create a custom strategy if they wish to use
an optimal configuration that does not make layout changes, and then
use their own pass manager.

* Add basic testing for TOQM integration.

* Update to use qiskit-toqm 0.0.3 API.

* Add testing of 5 qubit device.

This exercises the optimal mapper code paths of qiskit-toqm
opt levels.

* Update for target awareness.

* Add extra to setup.py for toqm.

* Bump requirement-dev.txt TOQM version.
2022-06-14 19:11:06 -04:00
Matthew Treinish e508729400
Make python-constraint optional (#7733)
* Make python-constraint optional

Since #7213 we no longer have been using the CSPLayout pass by default
in the preset passmanagers or transpile(). This is because it has been
superseded by the VF2Layout pass which is now used everywhere. While we
will keep the CSPLayout pass around for the forseeable future there is
no need to install python-constraint by default anymore since it's only
user is the CSPLayout pass, which isn't going to be commonly used
anymore now that it's not used in the default compilation path anymore.
This commit removes the python-constraint library from the requirements
list and makes it an optional dependency.

Fixes #7726

* Add docstring for HAS_CONSTRAINT

* Add private module to avoid module level optional import

This commit splits the custom solver class definition out into a
separate private module that is not imported until runtime. This enables
us to avoid a module level import for python-constraint meaning we only
try to import if something is actually using CSPLayout.

* Fix rebase issue

* Fix lint

* Fix typo in release note

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>

* Alphabetize optionals list

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
2022-05-26 19:20:51 +00:00
Matthew Treinish 7c50a17ee2
Bump version strings post release (#7852)
Now that qiskit-terra 0.20.0 is out the door we should bump the version
string on main to show the source version we're installing is newer
than what's been released.
2022-03-31 23:21:46 +00:00
Jake Lishman 9d671e53b4
Add dummy extra for `CSPLayout` (#7842)
* Add dummy extra for `CSPLayout`

This currently has no effect, but since we no longer use `CSPLayout` in
the preset pass managers, we are moving to demote its dependency
`python-constraint` from a requirement to an optional.  This is the
preliminary step of the process, which allows packages to depend on
`qiskit-terra[csp-layout-pass]` before we actually make the switch.

* Add redundant requirement rather than TODO

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-03-30 19:54:17 +00:00
Matthew Treinish e5721e9133
Replace pauli expectation value cython with multithreaded rust implementation (#7702)
* Replace pauli expectation value cython with rust implementation

This commit replaces the cython implementation of the pauli expectation
value functions with a multithreaded rust implementation. This was done
primarily for two reasons, the first and primary reason for this change
is because after #7658 this module was the only cython code left in the
qiskit-terra repository so unifying on a single compiled language will
reduce the maintanence burden in qiskit-terra. The second reason is
similar to the rationale in #7658 around why using rust over cython for
multi-threaded hybrid python module. The difference here though is
unlike in stochastic swap this module isn't as performance critical as
it's not nearly as widely used.

* Tune single threaded performance for rust sum

This commit tunes the sum for the single threaded path. Using the
iterator sum() method is very convienent but for the single threaded
path it doesn't create the most efficient output. This was causing a
regression in performance over the previous cython version. To address
that issue, this commit adds a new tuned function which does a chunked
sum which the compiler can handle better. It more closely models how
we'd do this with vectorized SIMD instructions. As a future step we can
look at using simdeez https://github.com/jackmott/simdeez
to further optimize this by doing runtime CPU feature detection and
leveraging SIMD instrinsics (we might want to look at using `fast_sum()`
in the multithreaded path if we do that too).

* Add release notes

* Fix lint

* Add docstring and signature to rust functions

* Define parallel threshold as a constant

* Add attribution comment to fast_sum()

* Rename eval_parallel_env -> getenv_use_multiple_threads

* Use inline literal type for size

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Add overflow check on num_qubits

The functions only work for at most for number of qubits < usize bits
anything larger would cause an overflow. While rust provides overflow
checking in debug mode it disables this for performance in release mode.
Sice we ship binaries in release mode this commit adds an overflow check
for the num_qubits argument to ensure that we don't overflow and produce
incorrect results.

* Remove unecessary setup_requires field from setup.py

The setup_requires field in the setup.py is deprecated and
has been superseded by the pyproject.toml to define build
system dependencies. Since we're already relying on the
pyproject.toml to install setuptools-rust for us having the
setup_requires line will do nothing but potentially cause
issues as it will use an older install mechanism that will potentially conflict with  people's environments.

* Drop `.iter().take(LANES)`.

* Fix typo.

Co-authored-by: Kevin Hartman <kevin@hart.mn>
2022-03-10 20:54:24 +00:00
Matthew Treinish ccc371f8ff
Implement multithreaded stochastic swap in rust (#7658)
* Implement multithreaded stochastic swap in rust

This commit is a rewrite of the core swap trials functionality in the
StochasticSwap transpiler pass. Previously this core routine was written
using Cython (see #1789) which had great performance, but that
implementation was single threaded. The core of the stochastic swap
algorithm by it's nature is well suited to be executed in parallel, it
attempts a number of random trials and then picks the best result
from all the trials and uses that for that layer. These trials can
easily be run in parallel as there is no data dependency between the
trials (there are shared inputs but read-only). As the algorithm
generally scales exponentially the speed up from running the trials in
parallel can offset this and improve the scaling of the pass. Running
the pass in parallel was previously tried in #4781 using Python
multiprocessing but the overhead of launching an additional process and
serializing the input arrays for each trial was significantly larger
than the speed gains. To run the algorithm efficiently in parallel
multithreading is needed to leverage shared memory on shared inputs.

This commit rewrites the cython routine using rust. This was done for
two reasons. The first is that rust's safety guarantees make dealing
with and writing parallel code much easier and safer. It's also
multiplatform because the rust language supports native threading
primatives in language. The second is while writing parallel cython
code using open-mp there are limitations with it, mainly on windows. In
practice it was also difficult to write and maintain parallel cython
code as it has very strict requirements on python and c code
interactions. It was much faster and easier to port it to rust and the
performance for each iteration (outside of parallelism) is the same (in
some cases marginally faster) in rust. The implementation here reuses
the data structures that the previous cython implementation introduced
(mainly flattening all the terra objects into 1d or 2d numpy arrays for
efficient access from C).

The speedups from this PR can be significant, calling transpile() on a
400 qubit (with a depth of 10) QV model circuit targetting a 409 heavy
hex coupling map goes from ~200 seconds with the single threaded cython
to ~60 seconds with this PR locally on a 32 core system, When transpiling
a 1000 qubit (also with a depth of 10) QV model circuit targetting a 1081
qubit heavy hex coupling map goes from taking ~6500 seconds to ~720
seconds.

The tradeoff with this PR is for local qiskit-terra development a rust
compiler needs to be installed. This is made trivial using rustup
(https://rustup.rs/), but it is an additional burden and one that we
might not want to make. If so we can look at turning this PR into a
separate repository/package that qiskit-terra can depend on. The
tradeoff here is that we'll be adding friction to the api boundary
between the pass and the core swap trials interface. But, it does ease
the dependency on development for qiskit-terra.

* Sanitize packaging to support future modules

This commit fixes how we package the compiled rust module in
qiskit-terra. As a single rust project only gives us a single compiled
binary output we can't use the same scheme we did previously with cython
with a separate dynamic lib file for each module. This shifts us to
making the rust code build a `qiskit._accelerate` module and in that we
have submodules for everything we need from compiled code. For this PR
there is only one submodule, `stochastic_swap`, so for example the
parallel swap_trials routine can be imported from
`qiskit._accelerate.stochastic_swap.swap_trials`. In the future we can
have additional submodules for other pieces of compiled code in qiskit.
For example, the likely next candidate is the pauli expectation value
cython module, which we'll likely port to rust and also make parallel
(for sufficiently large number of qubits). In that case we'd add a new
submodule for that functionality.

* Adjust random normal distribution to use correct mean

This commit corrects the use of the normal distribution to have the mean
set to 1.0. Previously we were doing this out of band for each value by
adding 1 to the random value which wasn't necessary because we could
just generate it with a mean of 1.0.

* Remove unecessary extra scope from locked read

This commit removes an unecessary extra scope around the locked read for
where we store the best solution. The scope was previously there to
release the lock after we check if there is a solution or not. However
this wasn't actually needed as we can just do the check inline and the
lock will release after the condition block.

* Remove unecessary explicit type from opt_edges variable

* Fix indices typo in NLayout constructor

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Remove explicit lifetime annotation from swap_trials

Previously the swap_trials() function had an explicit lifetime
annotation `'p` which wasn't necessary because the compiler can
determine this on it's own. Normally when dealing with numpy views and a
Python object (i.e. a GIL handle) we need a lifetime annotation to tell
the rust compiler the numpy view and the python gil handle will have the
same lifetime. But since swap_trials doesn't take a gil handle and
operates purely in rust we don't need this lifetime and the rust
compiler can deal with the lifetime of the numpy views on their own.

* Use sum() instead of fold()

* Fix lint and add rust style and lint checks to CI

This commit fixes the python lint failures and also updates the ci
configuration for the lint job to also run rust's style and lint
enforcement.

* Fix returned layout mapping from NLayout

This commit fixes the output list from the `layout_mapping()`
method of `NLayout`. Previously, it incorrectly would return the
wrong indices it should be a list of virtual -> physical to
qubit pairs. This commit corrects this error

Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>

* Tweak tox configuration to try and reliably build rust extension

* Make swap_trials parallelization configurable

This commit makes the parallelization of the swap_trials() configurable.
This is dones in two ways, first a new argument parallel_threshold is
added which takes an optional int which is the number of qubits to
switch between a parallel and serial version. The second is that it
takes into account the the state of the QISKIT_IN_PARALLEL environment
variable. This variable is set to TRUE by parallel_map() when we're
running in a multiprocessing context. In those cases also running
stochastic swap in parallel will likely just cause too much load as
we're potentially oversubscribing work to the number of available CPUs.
So, if QISKIT_IN_PARALLEL is set to True we run swap_trials serially.

* Revert "Make swap_trials parallelization configurable"

This reverts commit 57790c84b0. That
commit attempted to sovle some issues in test running, mainly around
multiple parallel dispatch causing exceess load. But in practice it was
broken and caused more issues than it fixed. We'll investigate and add
control for the parallelization in a future commit separately after all
the tests are passing so we have a good baseline.

* Add docs to swap_trials() and remove unecessary num_gates arg

* Fix race condition leading to non-deterministic behavior

Previously, in the case of circuits that had multiple best possible
depth == 1 solutions for a layer, there was a race condition in the fast
exit path between the threads which could lead to a non-deterministic
result even with a fixed seed. The output was always valid, but which
result was dependent on which parallel thread with an ideal solution
finished last and wrote to the locked best result last. This was causing
weird non-deterministic test failures for some tests because of #1794 as
the exact match result would change between runs. This could be a bigger
issue because user expectations are that with a fixed seed set on the
transpiler that the output circuit will be deterministically
reproducible.

To address this is issue this commit trades off some performance to
ensure we're always returning a deterministic result in this case. This
is accomplished by updating/checking if a depth==1 solution has been
found in another trial thread we only act (so either exit early or
update the already found depth == 1 solution) if that solution already
found has a trial number that is less than this thread's trial number.
This does limit the effectiveness of the fast exit, but in practice it
should hopefully not effect the speed too much.

As part of this commit some tests are updated because the new
deterministic behavior is slightly different from the previous results
from the cython serial implementation. I manually verified that the
new output circuits are still valid (it also looks like the quality
of the results in some of those cases improved, but this is strictly
anecdotal and shouldn't be taken as a general trend with this PR).

* Apply suggestions from code review

Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>

* Fix compiler errors in previous commit

* Revert accidental commit of parallel reduction in compute_cost

This was only a for local testing to prove it was a bad idea and was
accidently included in the branch. We should not nest the parallel
execution like this.

* Eliminate short circuit for depth == 1 swap_trial() result

This commit eliminates the short circuit fast return in swap_trial()
when another trial thread has found an ideal solution. Trying to do this
in a parallel context is tricky to make deterministic because in cases
of >1 depth == 1 solutions there is an inherent race condition between
the threads for writing out their depth == 1 result to the shared
location. Different strategies were tried to make this reliably
deterministic but there wa still a race condition. Since this was just a
performance optimization to avoid doing unnecessary work this commit
removes this step. Weighing improved performance against repeatability
in the output of the compiler, the reproducible results are more
important. After we've adopted a multithreaded stochastic swap we can
investigate adding this back as a potential future optimization.

* Add missing docstrings

* Add section to contributing on installing form source

* Make rust python classes pickleable

* Add rust compiler install to linux wheel jobs

* Try more tox changes to fix docs builds

* Revert "Eliminate short circuit for depth == 1 swap_trial() result"

This reverts commit c510764a77. The
removal there was premature and we had a fix for the non-determinism in
place, ignoring a typo which was preventing it from working.

Co-Authored-By: Georgios Tsilimigkounakis <45130028+georgios-ts@users.noreply.github.com>

* Fix submodule declaration and module attribute on rust classes

* Fix rust lint

* Fix docs job definition

* Disable multiprocessing parallelism in unit tests

This commit disables the multiprocessing based parallelism when running
unittest jobs in CI. We historically have defaulted the use of
multiprocessing in environments only where the "fork" start method is
available because this has the best performance and has no caveats
around how it is used by users (you don't need an
`if __name__ == "__main__"` guard). However, the use of the "fork"
method isn't always 100% reliable (see
https://bugs.python.org/issue40379), which we saw on Python 3.9 #6188.
In unittest CI (and tox) by default we use stestr which spawns (not using
fork) parallel workers to run tests in parallel. With this PR this means
in unittest we're now running multiple test runner subprocesses, which
are executing parallel dispatched code using multiprocessing's fork
start method, which is executing multithreaded rust code. This three layers
of nesting is fairly reliably hanging as Python's fork doesn't seem to
be able to handle this many layers of nested parallelism. There are 2
ways I've been able to fix this, the first is to change the start method
used by `parallel_map()` to either "spawn" or "forkserver" either of
these does not suffer from random hanging. However, doing this in the
unittest context causes significant overhead and slows down test
executing significantly. The other is to just disable the
multiprocessing which fixes the hanging and doesn't impact runtime
performance signifcantly (and might actually help in CI so we're not
oversubscribing the limited resources.

As I have not been able to reproduce `parallel_map()` hanging in
a standalone context with multithreaded stochastic swap this commit opts
for just disabling multiprocessing in CI and documenting the known issue
in the release notes as this is the simpler solution. It's unlikely that
users will nest parallel processes as it typically hurts performance
(and parallel_map() actively guards against it), we only did it in
testing previously because the tests which relied on it were a small
portion of the test suite (roughly 65 tests) and typically did not have
a significant impact on the total throughput of the test suite.

* Fix typo in azure pipelines config

* Remove unecessary extension compilation for image tests

* Add test script to explicitly verify parallel dispatch

In an earlier commit we disabled the use of parallel dispatch in
parallel_map() to avoid a bug in cpython associated with their fork()
based subprocess launch. Doing this works around the bug which was
reliably triggered by running multiprocessing in parallel subprocesses.
It also has the side benefit of providing a ~2x speed up for test suite
execution in CI. However, this meant we lost our test coverage in CI for
running parallel_map() with actual multiprocessing based parallel
dispatch. To ensure we don't inadvertandtly regress this code path
moving forward this commit adds a dedicated test script which runs a
simple transpilation in parallel and verifies that everything works as
expected with the default parallelism settings.

* Avoid multi-threading when run in a multiprocessing context

This commit adds a switch on running between a single threaded and a
multithreaded variant of the swap_trials loop based on whether the
QISKIT_IN_PARALLEL flag is set. If QISKIT_IN_PARALLEL is set to TRUE
this means the `parallel_map()` function is running in the outer python
context and we're running in multiprocessing already. This means we do
not want to be running in multiple threads generally as that will lead
to potential resource exhaustion by spawn n processes each potentially
running with m threads where `n` is `min(num_phys_cpus, num_tasks)` and
`m` is num_logical_cpus (although only
`min(num_logical_cpus, num_trials)` will be active) which on the typical
system there aren't enough cores to leverage both multiprocessing and
multithreading. However, in case a user does have such an environment
they can set the `QISKIT_FORCE_THREADS` env variable to `TRUE` which
will use threading regardless of the status of `QISKIT_IN_PARALLEL`.

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Minor fixes from review comments

This commits fixes some minor details found during code review. It
expands the section on building from source to explain how to build a
release optimized binary with editable mode, makes the QISKIT_PARALLEL
env variable usage consistent across all jobs, and adds a missing
shebang to the `install_rush.sh` script which is used to install rust in
the manylinux container environment.

* Simplify tox configuration

In earlier commits the tox configuration was changed to try and fix the
docs CI job by going to great effort to try and enforce that
setuptools-rust was installed in all situations, even before it was
actually needed. However, the problem with the docs ci job was unrelated
to the tox configuration and this reverts the configuration to something
that works with more versions of tox and setuptools-rust.

* Add missing pieces of cargo configuration

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-02-28 21:49:54 +00:00
Matthew Treinish 9a743fb2ea
Add support for Python 3.10 (#7102)
* Add support for Python 3.10

Python 3.10.0 was released on 10-04-2021, this commit marks the support
of Python 3.10 in qiskit-terra. It adds the supported python version in
the package metadata and updates the CI configuration to run test jobs
on Python 3.10 and build Python 3.10 wheels.

* Fix typo

* Update default envlist in tox.ini to include 3.10

* Bump cibuildwheel to the latest version

This also takes the opportunity to deduplicate the cibuildwheel
configuration using the pyproject.toml support in newer versions of
cibuildwheel. The common options for all builds are put there and per
build overrides (which are only for cross compiling arm wheels) are left
as environment variables in the CI configuration.

* Add missing cibuildwheel config to pyproject.toml

* Ignore internal deprecation warning emitted by jupyter in ci

* Fix black

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-01-20 00:38:28 +00:00
Matthew Treinish 8c9e01d33f
Drop support for Python 3.6 (#7295)
* Drop support for Python 3.6

As has been advertised for some time the Qiskit 0.19.0 release is the
last release which supports Python 3.6 (which goes End of Life in
Decemeber). This commit drops support accordingly so that the minimum
supported Python version is 3.7.

* Add release note
2021-12-06 23:30:00 +00:00
Matthew Treinish 0248c77cb2
Bump version strings post release (#7357)
Now that qiskit-terra 0.19.0 is out the door we should bump the version
string on master to show the source version we're installing is newer
than what's been released.
2021-12-06 16:46:09 -05:00
Jake Lishman ba8e3f34f0
Fix compatibility with Matplotlib 3.5 (#7301)
* Fix compatibility with Matplotlib 3.5

The problem was `qiskit.visualization.bloch.Arrow3D`, which subclassed
`matplotlib.patches.FancyArrowPatch` (a 2D patch), but not the 3D
machinery.  It is now made an unholy multiple-inherited abomination of
both the 2D patch and `mpl_toolkits.mplot3d.art3d.Patch3D`; the latter
is a relatively thin wrapper (in terms of attributes) around the 2D
patch, so this is not too terrible.

Matplotlib 3.5 calls the `Patch3D.do_3d_projection` method using a
deprecated parameter, triggering two warnings, unless the artist's
module appears to have come from `mpl_toolkits.mplot3d.art3d`, even if
the new calling convention is respected.  The warning is only triggered
when the figure is drawn, which may well be outside of our control, so
we cannot suppress the warnings.  Instead, we just lie about the module
the arrow patch was defined in, to trick it into not warning, because we
use the new calling convention.  This is supported at least as far back
as Matplotlib 3.3, which is the current minimum supported version.  The
nasty hack should be removable once Matplotlib 3.6 is the minimum
version because the deprecation period will expire.

* Remove useless word

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-11-23 19:54:51 +00:00
Anton Dekusar f6b6395517
Approximate Quantum Compiler (#6727)
* initial version

* linting

* linting

* linting and black

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* hello

* linting

* remove debugging

* changed variable names, defined d, and moved -1j/2 multiply to the end

* linting

* linting

* checking

* changed variable names

* corrected typo

* corrected typo

* commented

* typo

* typo

* check

* typo

* linting

* changed variable names and commented

* linting

* changed variable names and commented

* cleaning mvp

* cleaning mvp

* cleaning mvp

* added plugin

* code review

* fix types in cnot_structures.py

* more on documentation

* Update qiskit/transpiler/synthesis/aqc/approximate.py

* Update qiskit/transpiler/synthesis/aqc/cnot_unit_objective.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Update test/python/transpiler/aqc/sample_data.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* code review

* fix cache

* updated plugin, more on documentation

* restructured documentation

* default configuration, aqc plugin setup

* added reno

* Update setup.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* added a test where AQC is invoked via the plugin discovery interface

* added a test where AQC is invoked via pass manager

* update scipy in requirements.txt

* Update qiskit/transpiler/synthesis/aqc/aqc.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* added tests for cnot networks

* added support for plugin configuration

Co-authored-by: Liam Madden <liam.madden2@ibm.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2021-11-23 09:47:56 -05:00
Jake Lishman 6cd3ed163b
Pin matplotlib <3.5 and remove unused imports (#7273)
* Pin matplotlib <3.5

This is temporary to get CI running again, while we prepare a proper
fix for the latest version.

* Remove unused imports

A bug in pylint can sometimes cause unused imports in certain files to
be ignored if they're used in a module-level comment type hint somewhere
that's imported first.  For more, see:
https://github.com/Qiskit/qiskit-terra/pull/7270/#discussion_r749854451

* Pin matplotlib in setup.py too

* Pin matplotlib in azure-pipelines.yml
2021-11-16 13:31:40 +00:00
Matthew Treinish 4c444a3bba
Bump minimum matplotlib version to 3.3.0 (#7175)
* Bump minimum matplotlib version to 3.3.0

In matplotlib 3.4.0 released on 03/26/2021 there were some deprecations
around our use of Axes3d in the state visualization and bloch sphere
modules. Fixing our usage to avoid these deprecations was previously
attempted in #6136 and #6087 but we did not move forward there because
the supported API we need to use matplotlib 3.3.0 when it was
introduced. We previously did not want to raise our minimum supported
matplotlib version to 3.3.0 to accomodate this. However, recent changes
in transitive dependency of mpl, pyparsing, caused an incompatibility
when running with older mpl versions around mathtex. To fix that we
had to pin pyparsing in the constraints file (see #7174). It appears
that now is a better time to raise our minimum version because the
burden of trying to keep support for older matplotlib versions is higher
than it once was.

This commit bumps the minimum matplotlib version to 3.3.0, updates the
usage of Axes3d to avoid the deprecated usage in matplotlib 3.4.0, and
removes the contraints pinning introduced in #7174. This should get us
on supported releases for matplotlib moving forward and it'll hopefully
be a while before we encounter this kind of version issue in the future.

Fixes #6136

* Run black

* Restore constraints pinning

I was under the mistaken impression that the current mpl releases were
compatible with pyparsing3, but looking at the linked mpl issue it's not
fixed yet only for their development so far. So to unblock CI this
restores the pinning as it's still needed until mpl releases a fix.

* Fix matplotlib 3.3.x compat

* Fix version string comparison typing

* Fix typo

* Fix second `ax` typo

* Fix gatemap tests with newer matplotlib

* Fix lint

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-10-28 13:39:38 +00:00
Matthew Treinish 4eda7993fa
Add unitary synthesis plugin interface (#6124)
* Add unitary synthesis plugin interface

This commit adds the initial steps for a unitary synthesis plugin
interface. It enables external packages to ship plugin packages that
then integrate cleanly into qiskit's transpiler without any need for
extra imports or qiskit changes. The user can then just specify the
'unitary_synthesis_method' kwarg on the transpile() call and use the
name of the external plugin and the UnitarySynthesis pass will leverage
that plugin for synthesizing the unitary.

* Also add qubits in payload with coupling map

* Fix lint

* Fix logic

* Add documentation about the plugin interface

* Export get_unitary_synthesis_plugin_names from qiskit.transpiler.passes

* Fix lint

* Tweak doc organization slightly

* Use UnitarySynthesis for unroll3q step

The usefulness of the plugin for unitaries >2q in the default pass
manager pipelines was limited by the fact that previously the pass
managers were all setup to run unroll3q before the unitary synthesis
pass is ever run. The unroll3q pass just calls the circuit.data to
decompose gates >=3q which for unitary gate objects just calls an
inlined equivalent of the 'default' plugin. The purpose of this is to
ensure later passes only ever need to deal with 2q gates. However with
plugins now if a plugin only works on > 2q we'll never actually be
passing an >= 3q unitaries to the plugin in the default pipelines. To
fix this issue, this commit calls unitary synthesis before unroll 3q to
use the synthesis pass to unroll any unitary gates instead of relying on
the gate class's internal decomposition method which will always use the
qiskit decomposition techniques.

* Run black

* Tweak doc organization slightly

* Fix lint

* Fix pylint errors

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Update plugin interface docs

* Review comment updates on UnitarySynthesis pass

* Fix typos

* Include release notes

* Fix docstring typo

* Update qiskit/transpiler/passes/synthesis/unitary_synthesis.py

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

* Ignore deprecation warnings from importlib metadata

Since the importlib metadata 4.8.0 release in late August 2021,
stevedore <= 4.8.0 has raised a deprecation warning around using tuple
based access (which was deprecated in 4.8.1 after 4.8.0 removed it and
broke everything using stevedore). While this has been fixed on the
master branch of stevedore (see:
11da137e3f
) Until that fix is released this commit adds a deprecation warning
ignore because there isn't anything we can do about the warning in
qiskit. Once stevedore has a release that includes this fix we can
remove the ignore from the tests.

* Pin importlib-metadata

The previous commit tried to fix the failures in CI around the
deprecation warnings but while I'm unable to reproduce those locally
with the warning ignore in place it still fails in CI. I expect there is
a similar incompatibility around the 4 frequent importlib-metadata
releases >=4.7.0 (2 of which were yanked) causing issues in the CI
environment. Since things were working fine for the several months this
PR was open prior to 4.7.0 this commit just pins the version in the
constraints file to fix CI.

* Add length units to docstring

* Add min and max qubit abstract properties

This commit adds 2 new required properties to the plugin class interface
for min and max qubits. These enable a plugin author to specify the
number of qubits the plugin supports and if the unitary to be
synthesized is outside that range it will just fallback to using the
``default`` plugin.

* Add option to automatically find basis for a run() call

* Fix typo

* Update gate errors docstring

* Remove approximation degree from plugin interface

* Fix docstring typos

Co-authored-by: Eric Peterson <peterson.eric.c@gmail.com>

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Update qiskit/transpiler/passes/synthesis/unitary_synthesis.py

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Update docstrings and naming and default to 'default' plugin in kwarg

This commit updates several aspects of the documentation to make it more
clear how to use the plugin interface. It also updates the naming of
supported_basis to be supported_bases as it's actually plural. The last
change in this commit is making the default kwarg value for the
unitary synthesis method default to 'default' (for the default built-in
method) instead of None. This simplifies the logic in the unitary
synthesis pass.

* Make coupling_map run() kwarg a tuple

* Add comment on why we don't use a shared global instance

* Fix straggler basis->bases typos

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Document supported_bases handling of no matching basis

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Eric Peterson <peterson.eric.c@gmail.com>
2021-09-30 19:09:24 +00:00
Jake Lishman 0804630785
Exclude bip-mapper extra from all (#6843)
* Exclude bip-mapper extra from Python 3.6 and 3.9

The 'cplex' package is not (presently) available on Python 3.6 or 3.9.
This means that
    pip install qiskit-terra[all]
will fail on those Python versions, because the requirements cannot be
specified.

This patch makes it so that the 'all' target will treat requirements
from 'bip-mapper' as unnecessary on the relevant Python versions, but
will still enforce them if 'qiskit-terra[bip-mapper]' is specified
explicitly.

* Do not restrict docplex by Python version

docplex only claims to be usable with Pythons 3.6--3.8, but is
sdist-only, so will install with any version.  We now unrestrict it, so
if someone has a commerical version of 'cplex' they may still be able to
get the benefits.

This commit also removes the Python-3.8-only `sum(..., start=...)` form.

* Update wording in release note

* Remove 'bip-mapper' from 'all' target

The available versions of `cplex` are too restrictive compared to the
supported OSes, platform architectures and Python versions of Terra.
The `bip-mapper` extra can still be installed explicitly, but `all` will
not give it to you by default, to avoid failing resolution in more
common cases.
2021-07-30 18:38:12 +00:00
Matthew Treinish 7bb2b1e0b1
Bump version strings post release (#6722)
Now that qiskit-terra 0.18.0 is out the door we should bump the version
string on master to show the source version we're installing is newer
than what's been released.
2021-07-13 07:40:28 -04:00
Matthew Treinish 5ca967557b
Prepare 0.18.0 release (#6652)
* Prepare 0.18.0 release

To prepare for the upcoming 0.18.0 release this commit moves all the
release notes into a 0.18 subdirectory to keep them separate from future
development notes post-release. It also adds a release note with the
prelude section providing the high level overview of the release. When
this merges it should be the commit used to tag the 0.18.0 release.

* Move new release note

* Start rewriting release notes

* More updates

* Fix RZXCalibrationBuilderNoEcho docs

* Fix formatting issue

* Update more release notes

* Finish first pass of feature release notes

* Apply suggestions from code review

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Finish first pass of upgrade and deprecation notes

* Start rewriting fix notes

* Remove accidentally committed file

* Update releasenotes/notes/0.18/prepare-0.18-9a0fb87005e314fd.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Remove 0.17.x stable release notes

* More fix note rewrites

* Move new release notes

* Move new release notes

* Add bip mapper extras to all extra

* Finish first pass of release notes

* Revert changes to tox.ini

* Move and rewrite new release notes

* Fix typos

* Fix another typo

* Remove new fix note as it only was an issue on unreleased code

* Apply suggestions from code review

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Expand prelude

* Fix alignment release note example

* Remove double requirement on tweedledum in ci

* Move and update new release notes

* Move new release notes

* Fix lint

* Move and update new release notes

* Apply suggestions from code review

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Move and update new release notes

* Apply suggestions from code review

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

* Update releasenotes/notes/0.18/TensoredMeasFitter-d327f0e2d736efdd.yaml

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Apply suggestions from code review

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

* Update alignment release note

* Remove release note that shouldn't be advertised yet

* Fix alignment pass release note

* Move and update the last release note

* Apply suggestions from code review

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
2021-07-12 19:22:26 +00:00
Matthew Treinish 927fd0226b
Make tweedledum a hard requirement (#6588)
* Make tweedledum a hard requirement

This commit switches the tweedledum requirement from being optional to a
hard requirement for installing qiskit-terra. We rely on tweedledum to
synthesize phase oracles which is commonly used functionality and several
issues have been opened. This use of tweedledum will likely continue to
grow so we should just list it as a requirement moving forward.

We originally made it optional because the functionality depending on
tweedledum was isolated to just the classical function compiler which
wasn't widely used. There were also packaging issues in the past where
the available precompiled binaries for tweedledum didn't support all of
our supported environments, but those have been resolved. There is still
an issue for arm64 macOS binaries but Qiskit doesn't have wide support
for that yet (although there is a job for terra).

At the same time this commit cleans up the optional requirements list
so that aer is no longer listed there and we add an 'all' extra so that
people can have a simple entypoint to install all the optional extras at
once.

Fixes #6333
Fixes Qiskit/qiskit#1253

* Remove unused imports

* Cleanup docstrings

* black setup

* Update requirements.txt

Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>
2021-07-01 14:46:56 +00:00
itoko cd4a712d8f
BIP mapping pass (#6580)
* wip: initial move

* fix a bug when no coupling_map is supplied

* Improved documentation and parameter settings

* Improved logical/physical qubit mapping

* Better handling of measurements and final layout

* minor fixes

* add unit tests

* wip: start refactoring

* improve layout handling

* simplify dag construction and fix to output all ops

* fix to work with ApplyLayout

* focus on layout+routing

* improve how to call MIPMapping

* simplify the spec

* add an error handling

* fix how to call MIPMapping pass

* update user warning for change of given layout

* wip: refactor mip model

* improve top-level interface

* return original dag if fails to solve MIP

* minor fixes

* care the case no cplex is installed

* fix not to ignore swaps in original layers

* fix mismatch in layer and su4layer indices

* simplify by focusing only on depth objective

* rename MIP to BIP

* lint

lint

lint

lint

* improve interface around dummy steps

* improve error message when cplex fails

* restore level3 preset passmanager

* improve depth objective

* Rework optional dependency and add test configuration

This commit reworks the logic around the optional dependency on cplex.
The pass despite raising an exception if cplex wasn't installed was
unconditionally trying to import cplex from the model module at import
time. To avoid failures from that this adds a try block around the
actual cplex usage in the model module and exports whether it's
available or not. At the same time this is leveraged to add a skip
condition on the tests so we only run them if cplex is installed. Then
to run tests in CI we install cplex in the linux 3.7 job so we at least
run it in one environment. It's not available in all our supported
environments so getting full coverage in every env is not worth trying
for, so just testing the qiskit portion works is enough.

* Fix lint

* Fix test, lint and logging

* Fix lint and test, update docstring

* Fix docstring and improve performance taking the risk of failing to map

* Update docstring

* Replace cplex.Cplex with docplex.mp.model.Model to improve readability

Replace cplex.Cplex with docplex.mp.model.Model to improve readability

fix requiring docplex version

move docplex to requirements-dev

* Improve BIPMappingModel interface

simplify and improve docstring

Improve BIPMappingModel interface

* Update qiskit/transpiler/passes/routing/algorithms/bip_model.py

Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>

* Fix docplex dependency

* fix unnecessary-comprehension

* lint

* lint

* update how to set cplex params and remove redundant constraints

* skip unless docplex

* fix a bug in arg threads

* remove python version restriction

* Change spec to require the number of virtual and physical qubits are the same

* Update to use 'requires' to require precondition passes

* Update qiskit/transpiler/passes/routing/algorithms/bip_model.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* lint

* Add release note

Add release note

fix typos

* Update docstring

Update docstring

fix typo

* Improve error handling

* Change to return mapped dag for circuits with only 1q-gates

* Revert the spec change in the case of only 1q-gates

* Update releasenotes/notes/add-bip-mapper-f729f2c5672d7f3e.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update releasenotes/notes/add-bip-mapper-f729f2c5672d7f3e.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

Co-authored-by: Giacomo Nannicini <gnannicini@users.noreply.github.com>
Co-authored-by: Giacomo Nannicini <giacomo.n@gmail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-07-01 06:29:40 +00:00
Lev Bishop 9e9ad8aa66
Blacken stragglers (#6611)
* Blacken stragglers

* fix tox.ini and azure-pipelines.yml

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-06-21 21:49:31 +00:00
Lev Bishop 0431516919
Skip badges on pypi (#6034)
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-04-06 22:07:36 +00:00
Matthew Treinish e5d66367fb
Bump version strings post release (#6135)
* Bump version strings post release

Now that qiskit-terra 0.17.0 is out the door we should bump the version
string on master to show the source version we're installing is newer
than what's been released.

* Bump mergify config
2021-04-01 17:58:39 -04:00
Luciano Bello 674a6e2898
Boolean expression object (#5830)
* added dymacs_oracle

* added dimacs_oracle

* added dimacs_oracle

* updated evaluate_bitstring

* simplify logic a bit

* added unittests

* clean up

* added logical_expression_oracle.py

* added comments and unittests

* clean up

* lint

* fix linting

* fixed based on the comments

* boolean expression

* docstring

* converter and dimacs support

* parity decomposition

* phase oracle

* boolean expression as a gate

* simulate to keep it like classical function

* objective_qubits from a phase oracle

* new api

* revert problem touching

* tests

* fixing test.python.classical_function_compiler.test_tweedledum2qiskit

* Update qiskit/circuit/library/__init__.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* revert

* fix simulate

* more testing

* change synth algo

* fixes #5666

* dependency

* linting linting

* circular impport

* testing phase oracle

* phase test

* msg

* similar testing

* lint

* maybe last lint cleaning

* moving docs

* lint

* more linting

* lint

* another lint

* lint!

* adapt test

* new test

* failing in linux

* remote debuging

* more debug

* new tweedledum

* more debugging

* false positive in pylint

* tweedledum==1.0.0b3

* organize HAS_TWEEDLEDUM flag

* linting

* check if the file exists

* release note

* remove state_qubits

* docstring

* no python highlighting?

* Apply suggestions from code review

import error with pinned version

* abstract class for classical elements

* abc

* cleaner Phaseoracle

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* now _build_from_boolean_expression

* ups

* from_dimacs

* MissingOptionalLibraryError

* abstract class should skip

* Update qiskit/circuit/library/phase_oracle.py

* some refactors

* lint

* Update qiskit/circuit/library/phase_oracle.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* reno

* Update releasenotes/notes/bool_expression_phaseoracle-1802be3016c83fa8.yaml

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* type hint

* Update qiskit/circuit/classicalfunction/boolean_expression.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* lint

* more typehints

* hints are getting out of control

* self.qreg

* 3.6

* fix missing whitespace

* lint

* ilnt

Co-authored-by: Atsushi Matsuo <MATSUOA@jp.ibm.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: a-matsuo <47442626+a-matsuo@users.noreply.github.com>
2021-03-31 18:11:32 +00:00
gadial ddb2b74653
Adding optimized pauli expval computation (#5941) 2021-03-08 08:50:37 -05:00
Luciano Bello 0b30218df2
pin tweedledum version (#5853)
* pin tweedledum version

* setup
2021-02-16 18:06:19 -05:00
Lauren Capelluto 5515717594
Update setup.py: REQUIREMENTS (#5613)
* Update setup.py to utilize requirements.txt for installation-required dependencies. This reduces the chance of hard-to-debug errors if requirements and setup don't match

* Add requirements to MANIFEST

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2021-01-12 21:37:19 +00:00
Matthew Treinish 75e600ebf7
Migrate ApproximateTokenSwapper to only use retworkx and make networkx optional (#5471)
* Migrate ApproximateTokenSwapper to only use retworkx

This commit removes the networkx usage in the ApproximateTokenSwapper to
use retworkx instead. Besides being speeding up the execution of the
pass what's more important here is that this was the last networkx usage
in qiskit-terra (with the exeception of a couple compatibility
converters in qiskit.dagcircuit). So this commit also makes networkx an
optional dependency and updates the 3 methods (which are outside the
common usage scenarios) to use runtime imports and emit a more detailed
import error if networkx isn't installed.

Fixes: #5470
Related to: #5100

* Remove unecessary duplicate None check

* Add networkx to requirements-dev.txt

There is a single dagcircuit test that uses the to_networkx() method. So
we need to install networkx in test environments.

* Remove _T type

* Update releasenotes/notes/nx-optional-6b8ad63529fe32ca.yaml

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Remove _V type

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>
2020-12-07 16:17:45 -05:00
Matthew Treinish 84672ff862
Leverage retworkx for DAGCircuit.collect_runs() (#5463)
In the recent retworkx 0.7.0 release a new function that can be used for
collect runs. This commit migrates the collect_runs implementation to
leverage retworkx's collect_runs() function. This provides a ~2x speedup
for the optimize_1q_gats transpiler pass.

Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
2020-12-04 01:11:08 +00:00
Matthew Treinish 200d7395c7
Add support for Python 3.9 (#5189)
* Add support for Python 3.9

Python 3.9.0 was released on 10-05-2020, this commits marks the support
of Python 3.9 in qiskit-terra. It adds the supported python version in
the package metadata and updates the CI configuration to run test jobs
on Python 3.9 and build python 3.9 wheels.

* Also deprecate 3.6

* Use latest nodes for CI

* Remove Python 3.6 deprecation

The Python 3.6 deprecation is being handled separately in #5301 to
decouple it from adding python 3.9 support. This commit removes the 3.6
deprecation accordingly.

* Bump cibuildwheel version to the latest release

* Remove unused assertNoLogs method

The assertNoLogs methods was built using a private class from python's
stdlib unittest library. This should never have been done as it's
explicitly marked as private. Accordingly in Python 3.9 this private
class has been removed and no longer exists. It turns out this method
was not used anywhere in all of qiskit (not just terra). Since the
implementation is not sound and nothing uses it this commit just removes
the class and method.

* Fix lint

* Remove aer from macOS and windows jobs

* Remove IBMQ provider from ci jobs

The ibmq provider is not used by anything in CI anymore. It was an
historical artifact when some of the visualization and jupyter tests
required it. This is no longer true. However, installing the ibmq
provider in the linux 3.9 job is blocking CI because of an unrelated
requests library issue with urllib3. To resolve this, this commit just
removes the unecessary install.

* Add back ibmqprovider to tutorials job, it's needed for aqua tutorials

* Fix jupyter test skip

* Update test/python/tools/jupyter/test_notebooks.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Fix lint

* Add back pbars macOS test skip

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-12-02 04:51:32 +00:00
Matthew Treinish 4e03ad1fb5
Leverage retworkx for apply_operation* inner loop (#5267)
* Leverage retworkx for apply_operation* inner loop

This commit migrates the inner loop for apply_operation_back and
apply_operation_front to leverage retworkx's
insert_node_between_multiple PyDiGraph method. This retworkx method
performs essentially the same loop internally but executes faster.

Depends on https://github.com/Qiskit/retworkx/pull/181 being included in
a release.

* DNM: Test with retworkx branch

* Update for retworkx 0.6.0 release

* Remove stray kwarg from earlier revision

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-11-25 17:42:26 +00:00
Lauren Capelluto 7633baa6dd
Bump version to 0.17.0 for next release (#5243)
Now that 0.16.0 is out the door this commit bumps
the version to 0.17.0 for the next release.

Mergify backport targets 0.16.0 release
2020-10-15 22:07:00 -04:00
Luciano Bello bbe1f1c973
Classical Function compiler (#4522)
* classical function compiler

Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>

* utils

* synthesis

* renaming

* int1

* import

* reno

* docstring

* doc

Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-09-30 20:21:47 +00:00
Matthew Treinish e137554c80
Remove deepcopies from DAGCircuit.__eq__ (#4992)
The __eq__ method of the dagcircuit class was previously deep copying
the retworkx PyDAG objects for both self and other to force a reindexing
of the node indices in the graphs to acvoid a bug in retworkx (see
Qiskit/retworkx#27 for more details). In the next retworkx a workaround
for that bug was introduced which removes the need for doing the deepcopy
calls. This commit does that and removes the deep copies which should
improve the performance of run __eq__ o dagcircuit objects.
2020-09-18 12:12:48 -04:00
Jessie Yu 2754ef8c84
update email (#5070) 2020-09-15 19:52:41 +00:00
Matthew Treinish 7998b60225
Drop support for python 3.5 (#4926)
This commit drops support for running with python 3.5. It marks the
minimum supported version of the package as python 3.6, removes python
3.5 package pins, removes the 3.5 CI jobs, and removes the warning on
python 3.5. Looking at the PyPI stats since the deprecation period
started the number of users on Python 3.5 has diminished significantly,
but not disappeared. There were 783 downloads with pip from pypi out of
total of 25782 total pip downloads in the last 30 days. Compared to the
roughly 10% figure when we deprecated Python 3.5.

Merging this means we can not release until after the documented EoL
date for Python 3.5 support of September 13. This shouldn't be a problem
because with #4767 we will need to coordinate the release of all the
qiskit elements and are planning to do that after 09/13/2020.

It's worth noting that we should start planning to deprecate python 3.6
support sooner rather than later it goes EoL upstream at the end of
next year [1] and some of our other upstream dependencies (mainly numpy
et al) are going to remove support before the upstream Python EoL date
[2].

[1] https://devguide.python.org/#branchstatus
[2] https://numpy.org/neps/nep-0029-deprecation_policy.html

Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
2020-09-01 12:12:49 -04:00
Lev Bishop 779fa14d44
Remove coding: utf-8 per PEP 3120 (#4914)
utf-8 has been the default since PEP 3120.
https://www.python.org/dev/peps/pep-3120/

Non trivial edits are to Makefile and verify_headers.py
2020-08-12 08:29:16 -04:00