Commit Graph

1041 Commits

Author SHA1 Message Date
Manoel Marques 837d4edffb
Pending deprecate algo eigen_solvers (#8651)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-29 12:43:15 +00:00
ElePT bebc1f8bbf
Implement eigensolvers (VQD) with primitives (#8640)
* New eigensolver namespace

* Add unittests

* Remove unit test

* Progress

* Revert vqd changes

* Restore temporary changes

* Change test names

* Code cleanup

* More cleanup

* Remove run options

* Fix seed test callback

* Add warning gradients

* Fix style

* Move aux ops evaluation to vqd

* Make black

* Fix cyclic imports

* Fix style unit tests

* Remove eigenstate from result class

* Add eigenstates to init

* Fix black

* Add NumPyEigensolverResult

* Fix lint

* Add eigensolvers with primitives (VQD)

* Update base class

* Update numpy eigensolver

* Apply changes VQE

* Update

* Add TODO

* Remove opflow code

* Update copyright

* Change run_options

* Add obs.eval, fix bug, add unit test, apply comments

* Fix black

* Fix attributes, remove gradient

* Remove defaults

* Fix lint, add base operator support

* Add BaseOperator support and unit tests

* Fix style

* Fix style

* Fix lint

* Fix sphinx

* Update qiskit/algorithms/eigensolvers/vqd.py

* Update qiskit/algorithms/eigensolvers/vqd.py

* Apply VQE changes

* Add metadata to result

* Fix old reno cross reference

* fix lint

* modify aux ops metadata

* Add metadata to callback

* Return metadata in observables evaluator

* fix copyright

* Update test/python/algorithms/test_numpy_eigen_solver.py

* Remove opflow from vqd tests

* Add optimizer result

* fix tests

* Fix lint

* Fix black

* Fix cyclic imports

* Fix black againnn

* Add minimally working VQE with estimator primitive implementation.

No gradients, no tests etc.

* Revert from dataclass results to original result classes.

* Enforce positional and keyword VQE arguments.

* Move aux op eval logic to function

* Update docstring.

* Remove max_evals_grouped. Force to set directly on optimizer.

* Remove validate min import.

* Make note that eval_observables will be used to eval aux ops.

* Add initial vqe tests.

* Have VQE inherit from VariationalAlgorithm.

* Move energy evaluation to unnested function.

* Construct h2_op using SparsePauliOp

* Add gradient with primitives support.

* Update docstrings

* update broadcast handling

* update eval_energy output for batching

* add incomplete QNSPA test

* fix batch evaluation of QNSPSA test

* remove vqe callback

* move estimator to first arg

* remove usused imports

* add minimum eigensolvers test init file

* add aux ops tests and prepare for new eval_operators

* no longer support account for Nones in aux_ops

* correct typing for MinimumEigensolver

* Compute default initial point using ansatz bounds.

* Add NumPyMinimumEigensolverResult

* Fix type hints

* Fix type hints

* Formatting

* Do not store NumPyMES result inside the algo.

* Provide default values for ansatz and estimator

* Formatting

* fix old and new batching

* Add tests for NumpyMES and import in module.

* Use lazy formatting in log messages

* Use lazy formatting in log messages

* Add back callback to VQE.

* minor renaming

* raise algorithm error if primitive jobs fail

* Add return documentation

* Improve var names and docstrings.

* Apply suggestions from code review

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>
Co-authored-by: dlasecki <dal@zurich.ibm.com>

* minor formatting

* minor formatting

* Ensure evaluate_energy/gradient match

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* return bounds logic; fix some docstrings and minor refactor

* Force keyword arguments in vqe.

* Use estimate_observables function

* break up numpy mes tests with subTest

* formatting

* remove redundant eval_aux_ops

* add typehints to docstring attributes

* remove usused imports

* remove default ansatz

* remove usused imports

* update typehints

* avoid changing the original ansatz

* avoid changing the original ansatz

* create separate function to build vqe result

* Correct aux operator eignvalue type hint

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* add variance to callback

* use std_dev in callback rather than variance

* formatting

* return variance and shots in callback

* return full metadata in callback

* Move validation functions to algorithms/utils

* correct the callback attribute documentation

* correct the callback attribute typehint docstring

* update VQE docstring

* release note and pending-depreciate old algs

* update vqe class docstring

* Apply suggestions from code review

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* Do not copy ansatz

* Note pending depreciation of old algs

* fix docstrings and imports

* Fix issues with building docs

* Include OptimizerResult in VQEResult

* Remove trailing whitespace

* Fix math notation in docstring

* estimate_obervables to return metadata @ElePT +VQE

* add example in release note

* Update evaluate_observables docstring

* Fix observables_evaluator tests.

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* fix trotter_qrte tests and remove depreciation

* formatting

* remove unused import

* Apply suggestions to docstring from code review

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

* Update VQE docstring

* Remove printing

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* Add parameters to estimate observables

* Fix estimate obs. unit test

* Update arg description

* Update arg description

* keep equation part of sentence

* dict -> dict[str, Any]

* Update qiskit/algorithms/optimizers/spsa.py

Apply suggestion Imamichi-san

* introduce FilterType and aux_operator_eigenvalues -> aux_operators_evaluated

* Correct typehint

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>

* Adapt to VQE

* Update qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py

* Pull from main

* Remove change vqe

* Refine docs, typehints, remove opflow

* add check for PauliSumOp

* Fix import

* reformat test

* Remove metadata unit tests

* Add operator tests

* Reformat tests

* Fix observables eval test

* Apply initial feedback

* Change numpy eig. aux ops metadata

* Apply review comments

* Fix unittests

* Update reno

* Apply review comments

* Fix result names, typehints

* Fix docs

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
Co-authored-by: Declan Millar <declan.millar@ibm.com>
Co-authored-by: dlasecki <dal@zurich.ibm.com>
Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-29 11:22:17 +00:00
Ikko Hamamura 17de3b0b78
Clifford does not use StabilizerTable as internal data and PendingDeprecation of PauliTable and StabilizerTable (#7269)
* initial commit

* Update clifford and stabilizerstate

* fix lint and tests

* fix test

* Deprecate StabilizerTable

* Remove autogenerated file

* update docs

* refactoring

* improve random_clifford

* add phase_stab, phase_destab

* rename phase_stab to stab_phase

* add Clifford.symplectic_matrix method

* remove deprecation

* fix __setitem__

* add pending deprecation to PauliTable

* update releasenote

* update releasenote

* refactor

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-29 09:06:37 +00:00
Matthew Treinish 594ad019a3
Remove pulse defaults for old fake 20q backends (#8665)
* Remove pulse defaults for old fake 20q backends

The pulse defaults payload for the almaden, johannesburg, and singapore
fake backends are collectively taking up > 50% of the total disk
footprint of an installed copy of Qiskit. This is because the pusle
defaults for these backends predate the use the of parameterized pulse
definitions and contain arrays of sampled waveforms for the pulse
definitions. This exceedingly large file size slows down the entire
package and and makes it slower to install. When weighing the potential
value these defaults files provide for simulating and compiling with
pulse awareness for long retired devices against the real cost of
having the files included in the package there isn't a reason to keep
the files in the tree any longer. This commit removes the pulse
defaults files for these fake backends to greatly shrink the installed
package size of qiskit-terra.

* Update releasenotes/notes/remove-pulse-defs-old-20q-4ed46085b4a15678.yaml

* Update tests and docs

Several tests and docs were relying on the pulse data being present in
the fake backends. This commit updates the tests and docs to avoid this
and either rely on different fake backends that use parametric pulses or
not rely on a fake backend at all. In one case a bug is fixed the
assembler which was causing the tests to incorrectly pass because the
use of pulse backends without parametric pulses was masking incorrect
behavior.

* Revert passmanager config string test changes

* Remove self.maxDiff in str test

* Fix missing backtick

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-29 04:47:14 +00:00
Matthew Treinish 0cd7dba184
Use Sabre by default for optimization levels 1 and 2 (#8552)
* Use Sabre by default for optimization levels 1 and 2

This commit updates the preset pass manager construction to use the
SabreLayout and SabreSwap passes by default for optimization level 1 and
level 2. With the recently merged #7977 the performance of the sabre
swap pass has improved significantly enough to be considered for use by
default with optimization levels 1 and 2. While for small numbers of
target device qubits (< 30) the SabreLayout/SabreSwap pass doesn't quite
match the runtime performance of DenseLayout/StochasticSwap it typically
has better runtime performance for larger target devices. Additionally,
the runtime performance of Sabre should also improve further after #8388
is finished. However, the output quality from the sabre passes is
typically better resulting in fewer swap gates being inserted. With the
combination of better quality and comparable runtime performance it
makes sense to use sabre as the default for optimization levels 1 and 2.
For optimization level 0 stochastic swap is still used there because we
want to continue to leverage TrivialLayout for that level and to get
the full quality advantages SabreSwap and SabreLayout should be used
together.

* Fix pickling of SabreSwap object

In #7977 we moved to use compiled objects for part of the SabreSwap
compiler pass. However an unintended side effect of that PR was the use
of Rust objects stored in instance level variables which weren't
pickleable. This breaks multiprocessing at the PassManager level which
expects to be able to pickle and send a SabreSwap object to the
subprocess running on a circuit. This commit fixes this by making the
Rust NeighborTable object pickleable and switching to storing the
heuristic string at the instance level instead of the heuristic enum.

* Update layout tests to match new default

This commit updates a failing layout test which was assuming that level
1 and level 2 where still running DenseLayout. The test has been updated
to reflect the new default of SabreLayout.

* Fix stochastic swap specific test to use that routing method

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-29 03:43:28 +00:00
Jake Lishman fca3864951
Add conversion transpiler pass from `c_if` to `IfElseOp` (#8764)
* Add conversion transpiler pass from c_if to IfElseOp

This is intended to be used to ease the transition from the old-style
conditions to the new-style form.  Backends may use it in their custom
pipelines, so they can guarantee they only need to deal with one form.

A further classical optimisation may be to group `IfElseOp` blocks that
share the same condition into a single operation, but this would likely
be a separate pass, if added, or potentially be the domain of a separate
part of the circuit-description/compilation/running pipeline.

* Remove nondeterministic bit ordering

* Add test of no-op behaviour

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-29 02:39:09 +00:00
Ikko Hamamura 2b7282d476
Parameter handling in SparsePauliOp (#8620)
* Parameter-friendly usage of Numpy methods

* remove pdb.set_trace()

* Updated target image in mpl backend visualization tests

* Fixed methods causing failing tests

* fixed lint

* Fixed formatting of variable in SparsePauliOP

* Fixed dtype casting (object->float, complex->float) tests

* Fixed failing tests

* Fixed lint

* Fixed import order for linter

* revert gate.py

* revert qdrift.py

* revert PauliSumOp

* update SparsePauliOp

* readable code (Jake's suggestion)

* add tests

* add docs

* fix docs

* fix typo

* add reno

* Update documentation

* use-parameters

* bind_parameters_to_one

Co-authored-by: Jesus Sistos <jesussistos.josb@gmail.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-28 23:59:48 +00:00
Freya Shah 368fbbb702
Migrating AdaptVQE to Qiskit Terra (#7930)
* added adapt_vqe

* implemented  most of the suggested changes

* implemented the suggested changes

* added the changes

* .

* made the suggested changes

* added the code

* test added

* added adapt_vqe

* .

* .

* added changes

* added changes

* added changes

* .

* added the changes

* .

* added

* formatting done

* Update adapt_vqe.py

* made the suggested changes

* made the changes

* lint changes

* removed initial point from init

* black changes

* added inline definition

* made the changes

* removed sys import

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* Update qiskit/algorithms/minimum_eigen_solvers/adapt_vqe.py

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* added

* added

* .

* .

* made final changes

* fix: evaluate gradients via commutator relation

The gradients for the operators in an `EvolvedOperatorAnsatz` can
actually be evaluated via simple measurements on the current circuit
without having to construct the new ansatz for every single excitation
during every iteration. Instead, the gradients can be computed from the
commutator of the excitation operators with the main operator of the
VQE.
Doing so, results in a drastic performance improvement.

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

* .

* made the changes

* .

* fix: AdaptVQE gradient computation unittest

* fix: remove unused import

* refactor: migrate AdaptVQE to primitive-based module

* Add a release note

* Apply suggestions from code review

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

* Pass parameters to estimate_observables method

Co-authored-by: Declan Millar <declan.millar@ibm.com>

* Apply suggestions from code review

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

* More changes based on code review

* Avoid deep-copying the ansatz

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>
Co-authored-by: Max Rossmannek <oss@zurich.ibm.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: Declan Millar <declan.millar@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-28 19:38:52 +00:00
Matthew Treinish 4a857f6114
Add BackendV2Converter class for treating BackendV1 as BackendV2 (#8759)
* Add BackendV2Convert class for treating BackendV1 as BackendV2

This commit adds a new class BackendV2Converter which is a BackendV2
implementation that converts an input BackendV1 object into a BackendV2
implementation. This is useful for users that are supporting working
with arbitrary providers so that they can standardize on using the
newest access patterns even if a provider is still using BackendV1.
Similarly, for qiskit's internal usage, this gives us a path to move all
of the transpiler internals to use Target and avoid carrying around
duplicate information in the PassManagerConfig for passes that haven't
been updated. This will enable us to convert input BackendV1 instances
to a target once on initial calling and have the transpiler only ever
see a target.

Fixes #8611

* Update docstring

* Return empty options for _default_options

* Remove leftover pylint disable

* Expand standard gate conversions and handle missing basis_gates

* Fix copy paste error qubit_props_list_from_props() docstring

* Add name mapping argument to allow setting custom name-> gate mappings for conversion

* Add missing gamma parameter

* Fix handling of global ops in configuration

* Raise exception on custom gates without mapping

* Move name mapping to standard gates module

* Fix lint and docs

* Use gate object name attribute to build name mapping

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

* Fix lint

* Fix pylint cyclic-import error

* Update qiskit/providers/backend_compat.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Remove supported_instructions and add option for adding delay

The supported instructions field is underdocumented and it's not clear
that the instructions it contains are something that we want to support
directly. Since the only reason we added support for it in the target
generation was to handle the delay for ibm backends (mostly in tests as
the IBM provider will be using BackendV2 natively soon) this commit
removes its usage and adds a new flag for explicitly adding delay to the
backend's target.

* Add mention of converter class to API changes section

* Add missing flag usage to delay test

* Run black

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
2022-09-28 06:37:53 +00:00
Manoel Marques 293ab43afb
Pending deprecate algorithms (#8703)
* Pending deprecate algorithms

* Update releasenotes/notes/pending-deprecate-min-eigen-solvers-fa4341e1014e4df0.yaml

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

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-27 20:44:09 +00:00
Declan Millar 037ae6375e
VQE implementation with estimator primitive (#8702)
* Add minimally working VQE with estimator primitive implementation.

No gradients, no tests etc.

* Revert from dataclass results to original result classes.

* Enforce positional and keyword VQE arguments.

* Move aux op eval logic to function

* Update docstring.

* Remove max_evals_grouped. Force to set directly on optimizer.

* Remove validate min import.

* Make note that eval_observables will be used to eval aux ops.

* Add initial vqe tests.

* Have VQE inherit from VariationalAlgorithm.

* Move energy evaluation to unnested function.

* Construct h2_op using SparsePauliOp

* Add gradient with primitives support.

* Update docstrings

* update broadcast handling

* update eval_energy output for batching

* add incomplete QNSPA test

* fix batch evaluation of QNSPSA test

* remove vqe callback

* move estimator to first arg

* remove usused imports

* add minimum eigensolvers test init file

* add aux ops tests and prepare for new eval_operators

* no longer support account for Nones in aux_ops

* correct typing for MinimumEigensolver

* Compute default initial point using ansatz bounds.

* Add NumPyMinimumEigensolverResult

* Fix type hints

* Fix type hints

* Formatting

* Do not store NumPyMES result inside the algo.

* Provide default values for ansatz and estimator

* Formatting

* fix old and new batching

* Add tests for NumpyMES and import in module.

* Use lazy formatting in log messages

* Use lazy formatting in log messages

* Add back callback to VQE.

* minor renaming

* raise algorithm error if primitive jobs fail

* Add return documentation

* Improve var names and docstrings.

* Apply suggestions from code review

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>
Co-authored-by: dlasecki <dal@zurich.ibm.com>

* minor formatting

* minor formatting

* Ensure evaluate_energy/gradient match

Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>

* return bounds logic; fix some docstrings and minor refactor

* Force keyword arguments in vqe.

* Use estimate_observables function

* break up numpy mes tests with subTest

* formatting

* remove redundant eval_aux_ops

* add typehints to docstring attributes

* remove usused imports

* remove default ansatz

* remove usused imports

* update typehints

* avoid changing the original ansatz

* avoid changing the original ansatz

* create separate function to build vqe result

* Correct aux operator eignvalue type hint

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* add variance to callback

* use std_dev in callback rather than variance

* formatting

* return variance and shots in callback

* return full metadata in callback

* Move validation functions to algorithms/utils

* correct the callback attribute documentation

* correct the callback attribute typehint docstring

* update VQE docstring

* release note and pending-depreciate old algs

* update vqe class docstring

* Apply suggestions from code review

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* Do not copy ansatz

* Note pending depreciation of old algs

* fix docstrings and imports

* Fix issues with building docs

* Include OptimizerResult in VQEResult

* Remove trailing whitespace

* Fix math notation in docstring

* estimate_obervables to return metadata @ElePT +VQE

* add example in release note

* Update evaluate_observables docstring

* Fix observables_evaluator tests.

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* fix trotter_qrte tests and remove depreciation

* formatting

* remove unused import

* Apply suggestions to docstring from code review

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

* Update VQE docstring

* Remove printing

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>

* Add parameters to estimate observables

* Fix estimate obs. unit test

* Update arg description

* Update arg description

* keep equation part of sentence

* dict -> dict[str, Any]

* Update qiskit/algorithms/optimizers/spsa.py

Apply suggestion Imamichi-san

* introduce FilterType and aux_operator_eigenvalues -> aux_operators_evaluated

* Correct typehint

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>

* update vqe docstring and use old typing for type alias

Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com>
Co-authored-by: dlasecki <dal@zurich.ibm.com>
Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: ElePT <epenatap@gmail.com>
Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
2022-09-27 13:43:40 +00:00
Naoki Kanazawa 672e95d089
Remove symbolic pulse subclass implementation (#8278)
* Remove symbolic pulse subclass implementation. Now every symbolic pulse objects are SymbolicPulse instance. Subclasses become SymbolicPulse factory, and isinstance check is invalidated because these classes are never instantiated. QPY loader for these classes are also removed.

* Review comments

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* comments from review

* update release note

* fix test

Co-authored-by: Will Shanks <willshanks@us.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-27 02:23:59 +00:00
Alexander Ivrii 2f6ea4b87f
Improving memory consumption of DagDependency when lists of transitive predecessors and successors are not required (#8525)
* Improved construction of DagDependency when lists of transitive successors and predecessors are not needed

* typos

* minor

* Adding TODO and explanation messages following review comments

* Update releasenotes/notes/dag_dependency_speedup-f6298348cb3d8746.yaml

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>
2022-09-26 21:33:39 +00:00
Manoel Marques ae0ceee6ea
Rewrite Amplitude Estimators with Primitives (#8656)
* Rewrite Amplitude Estimators with Primitives

* Update qiskit/algorithms/amplitude_estimators/ae.py

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

* fix errors

* Update qiskit/algorithms/amplitude_estimators/ae.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* Update qiskit/algorithms/amplitude_estimators/fae.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* Update qiskit/algorithms/amplitude_estimators/fae.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* Update qiskit/algorithms/amplitude_estimators/iae.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* fix annotations

* Add sampler properties

* refactor evaluate_measurements

* deprecate qiskit.pulse.utils.deprecated_functionality in favor of qiskit.utils.deprecation.deprecate_function (#8696)

* deprecate deprecated_functionality

* pylint: disable=cyclic-import

* Add reno

* Include Terra version in deprecation notice

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

* feat: support sum(LinearMixin) (#8722)

* feat: support sum(LinearMixin)

This enables the use of `sum(...)` for subclasses of the `LinearMixin`
class. It also adds the reflective operand dunder methods `__radd__` and
`__rsub__`.

* Add crossreferences to release note

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

* set shots on fae sampler

* cache circuits during estimate

* Change algos estimate

* Change from run_options ro options

* remove circuits cache list

* Update qiskit/algorithms/amplitude_estimators/ae.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* Update qiskit/algorithms/amplitude_estimators/ae_utils.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* change slice

* Get shots from metadata

* Update qiskit/algorithms/amplitude_estimators/iae.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* Rearrange annotation None

* Update qiskit/algorithms/amplitude_estimators/ae.py

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

* Fix deprecation msg

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: dlasecki <dal@zurich.ibm.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Max Rossmannek <oss@zurich.ibm.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-24 00:24:10 +00:00
dlasecki 4c1042e4cc
Quantum Phase Estimation algorithms with primitives. (#8666)
* Added samplers in place (draft)

* Implemented unit tests with primitives.

* Implemented unit tests with primitives. Updated typhints.

* Added exception handling for sampler.

* add pending deprecation msgs

* Added code review suggestions.

* Added release notes.

* Added release notes.

* Removed shots argument.

* Implemented CR suggestions.

* Removed shots.

* Drafted the usage of EvolutionSynthesis.

* Applied some CR comments.

* Updated reno.

* Extended bound calculation to other types.

* Fixed bound calculation.

* Fixed unitary calculation.

* Made unit tests work.

* Code refactoring.

* Added Mapping; code refactoring.

* Fixed SparsePauliOp handling, reduced use of opflow in new tests.

* Removed opflow from primitive version unit tests.

* Updated reno; removed dead code.

* Added Statevector unit test.

* Added Statevector unit test.

* Changed run_options to options.

* Code refactoring.

* Removed deprecated pe_circuit.

* Made types more specific.

* Lint

* Improved docs for allowed types.

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-23 22:07:06 +00:00
dlasecki 13d93119ff
Implemented TrotterQRTE algorithm with primitives. (#8706)
* Implemented observables_evaluator.py with primitives.

* Added evolvers problems and interfaces to time_evolvers package.

* Mostly updated trotter_qrte.py to use primitives.

* Added observables_evaluator.py that uses primitives.

* Added observables_evaluator.py that uses primitives.

* Updated trotter_qrte.py to use primitives.

* Updated imports

* Updated typehints and limited use of opflow.

* Updated typehints and limited use of opflow.

* Removed files out of scope for this PR.

* Added annotations import.

* Added trotter_qrte.py with unit tests.

* Refactored trotter_qrte.py.

* Added observables_evaluator.py with primitives.

* Added ListOrDict support to observables_evaluator.py.

* Updated trotter_qrte.py unit tests; code refactoring.

* Included CR suggestions.

* Applied some CR comments.

* Applied some CR comments.

* Added reno.

* Added reno.

* Accepting Statevector.

* Added attributes docs.

* Support for 0 operator.

* Code refactoring.

* Updated init.

* Add pending deprecation

* Add pending deprecation for evolvers

* Code refactoring.

* Code refactoring.

* Renamed classes and linked to algorithms init.

* fix docstring

* Improved reno.

* Improved reno.

* Returning variances and shots.

* Code refactoring.

* Updated classes and applied CR suggestions.

* Added reno.

* Reduced use of opflow in tests.

* Black fix.

* Unit test fix.

* Reduced use of opflow.

* Handle empty inputs gracefully.

* Applied CR comments.

* Applied CR comments.

* Updated method names.

* Applied CR comments.

* Eliminated cyclic import.

* Drafted reduced use of opflow.

* Drafted reduced use of opflow.

* Removed use of opflow.

* Code refactoring.

* Addressed CR comments.

* Added more tests for error paths.

* Added Trotter section in algorithms init.

* Changed init.

* Apply suggestions from code review

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

* Co-located TrotterQRTE with time evolvers in docs.

Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-23 20:46:47 +00:00
Luciano Bello cb715a34d9
Fix for `None` in `state_to_latex` latex output (#8273)
* term might be None

* Test

Co-authored-by: Rishabh Chakrabarti <rishacha.dev@gmail.com>

* a better solution

* simpler example

* reno

* rounding

* remove _round_if_close

* black

* revert test

* black

* max_size

* max_size -> decimals

* max_siz=0 -> decimals=10

Co-authored-by: Rishabh Chakrabarti <rishacha.dev@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-23 16:48:12 +00:00
a-matsuo b7d5f4af39
Support `Sampler` in `Grover` (#8647)
* wip added sampler

* added sampler

* fix lint

* assert warns

* fix reno

* Add deprecation

* fix unit tests for pending deprecation

* remove unnecessary jupyter notebook

* add pend.deprecation test

* Update qiskit/algorithms/amplitude_amplifiers/grover.py

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

* added error handling

* fix

* use algorithm error

* fix lint

* fix

* Update qiskit/algorithms/amplitude_amplifiers/grover.py

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

* Update qiskit/algorithms/amplitude_amplifiers/grover.py

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

* filter warnings

* added unittests

* lint

* fix

* fix

* fix

* fix

* fix

* lint

* remove print

* update sampler's options

* changed the shots test to TODO

* lint

* added _prepare_grover in the unittest

* fix test

* changed the code-block in the release note

* Update releasenotes/notes/add-grover-primitives-10f81efdba93703d.yaml

* Update qiskit/algorithms/amplitude_amplifiers/grover.py

* Update qiskit/algorithms/amplitude_amplifiers/grover.py

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-22 23:44:27 +00:00
dlasecki cde535cf3d
Implemented PVQD algorithm with primitives. (#8705)
* Implemented observables_evaluator.py with primitives.

* Added evolvers problems and interfaces to time_evolvers package.

* Mostly updated trotter_qrte.py to use primitives.

* Added observables_evaluator.py that uses primitives.

* Added observables_evaluator.py that uses primitives.

* Updated trotter_qrte.py to use primitives.

* Updated imports

* Added estimator to pvqd.py (draft)

* Updated typehints and limited use of opflow.

* Updated typehints and limited use of opflow.

* Removed files out of scope for this PR.

* Added annotations import.

* Added observables_evaluator.py with primitives.

* Added ListOrDict support to observables_evaluator.py.

* Drafted pvqd.py with the fidelity primitive; type hints updated.

* Accepting fidelity primitive.

* Included CR suggestions.

* Applied some CR comments.

* Applied some CR comments.

* Added reno.

* Added reno.

* Accepting Statevector.

* Added attributes docs.

* Support for 0 operator.

* Implemented pvqd unit tests with primitives; code refactoring.

* Added reno.

* Updated algorithms init.

* Code refactoring.

* Removed old pvqd algorithm and related files.

* Add pending deprecation for evolvers

* Renamed classes and linked to algorithms init.

* fix docstring

* Improved reno.

* Updated classes names.

* Code refactoring.

* Applied CR comments.

* Removed unnecessary files.

* Applied CR comments.

* Black fix.

* Applied CR comments.

* Init updates.

* Reduced number of cyclic import.

* Fix for cyclic import

* Doc fix

* Updated init.

* Added error raising and unit test.

* Apply suggestions from code review

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

* Fixed code example.

Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Co-authored-by: woodsp-ibm <woodsp@us.ibm.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-22 19:06:14 +00:00
Pieter Eendebak 0f688eb305
Fix flipping of gate direction in transpiler for CZ gate (#8625)
* fix flipping of the symmetric cz gate

* complete test

* black

* pylint

* black

* add release notes

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2022-09-22 13:52:08 +00:00
Takashi Imamichi 007cc25bc4
Update `ProbDistribution` and `QuasiDistribution` to store the number of bits if bitstrings w/o prefix are given (#8464)
* Update ProbDistribution and QuasiDistribution to store data as bit-strings

* fix sampler tests

* Revert the internal data from bitstrings to integers

* Store the information of number of bits when bitstrings w/o prefix,
  e.g., "00101", are given.

* update reno

* Revised `num_bits`, comments, and tests.

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

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Paul Nation <nonhermitian@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-22 02:45:05 +00:00
Ryan Hill 418b7cc802
add state_to_latex prefix kwarg (#8461) 2022-09-21 23:37:26 +00:00
Manoel Marques f94647212d
Fix release notes code block format (#8777) 2022-09-21 18:39:24 +00:00
Takashi Imamichi db53e46cb2
Remove `parameters` arguments for `run` method of Primitives (#8684)
* remove `parameters` arguments for `run` method

* fix lint

* update docstring and reno

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-21 15:51:39 +00:00
Luciano Bello 4f650581f2
adding FakeGeneva (#8322)
* conf_geneva

* reno

* adding to the test

* order

* calibration data 2022-07-12 15:40:30+02:00

* calibration from 2022-06-24 23:00:30+02:00

* Update releasenotes/notes/ibm_geneva-5b1e9308dc302e2e.yaml

* remove v1

* reno new

Co-authored-by: Junye Huang <h.jun.ye@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-20 18:55:36 +00:00
Matthew Treinish c0f5ae02a9
Fix handling of holes in physical bits list in Layout (#8767)
* Fix handling of holes in physical bits list in Layout

Previously the behavior of `Layout.add(virtual)` would attempt to select
an available physical bit to pair for the layout. However, the manner in
which this selection was done was buggy and it would potentially skip
over available physical bits on the device and instead add a new
physical bit to the layout. This had unintended consequences for layouts
that added bits in higher numbers first. This commit fixes this behavior
by first checking that we've exhausted all available physical bits from
0 to max bit in layout. Then if there are no holes in the physical bits
in the layout it will add a bit to the top.

Fixes #8667

* Add release note and clarify docstring

* 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-09-20 17:35:45 +00:00
Luciano Bello b454a8dfcb
Add FakeAuckland backend to fake provider (#8467)
* adding FakePerth

* Update releasenotes/notes/ibm_perth-5b1e9308dc302e2e.yaml

* adding FakeAuckland

This PRs adds FakeAuckland based on ibm_auckland.

* V1 removed

* Mock over Fake

* remove V1

* removing v2

* remove v2 name

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-19 13:30:59 +00:00
Luciano Bello 4b5a5bf45e
Add FakeOslo backend to fake provider (#8358)
* adding FakeOslo

* Update releasenotes/notes/fake_oslo-7bba98d7269f959b.yaml

* only v2

* put FakePerth back
2022-09-19 12:01:23 +00:00
Luciano Bello cdfd66ef2e
adding FakePerth (#8344)
* adding FakePerth

* Update releasenotes/notes/ibm_perth-5b1e9308dc302e2e.yaml

* Mock over Fake

* remove V1

* removing v2

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-16 22:45:42 +00:00
Paul Nation e4381c3760
Default set to turn off approximation_degree (#8595)
* Default set to turn off approximation_degree

* Add a release note

* spelling

* convert to upgrade note

* Update releasenotes/notes/turn-off-approx-degree-df3d39eb69f7f09f.yaml

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

* Update releasenotes/notes/turn-off-approx-degree-df3d39eb69f7f09f.yaml

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

* Update releasenotes/notes/turn-off-approx-degree-df3d39eb69f7f09f.yaml

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

* Update releasenotes/notes/turn-off-approx-degree-df3d39eb69f7f09f.yaml

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

* Update releasenotes/notes/turn-off-approx-degree-df3d39eb69f7f09f.yaml

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-16 21:14:03 +00:00
Jake Lishman e76ab71562
Prepare for removal of `tweedledum` as a requirement (#8738)
* Prepare for removal of `tweedledum` as a requirement

This adds the necessary optional-functionality checker
(`HAS_TWEEDLEDUM`), converts all Terra uses of `tweedledum`-dependent
functionality to be gated on lazy checker, and deprecates the implicit
import of `tweedledum`-specific functionality in `qiskit.circuit`.  This
commit does not remove `tweedledum` as a requirement just yet; we are
waiting one Terra release to give downstream users a chance to adjust.

* Fix lint

* Fix import paths

* Fix straggler release note

* Update releasenotes/notes/begin-tweedledum-removal-25bb68fc72804f00.yaml

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-16 19:58:00 +00:00
Iman Elsayed 3ae23373e0
Fix printing an empty PauliList (#7712)
* add num.qubits check to be _truncated_str in pauli_list.py - Resolved Issue #7359

* new file:   fix-empty-string-pauli-list-init-4d978fb0eaf1bc70.yaml
	modified:   ../../test/python/quantum_info/operators/symplectic/test_pauli_list.py

* Added test to test_array_init to test array initialization for empty array

* Run black on test_pauli_list.py

* Update releasenotes/notes/fix-empty-string-pauli-list-init-4d978fb0eaf1bc70.yaml

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

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-16 16:50:02 +00:00
Jake Lishman 02d2d6e705
Allow DAG-node substitution without overriding conditions (#8615)
* Allow DAG-node substitution without overriding conditions

Currently, `DAGCircuit.substitute_node_with_dag` forcibly copies any
condition on the `node` onto all the operations in the replacement DAG.
This style was because the method was originally used by the
basis-translation passes (`Decompose`, `BasisTranslator`, etc), which
did not want to have to worry about the condition.

This model of the condition being a "addition" to a node is now too
restrictive with the move to more dynamic circuits; one cannot
replace an (old-style) conditioned node with a custom instruction or an
`IfElseBlock` that implements the condition internally, for example by
taking the condition bits in the `clbits` field and using the condition
on only a subset of the definition nodes.

This commit does not add any such option to `DAGCircuit.substitute_node`;
a new interface for wire-reordering in the arguments did not appear
quite as clear to me, and this commit can stand alone.

* Inline helper functions for clearer tracebacks on error

* Slightly improve wire-mapping error messages

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-16 02:07:45 +00:00
Jake Lishman 7c04319a8c
Add internal routine for canonicalisation of control-flow builders (#8627)
* Add canonical form for control-flow builders

This adds an internal function for use in tests that puts circuits
constructed with the control-flow builders into a canonical form.  There
are several non-determinstic components to the control-flow builders,
since they internally track their resources with hashmaps, and at the
end pick an arbitrary order to sequence their arguments in.  The order
is not likely to be the same between a circuit constructed manually and
one constructed by a builder, even though they describe the same
dynamics.

For-loops with automatically generated loop variables (the
`with qc.for_loop(indices) as param: ...` form) will also vary between
circuits, as a unique parameter is constructed each time a new one is
requested to avoid collisions.  The canonicalisation routine uses a
shared iterable of parameters that always returns the exact instances in
the same order.  Replacing the loop variable with a new name has no
effect, since it is logically scoped to the loop only and the operation
is effectively lambda-calculus-like alpha conversion.

This canonicalisation routine is very slow and inefficient, so is only
intended for ease in writing tests.  Making the builders always output a
canonical order would add unnecessary overhead to them for most cases,
and the loop-parameter canonicalisation would potentially cause problems
if one control-flow built circuit was nested somehow within another
(such as by `QuantumCircuit.compose`), as the loop variables could
clash (and would violate the canonical form anyway).

* Fix non-deterministic DAGCircuit.__eq__

The bits-in-registers equality check previously constructed a sequence
of `(name, bit_indices)` tuples using the `dict.items()` iterator.  This
is unnecessarily insertion-order dependent for registers (in CPython,
non-deterministic in general).  Instead, we can compare two
dictionaries, which will correctly check key-by-key without needing the
creation order to match.

* Use canonicalisation instead of custom equivalence in builder tests

The builder tests previously used a custom circuit-equality checker,
which somewhat separated them from other circuit-equality tests.  Using
the control-flow aware canonicalisation routine first lets us rewrite
the circuit using simple rules that clearly don't change the semantics
of the circuit, and then use the regular equality checkers.

This swap over turned up a bug in the previous iteration of the tests
(in the "expected" results!), where the bits of two block bodies were
not ordered the same as the arguments to those operations.  This commit
also corrects those.

* Make initial recursive call clearer

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-15 23:54:59 +00:00
dlasecki 8bb1c01a8b
Removes old VarQTE algorithm code (without primitives). (#8750)
* Removed old VarQTE and tests.

* Removed reno

* Updated init.

* Updated init.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-15 22:39:30 +00:00
dlasecki 50f2eaa33e
Adds observable evaluator with primitives. (#8683)
* Added observables_evaluator.py with primitives.

* Added ListOrDict support to observables_evaluator.py.

* Included CR suggestions.

* Applied some CR comments.

* Added reno.

* Support for 0 operator.

* Add pending deprecation

* Code refactoring.

* Code refactoring.

* Improved reno.

* Returning variances and shots.

* Unit test fix.

* Reduced use of opflow.

* Handle empty inputs gracefully.

* Applied CR comments.

* Applied CR comments.

* Eliminated cyclic import.

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-15 20:01:29 +00:00
Daniel J. Egger 4ac8b24af1
Edge coloring for the Commuting2qGateRouter (#8341)
* * Added an edge coloring to the Commuting2qGateRouter.

* * Black and lint.

* * Lint

* * ddt bug fix

* * docs

* * lint

* * Removed unneeded check.

* * Removed wrong test.

* * Updated docstring.

* * Test refactor

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-15 17:01:38 +00:00
Clemens Possel 3cc9c178be
Raise error for missing bounds in optimizer SNOBFIT (#8638)
* Update snobfit.py

Raise error for invalid `None`s in bounds of optimizer SNOBFIT

* Add SNOBFIT test for missing bounds

* Move refactored SNOBFIT test for missing bounds to test_optimizers_scikitquant.py

* Remove obsolete SNOBFIT import

* Add release note

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-14 20:07:18 +00:00
Naoki Kanazawa 69d2994779
Pulse reference mechanism (#8005)
* This commit add reference to schedule block and cleanup data structure of it with DAGSchedule class. Pulse builder call function is also updated to use reference mechanism. Now call function can be called without actual pulse program, which will be later assigned to the schedule through assign_reference method.

* Introduce ref_id instead of using (name, channels) tuple as a key of reference dict. Note that channels can be parametrized, and such dynamic key may break reference during programming. Even though if we update key with parameter assignment, assigned key doesn't work because they are different object, i.e. key is evaluated with "is" thus object id is important. Rather than introducing complicated mechanism to manage this, static ref key provides robust and cleaner solution.

* Add scope to reference manager

reference added to the program is managed with scope. this helps users to address parameters and reference to assign.

* fix parameter scope bug

* add more test

* documentation update

* support regex in get_parameters

* update reference manager implementation

Redefined ReferenceManager as a subclass of mutable mapping. This is the mapping to both schedule and channels.
Parameter management is excluded from the reference and moved to the schedule block.
All parameters including one in subroutines are exposed with .parameters property.

* wording edits

Co-authored-by: Daniel Egger <38065505+eggerdj@users.noreply.github.com>
Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* add details of returned order

* fix bug in reference management

* update reference model

- reference take multiple keys instead of channels
- builder.refer command is newly added
- schedule.blocks returns reference replaced with actual subroutine if assigned
- remove dagschedule and revert to on the fly dag generation
- move reference to own file
- simplify reference manager
- update docs and tests

* add test for special parameter name

* docs update

Co-authored-by: Will Shanks <willshanks@us.ibm.com>
Co-authored-by: Daniel Egger <38065505+eggerdj@users.noreply.github.com>

* update delimiter

* misc updates

* update reference argument (name, **extra_keys)

* update builder command refer -> reference

* update parallel alignment dag generator to consider unassigned reference placed before undefined channels

* add search_parameters method

* cleanup

* reno

* documentation update

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* update parameter collection method not to merge parameter object in different scope.

* avoid overriding existing reference

* update comments about reference policy

* cleanup

* add comment about parent

* Update union of parameters, add some test for expression.

* Switch baseclass to UserDict

* Remove .name setter

* Update parameter logic. Turn scoped_parameters into a method.

* update _get_references logic

* Fix sequential dag generation logic

* add warning for parameter collision

* add test of sequential two edges
Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* fix replace logic

* add explicit validate logic and cleanup constructor of instruction subclasses

* fix test

* add upgrade notice and API doc

* revert return type of parameters

* fix documentation

Co-authored-by: Daniel Egger <38065505+eggerdj@users.noreply.github.com>
Co-authored-by: Will Shanks <willshanks@us.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-14 16:09:06 +00:00
Pedro Rivero ae29802000
Add BaseResult functionality to primitives module (#8091)
* Add BaseResult functionality to primitives module

* Translate tests from pytest to unittest

* Update docstring

* Update __post_init__ docstring

* Add experiments property and update types

* Refactor variable names

* Refactor _field_values

* Finilize docstring

* Add renlease note

* Fix lint errors

* Fix lint docstring errors

* Fix formatting

* Fix variable names

* Remove BaseResult from primitives init and update test imports

* Rename BaseResult to BasePrimitiveResult

* Update qiskit/primitives/base_result.py

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

* Cache properties in base result since child dataclasses are frozen

* Revert "Cache properties in base result since child dataclasses are frozen"

This reverts commit 0d505a1cf1.

* Update experiments type, add decompose method, and validate data types

* Fix lint

* Fix BaseResult post_init docstring

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

* Index BasePrimitiveResult in primitives module __init__

* Add bytes case to TestBasePrimitiveResult

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

* Exclude bytes from possible field types in BasePrimitiveResult

Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
2022-09-14 13:12:41 +00:00
dlasecki b35b18a90f
Time Evolution Framework with primitives. (#8681)
* Implemented observables_evaluator.py with primitives.

* Added evolvers problems and interfaces to time_evolvers package.

* Mostly updated trotter_qrte.py to use primitives.

* Added observables_evaluator.py that uses primitives.

* Added observables_evaluator.py that uses primitives.

* Updated trotter_qrte.py to use primitives.

* Updated imports

* Updated typehints and limited use of opflow.

* Updated typehints and limited use of opflow.

* Removed files out of scope for this PR.

* Added annotations import.

* Applied some CR comments.

* Added reno.

* Accepting Statevector.

* Added attributes docs.

* Add pending deprecation for evolvers

* Renamed classes and linked to algorithms init.

* fix docstring

* Improved reno.

* Code refactoring.

* Black fix.

* Applied CR comments.

* Add deprecation msg to evolvers package

Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
2022-09-13 21:16:35 +00:00
Jake Lishman bcec9a314c
Fix OpenQASM 3 built-ins with classical conditions (#8731)
The `.condition` attribute for `Instruction` instances corresponding to
OpenQASM 3 built-ins (such as `reset` and `measure`) would previously be
ignored.  This now correctly nests them inside a a branching statement
in the exporter, so the condition is preserved.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-13 17:18:45 +00:00
Shelly Garion 780099972c
Add CS, CSdg and CCZ gates to the CNOTDihedral class (#8673)
* add CS, CSdg and CCZ gates to the CNOTDihedral class

* add CS, CSdg and CCZ gates to the CNOTDihedral tests

* add release notes

* fix test following review

* move assert in tests

* handle CCZGate() in dihedral_circuits

* test CSGate(), CSdgGate(), CCZGate()

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-13 02:02:45 +00:00
Max Rossmannek e8001f5448
feat: support sum(LinearMixin) (#8722)
* feat: support sum(LinearMixin)

This enables the use of `sum(...)` for subclasses of the `LinearMixin`
class. It also adds the reflective operand dunder methods `__radd__` and
`__rsub__`.

* Add crossreferences to release note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-09-09 13:00:50 +00:00
Luciano Bello 686ba343cd
deprecate qiskit.pulse.utils.deprecated_functionality in favor of qiskit.utils.deprecation.deprecate_function (#8696)
* deprecate deprecated_functionality

* pylint: disable=cyclic-import

* Add reno

* Include Terra version in deprecation notice

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-09-08 19:57:10 +00:00
Takashi Imamichi 18b38a9123
Add an error check for Sampler (#8678)
* add an error check for sampler

* update

* Update qiskit/primitives/base_sampler.py

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

* remove a duplicate check

* update an error messgage

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2022-09-08 10:38:53 +00:00
Luciano Bello 94904fa00c
Remove deprecated pulse-builder contexts (#8697)
* Remove qiskit.pulse.builder.inline as deprecated in 0.18.0 (2021-07-13)

* remove imports

* remove test

* Remove qiskit.pulse.builder.pad as deprecated in 0.18.0 (2021-07-13)

* reno

* Reword removal note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-09-07 22:52:46 +00:00
a-matsuo 30899cf996
Include primitive's run_options (#8694)
* include primitive's run_options

* rename to get_local_run_options
2022-09-07 08:33:53 +00:00
Edwin Navarro bb5201184b
Move circuit drawer files to `qiskit.visualization.circuit` (#8306)
* Add graph and circuit dirs

* Move files to new folders

* Finishing transition to circuit and graph dirs

* Finish import changes

* Positioning files and setting init entries

* Final tweaks to compatibility and lint

* Reduce to circuit dir only

* Cleanup

* Add qcstyle stub for docs

* Merge main conflicts fix

* Lint

* Change test message

* Fix _directive change

* Fix op.condition reference

* Change to _utils and cleanup

* Lint

* Fix _trim and dag_drawer test

* Allow direct import of text, etc.

* Add comment explaining backwards-compatibility imports

* Add release note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-09-07 01:12:00 +00:00
Ikko Hamamura 6927a8d26b
Default run_options for Primitives (#8513)
* Add run_options to Primitives

* rm unnecessary comments

* initial commit of Settings dataclass

* Revert "initial commit of Settings dataclass"

This reverts commit 96b8479fe4.

* fix lint, improve docs, don't return self

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-05 15:37:43 +00:00
a-matsuo b737fb5e64
Gradients with the primitives (#8528)
* added the gradients with the primitives

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

* add run_options and supported gate

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

* added unittests

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

* lint

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

* fix based on the comments

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

* fix

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

* add spsa gradient

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

* simplify + async

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

* added gradient variance

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

* lint

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

* added the run_options field

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

* fix lint

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

* fix based on comments

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

* wip fix2

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

* fix

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

* lint

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

* fix epsilon and doc

* lint

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

* fix

* Update qiskit/algorithms/gradients/base_sampler_gradient.py

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

* Update qiskit/algorithms/gradients/base_sampler_gradient.py

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

* Update qiskit/algorithms/gradients/base_estimator_gradient.py

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

* Update qiskit/algorithms/gradients/base_sampler_gradient.py

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

* Update qiskit/algorithms/gradients/base_estimator_gradient.py

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

* Update qiskit/algorithms/gradients/base_estimator_gradient.py

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

* change epsilon error

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

* Update qiskit/algorithms/gradients/estimator_gradient_result.py

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

* Update qiskit/algorithms/gradients/sampler_gradient_result.py

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

* add gradient test

* added batch size in spsa gradients

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

* fix

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

* lint

* Update qiskit/algorithms/gradients/lin_comb_estimator_gradient.py

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

* add operator tests

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

* consistent name

* rewrite spsa

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

* use algorithm job

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Takashi Imamichi <imamichi@jp.ibm.com>
2022-09-05 14:05:35 +02:00
Edwin Navarro aca01eb986
Clean up text drawer compression issues (#8588)
* Add barrier labels to mpl and text drawers

* Release note

* Add import

* Lint

* Add barrier labels to latex drawer

* Remove utils changes

* Cleanup

* Fix merge conflict

* Lint

* Remove label property for barriers and snapshots and increase mpl label font size

* First steps

* Fix vert spacing with text between lines

* Fix low compress connections and change tests

* Add tests

* Additonal test

* Lint

* Add back test

* Release note

* Fix typo in release note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-02 23:43:15 +00:00
ElePT 9ddc97da35
Fidelity interface using primitives (#8303)
* fidelity_poc

* init stuff

* simplified design

* unittests

* unittest working

* optional parameters

* typo

* documentation

* Update test/python/primitives/fidelity/test_fidelity.py

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

* Update qiskit/primitives/fidelity/base_fidelity.py

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

* black

* import order in test fixed

* docstring fixed

* Update qiskit/primitives/fidelity/base_fidelity.py

Co-authored-by: dlasecki <dal@zurich.ibm.com>

* context removed

* Reset branch

* Add init

* Fix inits

* lint fixes

* removed abstractmethod label for set_circuits

* added support for setting only one circuit

* new unittest

* Move fidelities to algorithms

* Update interface with new design doc

* Fix docstrings and unit tests

* Add evaluate

* Adapt signature run

* Make job async

* Fix types

* Remove async, cache circuits

* Update evaluate method, replace use of np

* Remove circuits from init

* Add async, tests, update docstrings

* Add default run options

* change names, abstract methods, improve docstrings

* Update docstrings, typing

* Fix style

* Update qiskit/algorithms/fidelities/base_fidelity.py

Co-authored-by: Declan Millar <declan.millar@ibm.com>

* Update qiskit/algorithms/fidelities/base_fidelity.py

Co-authored-by: Declan Millar <declan.millar@ibm.com>

* Make async

* Add FidelityResult

* Update qiskit/algorithms/fidelities/__init__.py

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

* Add to algorithms init

* Rename classes

* Apply review comments

* Update preprocessing

* Update docstrings

* Move run to base class

* Remove left/right params

* Apply reviews steve/julien/hamamura

* Fix typo

* Style changes

* Allow different num.params in circuit 1 and 2

* Fix unittest typo

* Fix black

* Fix docs

* Fix style/docstrings

* Add AlgorithmJob

* Add truncate, fix result docstring

* Completely remove left-right

* Add comments

* Make create circuit public

* Remove empty param distinction

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* change list preprocessing

* Update qiskit/algorithms/algorithm_job.py

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Apply comments Steve

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Update test/python/algorithms/state_fidelities/test_compute_uncompute.py

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

* Style changes

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Apply comments Julien

* Style fix

* Fix bug for lists of numpy values

* Support single circuits

* Support single circuits

* Add fidelity interface using primitives

* Apply reviews

* Fix docs

* Fix docs

* Fix docs

* Fix lint

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Update qiskit/algorithms/state_fidelities/compute_uncompute.py

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

* Update releasenotes/notes/add-fidelity-interface-primitives-dc543d079ecaa8dd.yaml

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

* Update qiskit/algorithms/state_fidelities/__init__.py

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

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

* Update qiskit/algorithms/state_fidelities/base_state_fidelity.py

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

Co-authored-by: Gian Gentinetta <gian.gentinetta@gmx.ch>
Co-authored-by: Gian Gentinetta <31244916+gentinettagian@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: dlasecki <dal@zurich.ibm.com>
Co-authored-by: Declan Millar <declan.millar@ibm.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-02 21:52:48 +00:00
Naoki Kanazawa ce1f8fedbb
Add curve fill control option to pulse drawer (#8658)
* Add fill control option

* reno

* add option description in docstring

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-02 04:34:24 +00:00
Matthew Treinish ab52d8b8bb
Add ResetAfterMeasureSimplification transpiler pass (#8330)
* Add ResetAfterMeasureSimplification transpiler pass

This commit adds a new transpiler pass to simplify resets after a
measurement. This pass when run will replace any reset after a
measurement with a conditional X gate. This is because the reset
operation on IBM backends is implemented by performing a conditional x
gate after a reset. So doing this simplification will improve the
fidelity of the circuit because we're removing a duplicate measurement
which was implicit in the reset. This pass is based on the marz library:
https://github.com/Qiskit-Partners/marz which did the same thing but at
the QuantumCircuit level.

One note is that this pass is basically specific to IBM backends so it's
not added to the preset pass managers. Ideally we'd be able to have the
IBM backends run this as part of the init stage or something to do the
logical transformation early in the compilation. But right now there is
no mechanism to do this (see #8329), so for now having the pass and
letting users specify it in the pass manager directly is the best
option. After #8329 is implemented we can look at adding this pass to
that hook interface in the ibm provider's backends directly so that they
can leverage this optimization whenever they're the compilation target.

* Fix lint

* Tweak wording on release note

* Remove stray debug draw() call

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-02 02:03:56 +00:00
Matthew Treinish 2ab0ae5112
Enable multiple parallel seed trials for SabreSwap (#8572)
* Enable multiple parallel seed trials for SabreSwap

The SabreSwap algorithm's output is quite linked to the random seed used
to run the algorithm. Typically to get the best result a user will run
the pass (or the full transpilation) multiple times with different seeds
and pick the best output to get a better result. Since #8388 the
SabreSwap pass has moved mostly the domain of Rust. This enables us to
leverage multithreading easily to run parallel sabre over multiple seeds
and pick the best result. This commit adds a new argument trials to the
SabreSwap pass which is used to specify the number of random seed trials
to run sabre with. Each trial will perform a complete run of the sabre
algorithm and compute the swaps necessary for the algorithm. Then the
result with the least number of swaps will be selected and used as the
swap mapping for the pass.

* Make parallel case fully deterministic

The parallel trial code was potentially non-deterministic in it's
execution because the way the parallel trials were compared was
dependent on execution speed of the pass. This could result in a
different output if results with equal number of swaps finished
executing in differing amounts of time between runs. This commit
addresses this by first collecting the results into an ordered Vec
first which is then iterated over serially to find the minimum swap
count. This will make the output independent of execution speed of the
individual trials.

* Fix test failures

This commit updates tests which started to fail because of the different
RNG behavior used by the parallel SabreSwap seed trials. For the most
part these are just mechanical changes that either changed the expected
layout with a fixed seed or updating a fixed seed so the output matches
the expected result. The one interesting case was the
TestTranspileLevelsSwap change which was caused by different swaps being
inserted that for optimization level enabled the 2q block optimization
passes to synthesize away the swap as part of its optimization. This was
fixed by changing the seed, but it was a different case than the other
failures.

* Add swap_trials argument to SabreLayout

This commit adds a swap_trials argument to the SabreLayout pass so that
users can control how many trials to run in SabreSwap internally. This
is necessary for reproducibility between systems for the same reason
it's required on SabreSwap.

* Add comment explaining the intermediate Vec usage

* Update layout in new test

* Update releasenotes/notes/multiple-parallel-rusty-sabres-32bc93f79ae48a1f.yaml

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

* Remove intermediate Vec for parallel trials

In an earlier commit we switched the parallel iterator to collect into
an intermediate `Vec` to ensure the output result was deterministic. The
min_by_key() will have a degree of non-determinism for equal entries as
the parallel iterator's threads finish. However, collecting to a Vec
isn't necessary as we can use the index as an element in a 2 element
array we can get the deterministic evaluation and avoid the overhead of
collecting into a `Vec`. This commit makes this change to improve the
performance of the parallel execution path.

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

Co-authored-by: Kevin Hartman <kevin@hart.mn>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-01 22:12:28 +00:00
Ikko Hamamura f1c5f5e272
Remove deprecated methods and arguments in quantum_info (#8510)
* Remove deprecated methods and arguments in quantum_info

* revert pauli.py

* add releasenote

* rm pauli_list argument

* update reno

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-09-01 14:34:58 +00:00
Luciano Bello 69ad6c66d5
Use np.array_split instead of np.split to support uneven splits in spsa._batch_evaluate (#8634)
* Use np.array_split instead of np.split to support uneven splits in spsa._batch_evaluate

* better testing

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

* Update test/python/algorithms/optimizers/test_spsa.py

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

* len of a boolean

* Apply suggestions from code review

* Fix Sphinx ref

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-31 22:04:17 +00:00
Manoel Marques 9195ec183f
Deprecate Algorithms Factorizers and Linear Solvers (#8617)
* Deprecate HHL and Shor

* Deprecate factorizers and linear solvers

* Fix docstrings
2022-08-31 13:42:09 +00:00
Anthony-Gandon 548dae2cb8
Implements two-step tapering (#8590)
* Adds two new methods for the tapering: `convert_clifford` and `taper_clifford`

* Adds two new methods for the tapering: `convert_clifford` and `taper_clifford`.
Adds a corresponding test.

* Make black

* Make lint

* Resolving the duplication and documenting the tapering.

* Add release note.

* Small changes

* Double the OpflowError + Update docstring indent

* Apply suggestions from code review

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-31 03:38:33 +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
Joseph McElroy d163e89cd0
Fix LaTeX drawer on split-filesystem systems (#8629)
* Update circuit_visualization.py

Corrects issue #8542

* Update circuit_visualization.py

* Add release note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-08-29 16:54:15 +00:00
Marc Sanz Drudis 231961d6cf
Steppable Optimizer (#8170)
* All Changes so far

* Revert "All Changes so far"

This reverts commit 871f29ef54.

* All changes again

* tests

* Formated documentation Gradient Descent

* Reviewed Documentation

* Dealing with CALLBACK

* Fixing documentation

* Documentation

* Apply suggestions from code review

Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>

* GD docs

* Fixed format of documentation

* Typo

* Imported files CMAES

* Testing

* Forgot to add nit to result

* Started stopping conditions

* Fixed comments

* Changes

* merge and black

* Fixed documentation

* IDK why docs is missing optimize

* make black

* Updated Documentation

* Updated Documentation

* Remove CMAES and merge

* Removed CMAES

* Learning Rate Class

* Lint

* RENO and unittests

* Removed attribute documentation

* Fixed variable name

* Added Learning Rate

* Fixed unittestt

* Fixes

* Apply suggestions from code review

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

* Fixing utils?

* lint

* Fixed Reno?

* Update releasenotes/notes/steppable-optimizers-9d9b48ba78bd58bb.yaml

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

* Apply suggestions from code review

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

* Fixed documentation typo

* Removed properties

* Apply suggestions from code review

Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>

* Fixed comments

* Learning Rate init

* LearningRate init

* Update qiskit/algorithms/optimizers/utils/learning_rate.py

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

* changes

* changes

* I can't fix the documentation

* Accidentaly merged with an other branch

* remains

Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-29 14:18:20 +00:00
Emilio a511d99c1f
Add CS and CCZ gates (#8583)
* add cs and ccz gates

* add csdg gate

* add gates to equivalence library

* add release note

* fix equivalences

* commit review suggestions

* simplify definitions and add ctrl_state to inverse

* removed unused import
2022-08-29 09:55:24 +02:00
Julien Gacon c008008be2
Fix decomposition for a single qubit and clbit (#8614)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-25 14:54:48 +00:00
Anthony-Gandon d970c46b42
Fix VQD callback not being used (#8576)
* Added support for non-hermitian operators in AerPauliExpectation

Fixes #415

QEOM creates a dictionary of operators to evaluate on the groundstate.
When using the noisy simulators (qasm_simulator or aer_simulator), one
could either use PauliExpectation (with noise) or AerPauliExpectation
(without noise). PauliExpectation works with non-hermitian operators
but internal methods of AerPauliExpectation raised an Error.
This is a workaround to this limitation.
Note that using include_custom=True on qasm allows the VQE to use a
local AerPauliExpectation without using the "expectation" input.
This does not apply to QEOM and one should explicitly define the
"expectation" input of the VQE for it to apply globally.

* Added support for non-hermitian operators in AerPauliExpectation

Fixes #415

QEOM creates a dictionary of operators to evaluate on the groundstate.
When using the noisy simulators (qasm_simulator or aer_simulator), one
could either use PauliExpectation (with noise) or AerPauliExpectation
(without noise). PauliExpectation works with non-hermitian operators
but internal methods of AerPauliExpectation raised an Error.
This is a workaround to this limitation.
Note that using include_custom=True on qasm allows the VQE to use a
local AerPauliExpectation without using the "expectation" input.
This does not apply to QEOM and one should explicitly define the
"expectation" input of the VQE for it to apply globally.

* Add a test case for non-hermitian operators.

* Add a test case for non-hermitian operators.

* Add a test case for non-hermitian operators.

* Update test/python/opflow/test_aer_pauli_expectation.py

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

* Update aer_pauli_expectation.py

Use a generator instead of list

* Update qiskit/opflow/expectations/aer_pauli_expectation.py

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

* Update releasenotes/notes/add-support-non-hermitian-op-aerpauliexpectation-653d8e16de4eca07.yaml

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

* Add a test case for PauliOp

* Change the test cases from using ~StateFn() to using StateFn(, is_measurement=True)

* Fix the formatting

* Working point for QEOM

* Small changes + Release note

* Undesired change

* Undesired change

* Indentation error

* Parenthesis

* Minor changes in docstring

* Minor changes in docstring

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-24 20:29:33 +00:00
dlasecki e6e5ff6ac6
Variational Quantum Time Evolution algorithm. (#8152)
* Fixed requirements-dev.txt

* Fixed some pylint.

* Fixed some pylint.

* Update Documentation variational principles

* updates documentation

* minor documentation

* Added unit tests docs and some package docs.

* Code refactoring.

* Code refactoring.

* Code refactoring.

* Update qiskit/opflow/evolutions/pauli_trotter_evolution.py

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

* Renamed the main folder.

* Code refactoring.

* Update qiskit/algorithms/quantum_time_evolution/variational/calculators/evolution_grad_calculator.py

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

* Code refactoring.

* Update qiskit/algorithms/time_evolution/variational/error_calculators/gradient_errors/error_calculator.py

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

* Code refactoring.

* Lint fixes.

* Code refactoring.

* Code refactoring.

* Code refactoring.

* Code refactoring.

* Code refactoring, docs fixed.

* Code refactoring, docs fixed.

* Code refactoring and docs improved.

* Exposed optimizer tolerance as an argument.

* Exposed allowed imaginary part as an argument.

* Exposed allowed numerical instability as an argument.

* Code refactoring.

* Introduced evolution_result.py class.

* Minor bugfix.

* Integrated evolution result to VarQte algorithms.

* Code refactoring.

* Black formatting fix.

* Fixed signatures.

* Fixed random seed setup.

* Fixed too long lines.

* Deleted unnecessary files.

* Some fixes in test_gradients.py

* Copyright date updated.

* Refactored getting rid of flags.

* Updated unit tests after refactoring.

* Removed a duplicated argument.

* Implemented general Quantum Time Evolution Framework interfaces.

* Updated docs.

* Reno added.

* Improved reno.

* Code refactoring.

* Code refactoring.

* Typehints added.

* Made variational_principle.py stateless.

* Updated copyright years.

* Simplified var_qte.py class.

* Refactored var_qte_linear_solver.py

* Refactored abstract_ode_function_generator.py

* Refactored var_qte_linear_solver.py

* Refactored var_qte.py

* Code formatting.

* ODE solvers and optimizers as objects, not strings.

* Update qiskit/algorithms/time_evolution/evolution_base.py

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

* Code refactoring.

* Introduced evolution problem classes.

* Code refactoring.

* Apply suggestions from code review

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

* Added unit tests.

* Lint fixed.

* Code refactoring.

* Removed error_based_ode_function_generator.py for MVP.

* Code refactoring

* Code refactoring

* Code refactoring

* Code refactoring

* Code refactoring

* Code review changes.

* Removed gradient code for now.

* Evolving observable removed. Evaluating observables added.

* Improved naming.

* Improved folder structure; filled evolvers init file.

* Added Evolvers to algorithms init file.

* Fixed missing imports.

* Code refactoring

* Fixed cyclic imports.

* Extracted ListOrDict.

* Code refactoring.

* Code refactoring.

* Fixed release note.

* Fixed inheritance order.

* Code refactoring.

* Code refactoring.

* Fixed cyclic imports.

* Name fix.

* Updated the algorithm to the latest version of interfaces.

* Code refactoring.

* Adapted unit tests to evolution problem.

* Implemented aux_ops evaluation.

* Fixed position of quantum_instance.

* Added algorithms to algorithms init.

* Imports refactoring.

* Imports refactoring.

* Updated code to the latest gradient framework.

* Code refactoring.

* Imports refactoring.

* Added gradient files.

* Code review addressed. Fixed tests.

* Switched to 1 sampler.

* Added unit tests for expected errors.

* Improved docs.

* Changed folder structure.

* Added test_evolution_grad_calculator.py unit test with bases.

* Updated interfaces.

* Added VarQite unit test with aux ops.

* Added VarQite unit test with aux ops.

* Added VarQrte unit test with aux ops.

* Update releasenotes/notes/add-variational-quantum-time-evolution-112ffeaf62782fea.yaml

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

* Code refactoring.

* Code refactoring.

* Code refactoring.

* Improved docs of variational principles.

* Code refactoring.

* Code refactoring.

* Simplified var principles folder structure.

* Opened VarQte algorithms for field modification.

* Improved Sphinx docs.

* Code refactoring.

* Introduced ode_function_factory.py

* Removed hardcoded rcond.

* Renamed hamiltonian_value_dict.

* Renamed hamiltonian_value_dict.

* Extracted lengthy expected results in tests.

* Updated unit tests.

* Apply suggestions from code review

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

* Apply suggestions from code review

* Extended release notes.

* Removed dead code.

* Improved ode solver types.

* Moved evolve method for now.

* Shortened Var Principles names.

* Updated metric_tensor_calculator.py

* Updated docs

* Removed ordered_parameters.

* Added and corrected code examples.

* Extended unit tests.

* Extended unit tests.

* Extended unit tests.

* Improved init files.

* Improved init files.

* Improved init files.

* Improved init files.

* Improved docs.

* Import fix

* Renamed sle to lse.

* Code refactoring.

* Replaced metric tensor calculator.

* Replaced evolution gradient calculator.

* Code refactoring.

* Removed evolution_grad_calculator.py

* Removed evolution_grad_calculator.py

* Evolution grad calculator removal; code refactoring; dirty bug fix.

* Added docs.

* Code refactoring

* Improved performance of evolution grad.

* Improved performance of evolution grad, code refactoring; bug fixed.

* Improved LSE solver handling.

* Improved docs.

* Unindented reno

* Mitigated some cyclic imports.

* Unindented reno

* Improved docs

* Lint resolutions

* Fix some line-too-long in tests

* Fixed lint.

* Fixed lint.

* Apply suggestions from code review

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

* Code review changes.

* Added reno for a bug fix.

* Fixed lint.

* Updated docs.

* Moved lse_solver to ODE factory.

* Made ODE factory optional and defaults set.

* Added expectation method argument and set defaults to PauliExpectation.

* Limited supported methods for real_time_dependent_principle.py.

* Fix imports.

* Updated docs.

* Implemented the Forward Euler ODE solver. Implemented a unit test.

* Set Forward Euler ODE solver as a default. Updated unit tests.

* Sync with main.

* Exposed ODE number of steps.

* Code refactoring

* Code refactoring

* Code refactoring

* Exposed ode_num_t_steps to the user; reduced default ode_num_t_steps; added ForwardEulerSolver to docs.

* Updated tests.

* Fixed CI.

* Fixed docs.

* Hides OdeFunction from the user.

* Update qiskit/algorithms/evolvers/variational/var_qrte.py

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

* Update releasenotes/notes/add-variational-quantum-time-evolution-112ffeaf62782fea.yaml

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

* Removes unsupported error-based method flag for now.

* Switched num time steps to deltas in ODEs.

* Code refactoring.

* Fixed typhint.

* Switched back to num_steps for ODE.

* Slow tests and code refactoring.

* Code refactoring.

* Removed TD variational principle.

* Apply suggestions from code review

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

* Code refactoring.

* Improved signatures; support for list of parameter values.

* Code refactoring.

* Improved variable name.

* Updated docs.

Co-authored-by: CZ <ouf@zurich.ibm.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: woodsp-ibm <woodsp@us.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-23 15:55:07 +00:00
Naoki Kanazawa 3f9edfc83e
Add logic to return channels to FakeBackendV2 (#8444)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-22 22:35:42 +00:00
Edwin Navarro 93e2fc52f9
Add barrier labels and display in 3 circuit drawers (#8440)
* Add barrier labels to mpl and text drawers

* Release note

* Add import

* Lint

* Add barrier labels to latex drawer

* Remove utils changes

* Cleanup

* Fix merge conflict

* Lint

* Remove label property for barriers and snapshots and increase mpl label font size

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-19 15:49:15 +00:00
Jake Lishman 26ba58ad54
Fix QuantumCircuit.compose within control-flow scopes (#8570)
* Fix QuantumCircuit.compose within control-flow scopes

Previously, `QuantumCircuit.compose` with `inplace=True` would insert
the appended instructions outside the scope due to unchecked use of
`QuantumCircuit._append` (and direct modification of the `data`
attribute).  This now respects any active control-flow scopes.

Using `front=True` in conjunction with `inplace=True` within a
control-flow scope has no clear meaning, and so the behaviour is
forbidden.  Emitting a new circuit (`inplace=False`) while in an active
scope would produce a broken circuit - the active scope would need to be
cloned to ensure equivalence, but it wouldn't be part of any
Python-managed context, so the scope could never be closed.

* Finish writing documentation sentence

* Add missing docstring in test

* Add missing Sphinx directive

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-18 13:55:39 +00:00
Jake Lishman a0964c10aa
Fix QPY serialisation of ControlledGate with open controls (#8571)
* Fix QPY serialisation of ControlledGate with open controls

Previously, an incorrect definition and name would be re-instated on
QPY deserialisation of a `ControlledGate` instance with open controls.
The base name would include the dynamic `_o{ctrl_state}` suffix, causing
the suffix to later be duplicated, and the definition would duplicate
the logic that added the open controls.  This fixes both by stripping
the suffix on re-read before it is assigned, and serialising only the
"11...1" state definition, since this is what is required and stored by
`ControlledGate`.

* Add QPY backwards compatibility test

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-18 12:34:08 +00:00
Emilio 4fac3f4bea
accept single qubit in initialize to fix #8408 (#8463)
* accept single qubit in initialize

* only call conversion when not iterable

* add single Qubit to if statement

* add test

* fix imports

* modify docs; add release note

* accept single qubit in state preparation

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-16 16:07:13 +00:00
Israel F. Araujo 82c85d859b
Fix global phase in inverse of UCGate (#8508)
* Defines the inverse of the global phase

The inverse of UCGate is defined by simply inverting the existing decomposition, but the inverse of the global phase was missing.

* Tests the UCGate.inverse() function

* Lint

* Seed for building the matrices

* Replace `unitary_simulator` by using `qiskit.quantum_info.Operator`.

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

* Import `Operator` class

* Release notes

* Lint

* Test the phase of isometry decomposition

* Removes the `prelude` from the release notes file

* Replaces `matrix_equal` with `np.allclose`

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2022-08-14 17:37:03 +02:00
Alexander Ivrii 19fdd32aff
Adding Cliffords to QuantumCircuits as Operations (#7966)
* Adding Clifford to a QuantumCircuit natively; adding some tests; adding a preliminary Clifford optimization pass

* Making Instruction.condition into a property

* improving tests

* adding release notes

* A few changes based on review

* Removing definition from Operation interface. Instead adding
HighLevelSynthesis transpiler pass, and incorporating it into the preset
pass managers

* minor lint fix

* moving all of broadcast functionality to a separate file; removing broadcast from Operation interface and in particular from Clifford

* moving HighLevelSynthesis pass from Decompose to QuantumCircuit.decompose; slightly changing Decompose pass to skip nodes with definition attribute

* Fixing broadcasting for Cliffords

* making sure that transpile decomposes cliffords

* lint

* As per code review, replacing x._direction by getattr(x, '_direction', False)

* Removing condition from Operation API.

Removing previously added getter and setter to instruction.py.

As per code review, starting to replace condition getters and setters.
For now, only dagcircuit and circuit_to_instruction.

* pass over condition in transpiler code

* more refactoring of condition

* finishing condition pass

* minor fixes

* adding OptimizeClifford pass to __init__

* Improving release notes

* considering DAG nodes in topological order; adding a simple test to see this

* typo

* release notes fixes

* Adding TODO comment to HighLevelSynthesis pass

* another attempt to fix docs build

* Fix based on code review

* Only construction Operator from Instruction (as before) and from Clifford (for backward compatibility)
2022-08-10 19:41:43 +00:00
Ikko Hamamura dadacb8050
Improve the performance of taper in opflow (#8410)
* reduce

* add releasenote

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-10 15:09:00 +00:00
Alexander Ivrii f48aab2b01
Refactoring commutativity analysis and a new commutative inverse cancellation transpiler pass (#8184)
* experimenting with transpiler passes

* removing some prints

* minor cleanup

* Improving external test file

* Simplified commutative inverse cancellation pass

* black

* Removing duplicate code from CommutationAnalysis and DagDependency

* black and lint

* commutation_checker cleanup

* Adding tests for CommutativeInverseCancellation pass

The tests are adapted from CommutativeCancellation, InverseCancellation
and issue 8020.

* Removing external test python file

* Update qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py

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

* Update qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py

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

* Removing the use of dag node classes and taking args and op separately

* Removing runtime import

* removing unnecessary pylint-disable

* moving commutation_checker to qiskit.circuit and improving imports

* Adding commutative_checker tests

* running black

* linting

* Adding corner-cases to test_commutative_inverse_cancellation

* release notes

* black

* release notes tweaks

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-10 13:58:15 +00:00
Ikko Hamamura db612922aa
Add run method to primitives (#8382)
* add submit method

* add method docstrings

* deprecate context manager

* [new feature] append

* deprecate __call__

* optional in constructor

* Introduce PrimitiveFuture

* refactoring

* ping Sphinx<5.1

* Extend Job

* JobV1

* rename submit to run

* rm PrimitiveFuture

* fix lint

* add tests

* add releasenote

* rm _submit and add _run

* use dict for ids

* run cannot take integer indices

* deprecate args in constructor

* refactoring

* Update qiskit/providers/job.py

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

* Update qiskit/primitives/base_sampler.py

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* refactoring

* support parameters in run

* fix docs (args order)

Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
2022-08-09 08:33:31 +00:00
Jun Doi 6a5adf20e8
Changing aer_simulator_statevector checking method (#8411)
* checking backend name by checking string is included

* added release note
2022-08-08 19:26:25 +00:00
Julien Gacon 2bab09c1aa
Fix ``ParameterExpression.is_real`` if ``symengine`` is installed (#8456)
* Fix is_real on ParameterExpression

* typo in reno

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-04 22:50:36 +00:00
Julien Gacon 37057987f4
Projected Variational Quantum Dynamics (#8304)
* pvqd dradt

* update as theta + difference

* black

* refactor test

* update to new time evo framework

* add gradients

* use gradient only if supported

* polishing!

- reno
- remove old pvqd file
- allow attributes to be None
- more tests

* fix algorithms import

* changes from code review

* add more tests for  different ops

* refactor PVQD to multiple files

* remove todo

* comments from review

* rm OrderedDict from unitary

no idea why this unused import existed, that should be caught before this PR?

* changes from code review

* remove function to attach intial states

* include comments from review

- support MatrixOp
- default for timestep
- update reno with refs
- test step and get_loss

* make only quantum instance and optimizer optional, and use num_timesteps

* fix docs

* add comment why Optimizer is optional

* use class attributes to document mutable attrs

* rm duplicate quantum_instance doc

* fix attributes docs

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-08-04 21:43:51 +00:00
Shelly Garion 82245c0141
Add optimization for TwoLocal synthesis when entanglement='full' (#8335)
* add optimization for CX subcircuits with full entanglement

* preserve the option of full_explicit

* add a test that full and full_explicit are the same

* add docstring to the test

* minor lint fix

* add comments following review

* minor fix: add default value None to entanglement_gates

* minor lint fix

* add the option reverse_linear, and remove full_entanglement

* add optimization for CX subcircuits with full entanglement

* preserve the option of full_explicit

* minor lint fix

* add comments following review

* add the option reverse_linear, and remove full_entanglement

* return extra space lines

* update comment

* add documentation in TwoLocal

* update documentation in TwoLocal

* add documentation in RealAmplitudes. Change default eantanglement to reverse_linear

* fix block size in reverse_linear

* enhance tests for reverse_local

* add documentation in EfficientSU2. Change default entanglement to reverse_linear

* reduce the nuber of tests of reverse_linear vs. full

* add a test that ZZ feature map works with reverse_linear entanglement

* style update

* add release notes

* add entanglement='pairwise' to the docs of TwoLocal

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
2022-08-02 16:32:40 +00:00
Edwin Navarro 244fd840a8
Fix MPL and LaTeX circuit drawer when `idle_wires=False` and there are barriers (#8321)
* Fix idle_wires False with barrier

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
2022-07-28 23:37:43 +02:00
Julien Gacon 625ff98f68
Fix converting VectorStateFn to a CircuitStateFn (#8405) 2022-07-27 17:19:44 +00:00
Polly Shaw 28802cf057
Fixes #7078: Change prefix of MemorySlot channel in Qasm Instructions (#8166)
* Fixes #7078: Add is_schedulable property to qiskit.pulse.Channel and don't apply a delay to it if True

RegisterSlot and MemorySlot have this set to False. The default implementation in Channel sets it to True.

* Fixes #7078: Introduce ClassicalIOChannel as a subclass of pulse.Channel

RegisterSlot, MemorySlot and SnapshotChannel now derive from this class. There are some tests to fix.

* Fixes #7078: Make Acquire.channels only return the channel

* Fixes #7078: Execute black

* Fixes #7078: Put slots in new tuple in acquire

* Fixes #7078: Add is_schedulable property to qiskit.pulse.Channel and don't apply a delay to it if True

RegisterSlot and MemorySlot have this set to False. The default implementation in Channel sets it to True.

* Fixes #7078: Remove is_schedulable property from qiskit.pulse.channel

* Fixes #7078: Put checks in SetPhase, ShiftPhase and SetPhase. Remove check from Delay.

* Fixes #7078: Add unit tests for restrictions on Classical IO channels

* Fixes #7078: Add unit tests for abstract nature of ClassicalIOChannel

* Fixes #7078: Tidying after self-review.

* Fixes #7078: Add release note.

* Fixes #7078: remove typo

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
2022-07-27 01:57:56 +00:00
Matthew Treinish f8681295dd
Fix handling of numpy arrays for indices in marginal_distribution (#8288)
* Fix handling of numpy arrays for indices in marginal_distribution

This commit fixes an issue with the marginal_distribution() function
where it would previously error if a numpy arrray of ints was passed in
for the indices parameter. This was caused by the input validation
looking for empty input by checking `not indices` which isn't valid for
numpy arrays. This commit fixes this by adjusting the check for
empty lists to work with any sequence input.

Fixes #8283

* Update releasenotes/notes/fix-numpy-indices-marginal-dist-45889e49ba337d84.yaml

Co-authored-by: Jim Garrison <jim@garrison.cc>

Co-authored-by: Jim Garrison <jim@garrison.cc>
2022-07-25 15:12:46 +00:00
Julien Gacon 1312624309
Fix `EvolvedOp.to_instruction` (#8384)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-21 08:38:55 +00:00
Julien Gacon d9af1d1f7a
Fix `Optimizer` reconstruction from `settings` (#8381)
* fix settings in optimizers

* add reno

* don't duplicate args

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-20 19:26:39 +00:00
Adenilton Silva f2c2fe263e
Fix Uc gate global phase (#8231)
* global phase UCGate

* Create global-phase-ucgate-cd61355e314a3e64.yaml

* Update qiskit/extensions/quantum_initializer/isometry.py

* Update qiskit/extensions/quantum_initializer/isometry.py

Co-authored-by: ewinston <ewinston@us.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-19 18:41:06 +00:00
Kevin J. Sung 77535607f9
Fix bug in circuit decompose (#8364)
* fix bug in circuit decompose

* add test

* Update test/python/circuit/test_circuit_operations.py

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>
2022-07-19 17:36:36 +00:00
Matthew Treinish 6dd0d69ec9
Reimplement SabreSwap heuristic scoring in Rust (#7977)
* Reimplement SabreSwap heuristic scoring in multithreaded Rust

This commit re-implements the core heuristic scoring of swap candidates
in the SabreSwap pass as a multithread Rust routine. The heuristic
scoring in sabre previously looped over all potential swap candidates
serially in Python and applied a computed a heuristic score on which to
candidate to pick. This can easily be done in parallel as there is no
data dependency between scoring the different candidates. By performing
this in Rust not only is the scoring operation done more quickly for
each candidate but we can also leverage multithreading to do this
efficiently in parallel.

* Make sabre_swap a separate Rust module

This commit moves the sabre specific code into a separate rust module.
We already were using a separate Python module for the sabre code this
just mirrors that in the rust code for better organization.

* Fix lint

* Remove unnecessary parallel iteration

This commit removes an unecessary parallel iterator over the swap scores
to find the minimum and just does it serially. The threading overhead
for the parallel iterator is unecessary as it is fairly quick.

* Revert change to DECAY_RESET_INTERVAL behavior

* Avoid Bit._index

* Add __str__ definition for DEBUG logs

* Cleanup greedy swap path

* Preserve insertion order in SwapScores

The use of an inner hashmap meant the swap candidates were being
evaluated in a different order based on the hash seeding instead of the
order generated from the python side. This commit fixes by switching the
internal type to an IndexMap which for a little overhead preserves the
insertion order on iteration.

* Work with virtual indices win obtain swap

* Simplify decay reset() method

* Fix lint

* Fix typo

* Rename nlayout methods

* Update docstrings for SwapScores type

* Use correct swap method for _undo_operations()

* Fix rebase error

* Revert test change

* Reverse if condition in lookahead cost

* Fix missing len division on lookahead cost

* Remove unused EXTENDED_SET_WEIGHT python global

* Switch to serial iterator for heuristic scoring

While the heuristic scoring can be done in parallel as there is no data
dependency between computing the score for candidates the overhead of
dealing with multithreading eliminates and benefits from parallel
execution. This is because the relative computation is fairly quick and
the number of candidates is never very large (since coupling maps are
typically sparsely connected). This commit switches to a serial iterator
which will speed up execution in practice over running the iteration in
parallel.

* Return a 2d numpy array for best swaps and avoid conversion cost

* Migrate obtain_swaps to rust

This commit simplifies the rust loop by avoiding the need to have a
mutable shared swap scores between rust and python. Instead the obtain
swaps function to get the swap candidates for each layer is migrated to
rust using a new neighbors table which is computed once per sabre class.
This moves the iteration from obtain swaps to rust and eliminates it as
a bottleneck.

* Remove unused SwapScores class

* Fix module metadata path

* Add release note

* Add rust docstrings

* Pre-allocate candidate_swaps

* Double swap instead of clone

* Remove unnecessary list comprehensions

* Move random choice into rust

After rewriting the heuristic scoring in rust the biggest bottleneck in
the function (outside of computing the extended set and applying gates
to the dag) was performing the random choice between the best candidates
via numpy. This wasn't necessary since we can just do the random choice
in rust and have it return the best candidate. This commit adds a new
class to represent a shared rng that is reused on each scoring call and
changes sabre_score_heuristic to return the best swap.

The tradeoff with this PR is that it changes the seeding so when
compared to previous versions of SabreSwap different results will be
returned with the same seed value.

* Use int32 for max default rng seed for windows compat

* Fix bounds check on custom sequence type's __getitem__

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

* Only run parallel sort if not in a parallel context

This commit updates the sort step in the sabre algorithm to only run a
parallel sort if we're not already in a parallel context. This is to
prevent a potential over dispatch of work if we're trying to use
multiple threads from multiple processes. At the same time the sort
algorithm used is switched to the unstable variant because a stable sort
isn't necessary for this application and an unstable sort has less
overhead.

Co-authored-by: Kevin Hartman <kevin@hart.mn>
2022-07-19 15:34:38 +00:00
Daniel J. Egger 40668f04b5
Tensored fitter (#8345)
* This PR adds a method subset_fitter to the TensoredMeasFitter in Terra. The 
subset_fitter provides a new fitter by reordering the calibration matrices in the internal 
list of the fitter.
2022-07-15 21:21:56 +02:00
Julien Gacon 38d1ef8293
Fix pairwise entanglement (#8346) 2022-07-15 12:42:27 +00:00
Prakhar Bhatnagar 56501cc673
Switched to `StandardScaler` from deprecated `normalize` in `NaturalGradient` (#8299)
* switched to `StandardScaler`

* Don't mention private methods in reno

* Fix typo

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-13 18:18:23 +00:00
Edwin Navarro 81abc384e4
Add wire_order option to all circuit drawers to allow defining the order of the wires (#8173)
* Add wire_order option - all except conditions working

* Update gate_span

* mpl drawer working with wire_order and reverse_bits

* Fix latex conditions for any wire order

* Adding text change

* Complete text drawer changes

* Lint and reno

* Lint

* More lint

* Fix typos

* Testing, deprecations, typos

* Lint

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-12 17:11:16 +00:00
Matthew Treinish bb4d52a290
Move release note in wrong location and add script to block this (#8320)
* Move release note in wrong location and add script to block this

In #8201 I added a release note as part of the PR which documented the
change in behavior. However, I accidentally committed this file in the
wrong location (by running reno new outside of the repo root). This
meant the file was never actually included in the release notes for the
0.21.0 release. This commit corrects this oversight and moves it back to
the proper location.

However, since this isn't my first time making this mistake and I can
expect that others will make it too in the future. This commit also adds
a new script to detect this and raise an error when release notes are
present outside of the proper location. By running this as part of lint
jobs we'll block this mistake from happening again.

* Fix lint

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-12 12:16:03 +00:00
kUmezawa 925d8cbf4d
Added argsort and sort method to SparsePauliOp (#8016)
* first share

* Remove reverse option

* Apply Lint

* Modify wording

* add release note

* Correct the text

* Correct the text

* Delete words

* Added description of arguments

* Fix typos & update reno

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2022-07-12 10:35:56 +00:00
Naoki Kanazawa d50d99a50c
fix limit_amplitude bug (#8308) 2022-07-07 13:02:22 +00:00
Kevin J. Sung c60d3b8e73
add atol parameter to SparsePauliOp.equiv (#8281)
* add atol parameter to SparsePauliOp.equiv

* lint

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-05 16:27:05 +00:00
Naoki Kanazawa 36c91add58
Avoid direct-CXs in RZX calibration pass (#8276)
* Step1. Add handling for direct CX in RZX calibration builder. PulseError is replaced with User warning not to crash pass manager execution.

* Step2. Cleanup RZX builder. Unreachable errors are removed. Use inplace mode for schedule construction to avoid redundant deep copy. Deprecate unused argument.

* Step3. Reorganize calibration module structure. Usually, in the transpile pass modules, single file contains a single (or similar) pass. RZX builder passes are moved to rzx_builder, Pulse gate pass is moved to pulse_gate and base class is moved to base_builder

* Step4. Write release note

* docs update and turn a cal validation into a separate function. calibration type enum is added for user-friendly error message.

Co-authored-by: Thomas Alexander <talexander@ibm.com>

Co-authored-by: Thomas Alexander <talexander@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-07-04 16:32:27 +00:00
Julien Gacon c796e71e32
Fix ``maxfun`` default in ``L_BFGS`` (#8285)
* Fix maxfun and rm deprecated arg

* update docs, rm "epsilon"

* add reno

* lint

* update reno
2022-07-04 08:57:07 +00:00