* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* fix flipping of the symmetric cz gate
* complete test
* black
* pylint
* black
* add release notes
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
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>
* 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>
* 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>
* deprecate deprecated_functionality
* pylint: disable=cyclic-import
* Add reno
* Include Terra version in deprecation notice
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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)
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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.
* 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>
* 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>
* 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>