Commit Graph

1635 Commits

Author SHA1 Message Date
Naoki Kanazawa f48d81983e
Fix pulse parameter value formatter bug (#11972)
* Fix value formatter bug

* reno

* Comments from review

Co-authored-by: Will Shanks <wshaos@posteo.net>

---------

Co-authored-by: Will Shanks <wshaos@posteo.net>
2024-03-14 17:08:39 +00:00
Matthew Treinish dd802cac41
Oxidize TwoQubitWeylDecomposition (#11946)
* Oxidize TwoQubitWeylDecomposition

This commit is part 1 of migrating the default 2q unitary synthesis to leverage
parallel rust described in #8774, the eventual goal is to be able to
run unitary synthesis in parallel for all the unitary matrices in a
circuit in a single call from the `UnitarySynthesis` pass. This commit
lays the initial groundwork for doing this by starting with the largest
piece of the default 2q unitary synthesis code, the
TwoQubitWeylDecomposition class. It migrates the entire class
to be a pyclass in rust. There is still a Python subclass for it that
handles the actual QuantumCircuit generation and also the string
representations which are dependent on circuit generation. The goal of
this is to keep the same basic algorithm in place but re-implement
as-is in Rust as a common starting point for eventual improvements to
the underlying algorithm as well as parallelizing the synthesis of
multiple 2q unitary matrices.

* Fix typo in closest_partial_swap()

This commit fixes a typo the formula in the function.
This is the same fix from #11953.

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>

* Run black and lint

* Fix potential imaginary component sign flip in determinant

* Run cargo fmt

* Simplify using numpy eigh example comment

* Add missing checks to decompose_two_qubit_product_gate()

* Use rng first trial from Python implementation

To aid in debugging and rule out rng differences causing different
results this commit switches the first iteration of the randomized loop
to have hard coded values that are identical to what the rng in numpy
was returning. It is very unlikely that this will have any impact
because the specific random numbers used shouldn't matter, this is
mostly to just rule it out as a possibility in debugging the remaining
test failures.

* Fix whitespace in error message

* Fix assert check

* Fix missing multiplier on specialized weyl gate

* Fix various mistakes

This commit fixes two fundamental issues in the code. The first is the
rz and ry matrix were being incorrectly constructed for a given angle.
This caused the specializations that were computing the 1q matrices in
the decomposition based on a product with these gates' matrices to
return invalid results. The second issue is for the MirrorControlledEquiv
specialization had the angles backwards for computing the matrix of the
rz gates used in the products for the 1q matrices:

`K1l = K1l @ Rz(K1r)` and `K1r = K1r @ Rz(K1l)` not
`K1l = K1l @ Rz(K1l)` and `K1r = K1r @ Rz(K1r)`

This was a typo from the original transcription.

* Add pickle serialization support for TwoQubitWeylDecomposition

* Remove duplicate conjs increment

* Fix fSim abmb equivalent specialization

* Add specialized test class back

* Use QiskitError for backwards compatibility

* Add release note

* Make explicit specialization private

* Use explicit inheritance from general decomposition (#23)

* Apply suggestions from code review

* Use smallvec for circuit sequence params and qubits

* Use const 2x2 identity array where possible

* circuit() and weyl_gate don't need a mutable self

* Remove unnecessary inline annotations

* Rename Specializations enum Specialization

* Add back specialize() method and deprecate

* Reorganize Python/Rust split to wrap rust instead of subclass

This commit reworks the handoff between python and rust space for the
TwoQubitWeylDecomposition class. Previously the Python side
TwoQubitWeylDecomposition was a subclass of the Rust struct/pyclass of
the same name. This was originally done to deduplicate the the getters
for the attributes. However, because of the overhead associated with
some of the rust getters and needing to do some import normalization to
a numpy array the deduplication wasn't worth the cost.

* Remove unecessary allocations

* Rename DEFAULT_ATOL to ANGLE_ZERO_EPSILON

* Stop obsessing over -0

* Handle enum to int conversion as method

* Cleanup decompose_two_qubit_product_gate()

* Use a trait for trace_to_fid()

* Use an enum instead of string for euler basis

* Fix release note typo

* Improve magic basis transformation functions

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

* Remove eigh() util function

* Revert unecessary changes to callers of TwoQubitWeylDecomposition

* Restore debug logging and add test assertions for it

* Update qiskit/synthesis/two_qubit/two_qubit_decompose.py

Co-authored-by: Lev Bishop <18673315+levbishop@users.noreply.github.com>

* Add specialization to __str__

* Add previous specialized class docstrings as inline rust code comments

* Rename fSim variants and suprress rustc warning about camel case

* Update tests for correct specialization enum name

* Expose specialization enum via private class attr and use for __repr__

---------

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Lev Bishop <18673315+levbishop@users.noreply.github.com>
2024-03-14 13:32:11 +00:00
Seyed Sajad Kahani 8b6e4fe0fe
Fix evolved operator ansatz (#11682)
* Fix handling of empty operators list in EvolvedOperatorAnsatz

* Add test for empty operator list in EvolvedOperatorAnsatz

* add release note for fixing evolved operator ansatz

* Update releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml

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

* add a note to fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml

* Update fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml

* merge two conditions in evolved_operator_ansatz

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

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2024-03-07 14:32:20 +00:00
Jake Lishman 67e0243abd
Remove old graph structure during `EquivalenceLibrary.set_entry` (#11959)
* Remove old graph structure during `EquivalenceLibrary.set_entry`

The previous implementation of `EquivalenceLibrary.set_entry` changed
the equivalence rules attached to particular nodes within the graph
structure, but didn't correctly update the edges, so the graph was no
longer representing the correct data, and queries within
`BasisTranslator` would still use the old equivalence sets.

This correctly clears out the old rules and adds the new structure when
`set_entry` is used.  The inner private variable `_rule_count` is
replaced with `_rule_id`, since it would actually be misleading for its
use to decrement it; this could cause clashes, and what's actually
intended and used is that it's an id for rules.

* Add test with parallel edges
2024-03-06 23:23:03 +00:00
Sebastian Brandhofer 97aa967c8e
Adapt commutation checker to abstract circuits (#11948)
* Update commutation_checker.py

* reno

* new tests

* Update commutation_checker.py

* remove Operator resolution in commutation pre-check

* Update releasenotes/notes/abstract-commutation-analysis-3518129e91a33599.yaml

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

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-03-06 18:56:32 +00:00
Jake Lishman 6ebb7aa577
Fix `Instruction.repeat` with conditionals (#11940)
* Fix `Instruction.repeat` with conditionals

We can't put register conditionals within an `Instruction.definition`
field; the data model of `QuantumCircuit` doesn't permit closing over
registers from within definitions.  This commit moves a condition to the
outer `Instruction` that's returned.

* Avoid 'to_mutable' if not needed

* Add proviso on repeated conditionals in documentation

* Update wording in release note

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

---------

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
2024-03-06 12:18:20 +00:00
Matthew Treinish f4b50fbb2d
Fix performance issue in parsing bit indices in QPY (#11944)
* Fix performance issue in parsing bit indices in QPY

This commit fixes a performance issue in the deserialization of QPY
payloads. Previously when parsing every instruction the deserialization
would build up a dictionary of indices to bits so that when we load the
bit index in the qargs and cargs for each instruction. This mean the
worst case scaling of this section was O(n * m) for n instructions and
m bits, which for very large circuits could end up dominating the time
spent in deserialization. However, this was unecessary work because it
is rebuilding a mapping from index to bit as a dictionary, but that
mapping already existed in the bit lists the circuit is carrying around.
This commit fixes the performance issue by removing the dictionary
generation and just using the bit lists directly.

* Add release note

* Simplify logic
2024-03-04 17:14:19 +00:00
Luciano Bello 4fd7faf242
replace CXCancellation with InverseCancellation (#11937) 2024-03-04 14:40:10 +00:00
Naoki Kanazawa c566b3ffa1
Bug Fix for missing qubit property (#11880) 2024-02-29 23:42:15 +00:00
Matthew Treinish 945fe1dc50
Forward port release notes changes from stable/1.0 (#11819)
* Forward port release notes changes from stable/1.0

In the rush to get 1.0.0rc1 release on time, we missed migrating the
release notes from the root of the notes directory to the 1.0/
subdirectory. Doing this is convenient because it makes it easier to
associate notes with a particular minor/major release which is useful
for navigating potential issues with reno's history scan. This commit
forward ports the state of the stable/1.0 branches release notes to
main. This will make it much easier to differentiate which release notes
are associated with 1.1 instead of 1.0.

* Add reno subsection config
2024-02-29 19:27:36 +00:00
Ian Hincks 4e0de54f97
Fix improper handling of BindingsArray in SamplerPub.coerce() (#11913)
* Fix SamplerPub.coerce too

* Update releasenotes/notes/fix-pub-coerce-5d13700e15126421.yaml

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

---------

Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
2024-02-29 10:09:48 +00:00
Jake Lishman d47a227d98
Fix transpilation of control flow to no hardware (#11907)
Previously we treated `basis_gates=None` the same as `basis_gates=()` in
the hardware check; that is, we treated it as meaning "nothing is
allowed", when the intention (and how it's treated elsewhere) is more
that "everything is allowed."
2024-02-28 19:41:13 +00:00
Alexander Miessen d21127aa5f
Fixing bug in `qcstyle` that modified custom style dict (#11874)
* fixed qcstyle bug that modified style dict, added test

* black

* ensure that the keys in nested_attrs are not overwritten again

* release notes

* Update releasenotes/notes/qcstyle-bug-custom-style-dicts-22deab6c602ccd6a.yaml

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2024-02-28 17:20:59 +00:00
Jake Lishman 244940a10c
Revert "Revert memory-owning `expr.Var` nodes (#11667)" (#11820)
This reverts commit 052d889a7e.
2024-02-26 15:29:02 +00:00
Matthew Treinish 65ab96508f
Fix handling of control flow instructions in convert_to_target() (#11877)
This commit fixes an issue in the convert_to_target() function where it
wasn't looking for control flow instructions in the proper location.
Typically the control flow instructions are put in the
supported_instructions field of the BackendConfiguration, but the
convert_to_target() function was ignoring this field. This commit
updates the function to check supported_instructions for the control
flow instructions. It doesn't more broadly look at
the supported_instructions field, because on other backends this field
is used to list the supported pulse instructions which might have name
conflicts with other instructions and cause issues building a target.

Fixes #11872
2024-02-26 09:47:14 +00:00
Ian Hincks aba7c0fd8a
Fix improper handling of BindingsArray in EstimatorPub.coerce (#11871) 2024-02-26 06:35:18 +00:00
Ian Hincks c92752d4a2
Fix Observables.coerce() for 0-d inputs (#11868)
* Fix Observables.coerce() for 0-d inputs

* force build
2024-02-23 17:35:53 +00:00
Will Shanks 3e6b646a33
Ensure that Parameters compare equal when they have the same hash (#11652)
Previously, only the `Parameter.uuid` was compared, so `Paramemter`
instances with different names could compare equal if they had been
constructed using a common value for the `uuid` parameter (which is
usually not passed explicitly).
2024-02-23 17:28:37 +00:00
Seyed Sajad Kahani 8509d94193
Fix an unchecked condition in InverseCancellation (#11834)
* fix an unchecked condition in self_inverse inversecancellation

* add release note for the bug in inversecancellation

* reformat reverse_cancellation.py to follow the standards

* update fix-inverse-cancellation release note

* add a test for InverseCancellation with self-inverse

* fix a typo in test_inverse_cancellation.py

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

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

* Update releasenotes/notes/fix-inverse-cancellation-self-inverse-e09a5553331e1b0b.yaml

* Revert "Update qiskit/transpiler/passes/optimization/inverse_cancellation.py"

This had a logical error in it and doesn't work.

This reverts commit 0048e8e4ba.

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-22 18:35:10 +00:00
Jake Lishman 9c1accb790
Fix `PropertySet` re-use in `BasePassManager.run` (#11787)
Since the genericised `PassManager`, the `PropertySet` used in the
`WorkflowState` of a pass-manager pipeline was taken directly from the
internal state of the `BasePassManager`.  This is set to a clean
`PropertySet` during the pass-manager initialisation (similar to how it
was in the previous version), but is not reset on subsequent runs.  This
didn't cause problems in the old form because the "iterator" over tasks
in the old form was a new `RunningPassManager` instance.

Failing to generate a clean property set could lead to passes getting
fed old analysis data when the pass manager was used more than once,
leading to miscompilations.
2024-02-22 17:17:17 +00:00
TsafrirA 060cb70441
Fix custom pulse instruction conversion to Qobj. (#11829)
* Possible fix.

* Update releasenotes/notes/fix-custom-pulse-qobj-conversion-5d6041b36356cfd1.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>

* release notes fix

* Add test

---------

Co-authored-by: Will Shanks <wshaos@posteo.net>
2024-02-20 03:54:02 +00:00
Max Rossmannek 05c69cdd64
Expose `PauliList.noncommutation_graph` in public API (#11795)
* refactor: remove duplicate method `SparsePauliOp._create_graph`

* refactor: de-duplicate the `PauliList.group_commuting` logic

* refactor: expose `PauliList.noncommutation_graph`

* docs: add release note

* test: add unittests for noncommutation_graph methods

* fix: remove now unused import

* refactor: parameterize the PauliList.noncommutation_graph test

* test: cover additional phases in noncommutation_graph tests

* docs: document the noncommutation_graph data contents
2024-02-19 14:48:56 +00:00
Elena Peña Tapia 944e20cee1
Fix scheduling units (#11782)
* Fix units

* Add test and reno

* Add support for non-IS units, move test to test_scheduled_circuit.py

* Adapt reno wording
2024-02-15 21:40:38 +00:00
Ian Hincks 172fa04ddb
Add release notes for V2 of the primitives (#11589)
* Add release notes for V2 of the primitives

* Update releasenotes/notes/primitives-v2-df871c0c6ac0b94a.yaml

Co-authored-by: Christopher J. Wood <cjwood@us.ibm.com>

* Add separate release notes for the statevector estimators.

* update base class reno

* fix typo

* Copy example into StaevectorSampler

* Move all renos into one file, as suggested by @mtreinish

* Removed references to privatized classes

* typo

* Modify statevector sampler docs to not talk about SamplerPub

* remove more references to BindingsArray and ObservablesArray

and add Estimator example

* lint

* Apply suggestions from code review

Co-authored-by: Christopher J. Wood <cjwood@us.ibm.com>

* minor fixes from CR

* switch to pub variables instead of inline

* switch to quantum_info types in examples

* remove references to removed BasisObservable type

* do a bit of reorganization and write a migration section

* make the statevectorestimator do the plot in docs

* Apply suggestions from code review

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

* remove comma

* address various minor code suggestions

* switch to get_bitstrings()

* revert accidental removal of V1 sections

* Fix Sphinx module-path imports

* Fix minor syntax errors

* Fix whitespace

* Stop importing docs with automodule

* add raw string directive

* add PrimitiveJob to the public API

* make some of Chris' changes

* rewrap textblocks to < 80 chars

---------

Co-authored-by: Christopher J. Wood <cjwood@us.ibm.com>
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: Jake Lishman <jake.lishman@ibm.com>
2024-02-15 14:21:43 +00:00
Luciano Bello 19c15b7495
bug loading MPL style from the configuration (#11750)
* config path fixing

* reno

* add test

* temp file creation

* Avoid using more internal details in style test

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2024-02-15 14:04:21 +00:00
Shelly Garion ec53b64693
Additions and fixes to qiskit synthesis docs and release notes (#11719)
* add two_qubit_cnot_decompose to docs

* improve TwoQubitWeylDecomposition docs

* update release notes

* add empty lines

* update refs

* improve TwoQubitBasisDecomposer docs

* more docs updates

* minor update to docs

* minor fix

* updates following review

* add docstring to two_qubit_cnot_decompose

* fix return type

* minor fix

* add args to two_qubit_cnot_decopose

* Add backtick

* update back return type

* add two_qubit_cnot_decompose returns

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-02-12 09:06:06 +00:00
Matthew Treinish 21be91c067
Fix qpy.dump()'s use_symengine when passed a truthy object (#11730)
This commit fixes an issue in the qpy dump() function's use_symengine
kwarg. When a user provided a truthy value that wasn't the literal
`Truth` boolean object the generated qpy payload would be corrupted.
That's because the check that assigns the encoding key in the file
header was unecessarily checking for the literal ``True`` object instead
of a object that evaluated to true. This was causing the header to say
it was using a sympy encoding, but then all the checks that were
encoding the data were evaluating true and setting symengine data. This
would cause a failure on reading the qpy payload when the parameter
expressions were parsed as it would try to load the binary symengine
encoding with the sympy parser.
2024-02-07 08:53:55 +00:00
Elena Peña Tapia 84f0d9bf7c
Remove provider-specific fake backends,`FakeProvider` class and related tools in 1.0 (#11376)
* Remove provider-specific fake backends, fake provider and related tools

* Add release note

* Remove sneaky fake generic

* Fix lint

* Fix typo, manifest and attempt to fix visual tests

* Fix seed in visual tests, change imports

* Remove deleted files and remove FakeBackend mentions from examples in API docs

* I'm sorry I'm at the point where I confuse 1s and 5s.

* Fix skip message when aer isn't installed

* Skip fake backend test with aer on windows

* Revert windows skip and limit v2 backend size

The underlying cause of the windows failures were actually much larger
performance issues in aer's `NoiseModel.from_backend()` constructor
method when run with a BackendV2 instance. This is causing the
`NoiseModel` construction for `GenericBackendV2` to take a great deal of
time and use up all the memory we have available in the windows VMs in
CI. To avoid this issue in the short term until a fix can be added to
aer this commit just limits the size of the backend v2 examples we run
to prevent resources problems in CI.

* Avoid all to all connectivity in fake backend tests

The aer noise model construction was an artifact of using all to all
connectivity in the test. Using a more sparse connectivity alleviates
the performance issues. This commit switches to use a ring graph and
restores the larger qubit count backends.

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 19:27:05 -05:00
Jake Lishman 4c410ed0bb
Effect final removals from Qiskit 1.0 (#11711)
* Effect final removals from Qiskit 1.0

This is a roll-up of a bunch of extant deprecation warnings that were
spotted in the 1.0 branch just before its release.  All of these are
trivial removals.

There remain one or two pending deprecations, but it's too late to do
anything about those.  There are also a couple of deprecations in the
older timeline drawer for features that are still used in documentation,
so I've just left in place.

* Remove unsed import

* Remove tests of deprecations

* Remove ClassicalRegister.qasm too

* Remove unused imports

* Update releasenotes/notes/rollup-removals-ce8326ea90c0ad99.yaml

* Remove stray autosummary for removed pass

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 22:04:16 +00:00
Alexander Ivrii 208a76e0e8
Update `gate.inverse()` to return `AnnotatedOperation` (#11593)
* changing control method for gate and annotated op

* adding argument annotated to all control functions

* formatting

* lint

* controlled library gates when annotated=True and tests

* release notes

* making sure all control functions have similar signature

* first pass over inverse

* additional merge fixes and improvements

* release notes

* improving comments, reno, and adding a few tests

* minor

* docs fix: disembiguating Instruction

* Update qiskit/circuit/library/basis_change/qft.py

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

* Update qiskit/circuit/instruction.py

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

* Update qiskit/circuit/instruction.py

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

* removing type hint: it's well-explained in the docstring comment anyway

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 17:50:53 +00:00
Alexander Ivrii 86a707e8a9
Fix qpy support for Annotated Operations (#11505)
* clifford qpy support + test

* release notes

* cleanup: checking if instruction is of type Instruction

* qpy support for annotated operations

* tests and release notes

* changing qpy format for floating-point numbers; updating tests

* minor

* fixes

* documenting qpy version 11 changes related to annotated ops

* bumping qpy version to 11

* changing to version 11 for annotated operations

* Update qiskit/qpy/binary_io/circuits.py

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

* exporting AnnotatedOperation + modifiers from qiskit.circuit

* minor

* qpy_compat test

* release notes fix?

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 17:38:18 +00:00
Jake Lishman 9e4ecb9631
Fix documentation build (#11706)
A recent commit merged with a release note with invalid rST in a release
note.  Our docs build currently sets the `branch` of the release notes
for the newest notes to be `main`, which causes new release notes in PRs
to be skipped during the PR CI, allowing potentially bad notes through.
2024-02-01 11:14:30 -05:00
Will Shanks 58188defdd
Remove pulse scoped_parameters and search_parameters (#11692)
* Remove pulse scoped_parameters and search_parameters

The `scoped_parameters` and `search_parameters` methods have been
removed from the `ScheduleBlock` class. These methods returned
`Parameter` objects that partially linked to the parameters in the
`ScheduleBlock` instance but assigning values using these objects did not
work correctly. Users should use `ScheduleBlock.parameters` instead and
iterate through `ScheduleBlock.references` and compare to the
`Schedule.parameters` attributes of the subreferences when needing to
distinguish which subroutine a parameter is used in. See
https://github.com/Qiskit/qiskit/issues/11654 for more information.

* Lint and sphinx clean up
2024-02-01 12:29:40 +00:00
Elena Peña Tapia 8c89df21e9
Add generic V1 Fake Backends, replace use in tests (#10952)
* Add generic fake V1 backends, replace use in tests and add reno.

* Update forgotten test

* Fix forgotten imports

* Fix copyright

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

---------

Co-authored-by: Kevin Hartman <kevin@hart.mn>
2024-02-01 05:59:55 +00:00
Jake Lishman d2d0927054
Native OpenQASM 3 importer (#11584)
* Begin work on new OpenQASM 3 importer

* Tidy up public interface construction

* Add load-from-file entry point

* Create public experimental interface

* Credit John

While I've been the author of the Qiskit side of this, John wrote the
separate Rust crates that this depends on, so in principle this
contribution to Qiskit is from both of us.

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Fix lint

* Bump version (git hash) of dependency on openqasm3_parser

The qasm3 crate fails to build on Windows. This commit should fix this.

* Add support for barrier

* Handle measurement with new parser version

Measures, including broadcasted measures, are now supported following
increased support on the parser side. The updated version also includes
changes to a few APIs, and the include-path settings are now
configurable at the entry point, so we switch to those.

* Fix Rust 1.75 code

* Depend on released version of oq3_seamntics

Change crates/qasm3/Cargo.toml to depend on a released version of the parser.
that is the crate oq3_semantics, rather than a commit of the github repo.
All of the commits added since the commit previously specified in the
dependency are either updating the README or tweaking the github actions.

* Add tests of interface successes

* Add dummy library to manifest

* Depend on lastest version, 0.0.7, of openqasm3_parser crates

This commit does two things
* Change the dependency on oq3_semantcis from 0.0.5 to 0.0.7

* Change in build.rs to reflect chang in API for gate modifiers from
`gatecall.modifier()` returning `Option<GateModifier>` to
`gatecall.modifiers()` returning `&[GateModifier]`

* Expand on readme

* Centralise dependencies

* Fix typing and error typing

* Credit Matt

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

* Fix clippy

* Clone using GIL

* Format

* Improve error for unexpected angle

* Add test of gate broadcasting

* Add additional warnings about experimental interface

* Add release note

* Add comment about diagnostics in docs

* Correct release series comment

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 02:21:49 +00:00
Jake Lishman 9dfb668891
Fix `approximation_degree` default in `generate_preset_pass_maanger` (#11695)
* Fix `approximation_degree` default in `generate_preset_pass_maanger`

This brings it inline with `transpile`, as was done in gh-8595.

* Correct release note

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

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 01:41:12 +00:00
Jake Lishman 4a69a21ba0
Support stabilised syntax for OpenQASM 3 `switch` (#11417)
* Support stabilised syntax for OpenQASM 3 `switch`

The OpenQASM 3 project made some changes to the preliminary syntax of
the `switch` statement, merging the final version in
openqasm/openqasm#463.  This commit adds support for the new syntax,
making it available by default while still supporting the experimental
flag to enable the preliminary syntax.  Support for the old flag is
necessary to allow Qiskit to continue to interoperate with other tooling
that still assumes the preliminary format (we know that at least the IBM
QSS compiler is in this position right now), and in general should
hopefully not be too onerous to continue to support.

* Fix lint

* 🇺🇸

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

* Make AST node more descriptive

* Use correct version number

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-02-01 00:20:22 +00:00
Alexander Ivrii 036478664c
Update `gate.control()` to return `AnnotatedOperation` (#11433)
* changing control method for gate and annotated op

* adding argument annotated to all control functions

* formatting

* lint

* controlled library gates when annotated=True and tests

* release notes

* making sure all control functions have similar signature

* suggestions from code review + improved support for annotated.control

* simplifying logic based on code review

* merge conflicts fix
2024-01-31 19:14:11 +00:00
Sebastian Brandhofer eda0435895
Library of Unparameterizable Standard Gates Commutations (#11192)
* library of standard gates commutations

* Changed transpiler passes to use SessionCommutationChecker instead of a new CommutationChecker each time

* addresses code review

* change back to max_num_qubits=3 for commutation resolution

* up

* up

* fix lint

* Update commutation_checker.py

* improved documentation

* black

* Update releasenotes/notes/add-commutation-library-88b7ff65b3d35f9a.yaml

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

* Update releasenotes/notes/add-commutation-library-88b7ff65b3d35f9a.yaml

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

* move the commutation library generation to the root tools directory

* up

---------

Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
2024-01-31 19:02:45 +00:00
Matthew Treinish 588f2df46b
Handle custom operations with overlapping names in QPY (#11646)
* Handle custom operations with overlapping names in QPY

This commit fixes a longstanding bug and limitation in QPY around the
use of custom operations. When QPY encounters a non-standard (meaning not
in Qiskit itself, or a direct instance of Gate or Instruction)
instruction it is not able to represent the exact instance perfectly in
that payload. This is because it would require more code that represents
those classes or data not contained inside Qiskit itself, which would be
an opportunity for arbitrary code execution which is something QPY was
designed to prevent (as it's a limitation with pickle serialization). So
to serialize these objects in a circuit, QPY stores as much data as it
can extract from the data model from the Instruction and Gate classes
and builds a table of custom instructions that will be recreated as
Instruction or Gate instances on deserialization. In all previous QPY
format versions that table was keyed on the .name attribute of the
custom instructions in the circuit, the thinking being the name is a
unique op code during circuit compilation and if there are multiple
circuit elements with the same name they should be the same object. With
this assumption it enabled the QPY payloads generated with repeated
custom instructions to be smaller and more efficient because we don't
need to store potentially repeated data. While that assumption is true
during most of compilation it was ignoring that for a bare quantum
circuit (or during the initial stages of compilation) this isn't
necessarily true and there are compiler passes that canonicalize custom
operations prior to that being true. To make it worse this assumption
was causing conflicts in the QPY payload and cause an inaccurate
reproduction of the original circuit when deserializing a QPY payload in
many cases when custom gates were used.

This commit fixes this limitation by introducing a new QPY format
version 11, which changes the key used in the custom instruction table
to instead of being just the name to `{name}_{uuid}` where each instance
of a custom instruction has a different uuid value. This means that
there are never any overlapping definitions in the table and we don't
have to worry about the case where two custom instructions have the same
name.

Fixes #8941

* Connect version option from interface to writers

* Add negative test for bug in qpy version 10

* Unify uuid logic in version 11
2024-01-31 14:16:43 +00:00
Luciano Bello e0b435ec19
Remove `qiskit.test` (#10998)
* remove qiskit.test

* add test/utils

* reno

* replace

* reajust

* revert test/python/transpiler/test_passmanager_config.py

* randomized

* test/benchmarks

* pylint and order

* missing file

* revert test/python/transpiler/test_passmanager_config.py

* linting

* add new tests

* on the base module

* reno
2024-01-31 14:11:41 +00:00
Matthew Treinish 3b82feadaf
Add version flag to qpy dump (#11644)
* Add version flag to qpy dump

This commit adds a new keyword argument to the qpy.dump() function which
is used to specify a compatibility version of QPY which is the latest
version for the 0.45 and 0.46 version. This basically adds a compatibility
mode for generating QPY files that returns a fixed QPY version that
enables the 0.45 and 0.46 release to load the QPY files generated with
the 1.0 release. The default output doesn't change and dump() will
always return the latest QPY format version by default as this is the
version that gets all the bugfixes and is kept up to date with the
QuantumCircuit class.

As of this commit the compatibility version and the latest version are
the same, both at version 10. However, this flag is being added so that
the interface exists for when we inevitably need to update the QPY
version field for any release in the 1.x major version series. There are
potential PRs in the 1.0 release series that will bump the latest QPY
version to 11 which will change this and those PRs will need to factor
this in when they change the format.

* Export current and compatibility version from qiskit.qpy

* Update test to use QPY_COMPATIBILITY_VERSION

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

* Revise support policy to be a range not just min/max versions

* Add attribute documentation

* Remove hardcoded reference to current QPY_VERSION

---------

Co-authored-by: Will Shanks <willshanks@us.ibm.com>
2024-01-31 00:36:10 +00:00
Elena Peña Tapia 3773444813
Rename `BasicAer` to `BasicProvider` and refactor interface to follow `BackendV2` (#11422)
* Rename `BasicAer` to `BasicProvider`, rename `QasmSimulatorPy` to `BasicSimulator`, remove statevector and unitary simulators.
Replace uses of `BasicAer` with `BasicProvider`, `QasmSimulatorPy` with `BasicSimulator`, `UnitarySimulatorPy` with `quantum_info.Operator` and `StatevectorSimulatorPy` with `quantum_info.Statevector`.

* Migrate `BasicSimulator` interface from `BackendV1` to `BackendV2` (with some extra methods for backward compat.).
Refactor class, rename some internal methods to avoid non-qasm related  use of "qasm", add typehints to module to
improve clarity, update existing typehints. Update tests to expect `BackendV2`.

* Update missing references in qiskit/examples and tests

* Update missing docstrings

* Add future import

* Add type

* Fix lint

* Avoid rebuilding target/configuration when calling property

* Update configuration

* Return methods to original order

* Restore template matching

* Add support for target.num_qubits=None in transpiler pipeline. Set num_qubits in BasicSimulator to None to avoid circuits being transpiled to the simulator's max number of qubits, thus blowing up the size of the computed statevector.

Apply suggestions from Julien's code review

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

* Small refactorings: apply Julien's suggestions, single out unitary gate basis gate, remove properties and status (but keep configuration, as it is required by assemble), change test case (it was based on backendV1).

* Fix style

* Add release note

* Apply inline suggestions from Julien's code review

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

* Add suggestion from Julien's code review

* Fix lint

* Fix docs, test

* (Desperate) attempt to fix docs

* Third attempt to fix docs

* Remove execute from basic simulator tests

* Fix conflicts

* Merge remove-execute, fix conflicts

* Update example docstring

* Apply suggestions from Matt's code review

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

* Remove BasicProvider global instance

* Apply remaining review comments

* Fix tests

Fix forgotten examples

* Update reno

* Fix examples

* Update np random generator

* Use basic simulator instead of basicaer in GenericBackendV2

* Apply code review suggestions

* Remove unused import

* Update releasenotes/notes/refactor-basicaer-to-basicprovider-e27aff9c8e81d26e.yaml

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

* Update refactor-basicaer-to-basicprovider-e27aff9c8e81d26e.yaml

* Update refactor-basicaer-to-basicprovider-e27aff9c8e81d26e.yaml

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-01-30 22:53:27 +00:00
Alexander Ivrii 738d3e4012
Token swapper permutation synthesis plugin (#10657)
* trying to implement permutation synthesis plugin based on token swapper

* improving plugin and tests

* pylint fixes

* exposing seed and parallel_threshold

* release notes

* clarification comment

* improved support for disconnected coupling maps

* unused import

* fix arxiv reference

* minor fix

* fix merge

* more merge fixes

* fixing imports

* updating toml file

* additional fixes

* better way to find the position in the circuit

* bump rustworkx version to 0.14.0

* doc and autosummary improvements

* Update plugin docs configuration

* Remove autosummary for available plugins list

This commit removes the autosummary directives for building the
documentation for the plugin classes. In the interest of time and
combining it with the existing aqc docs we'll do this in a follow up
for 1.0.0 after 1.0.0rc1 has been tagged.

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-01-30 21:31:13 +00:00
Alexander Ivrii d033e8a418
New OptimizeAnnotated transpiler pass (#11476)
* First installment to transpiler pass that optimizes annotated operations on a quantum circuit

* supporting control flow

* lint fixes

* release notes

* suggestions from code review

* option to override recursion

* fast return and style

* fast return only when no need to recurse

* adding test for recurse=False

* docs and reno improvements
2024-01-30 19:09:33 +00:00
Naoki Kanazawa 506098965c
Remove deprecated functions in pulse qobj converter (#11410)
* Removed deprecated functions in pulse qobj converter

* Minor reno suggestion

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-01-30 18:14:58 +00:00
Henry Zou cfb13c98b5
Remove deprecated feature in 0.45 in unroller (#11581)
* Removed unroller

* Additional removals where unroller appears

* Fix lint and remove unroller test

* Fixed test_controlled_gate

* Fix test_preset_passmanagers

* Fixed lint

* Fixed test_circuit_methods

* Fixed lint

* Fixed lint again

* Fixed test_circuit_methods again

* Fixed test_pass_manager_drawer

* Undo change in requirements.txt

* Fix test_controlled_gate

* Updated release note

* Fix test_circuit_methods

* Update releasenotes/notes/remove-deprecated-unroller-4693330708c681e0.yaml

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

* Reverted change to requirements

* Added seperate function for equality check to test_controlled_gate

* Fixed requirements.txt

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2024-01-30 17:37:42 +00:00
Matthew Treinish 9c58064b6a
Fix split barriers leaking during disjoint layout processing (#11655)
* Fix split barriers leaking during disjoint layout processing

This commit fixes an issue in the disjoint layout processing caused by a
shared reference from the input dag to a layout pass to the internal
transformations the layout processing performs. As part of the disjoint
layout processing the input dag needs to be split into smaller dags
for each connected component in the circuit. To enable this any barriers
present in the circuit need to be split up prior to analyzing the
connected components in the dag. A multiqubit barrier doesn't represent
a real connectivity requirement so they need to be split prior to
analysis to ensure they don't factor into the connected component
computation. To faciliate not losing the semantic meaning of the barrier
for the layout analysis of each connected component, the barrier split is
done by first taking an n-qubit barrier and converting it into n parallel
1q barriers with a uuid label applied to it. Then after we split the
circuit into the separate connected components the uuid is used to
identify any components of the same barrier and combine them together.

There were two issues with this approach the first is that the splitting
of the barriers was done on the input dag without copying first. This
causes the input dag to be modified and because in most cases it's a
shared instance which would leak out the barrier splitting if the input
dag was returned verbatim from the pass, which in most cases it would
be. This issue is fixed by ensuring that we re-combine any split
barriers after we've split the dag into it's connected components.
The second issue is the uuid label assignment would overwrite any
existing labels on barriers. While setting labels on barriers is
uncommon for users to do (but still completely valid) this is causing a
bigger issues since #10323 because the transpiler is assigning labels to
barriers it creates internally so they can be removed before the circuit
is returned. This is also fixed in this commit by appending a uuid to
the existing label instead of overwriting it, so we're able to restore
the original label when we recombine barriers.

Fixes #11649

* Always use string uuid

* Add release note
2024-01-30 09:03:05 +00:00
MozammilQ b4582a9705
Add fake generic and modify tests (#10266)
* Added a FakeGeneric BackendV2 backend, this is just a bare minimum working code

* All FakeBackends (like FakeMelbourne, FakeBoeblingen ,etc) is replaced with FakeGeneric

* relocated FakeGeneric in fake_provider directory; replaced if-elif with instruction_dict in fake_generic.py; added support of grid type of coupling map; using lower number of qubits, passed all tests of test_transpiler except one method ( test_parallel_dispatch_lazy_cal_loading )

* added tests for FakeGeneric

* This commit just reformats test_transpiler.py fake_generic.py and test_fake_generic.py

* Update qiskit/providers/fake_provider/fake_generic.py

Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com>

* Update qiskit/providers/fake_provider/fake_generic.py

Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com>

* Update test/python/providers/fake_provider/test_fake_generic.py

Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com>

* Update test/python/providers/fake_provider/test_fake_generic.py

Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com>

* Fix some tests

* Add calibration schedules, fix transpiler tests

* Fix lint

* Refactor, add pulse functionality

* Latest updates to FakeGeneric

* Fix some unit tests

* Fix some unit tests

* Fix tests, lint, refactor

* Remove unused inputs

* Make calibrations optional

* Attempt to speed up test: only add calibrations if option enabled

* Revert some tests to V1

* Refactor FakeGeneric

* Update unit test

* Rename supported instructions to operations, fix tests

Fix test seed

Fix unit test, lint

* Restore vf2postlayout test to V1

Fx vf2 test

* Add pulse test to validate pulse capabilities of new fake backend

Update fake generic

* Update docs, fix lint

* Avoid set for basis gates to allow reproducibility in the error/duration value generation

* Update calibrations

* Fix transpiler test

* Add run test to confirm noise defaults

* Add CZ to basis gates, dtm, update backend names, fix docs

* Remove GenericTarget, add default for basis_gates, remove supported_operations.

* Apply review comments, modify calibrate_instructions to avoid public calibration method.

* New name proposal

* Fix lint and test

* Fix comment

* Apply Kevin's suggestions to extract defaults from class

* Make defaults private

* Fix lint

* Revert previous 3 comments.

* Privatize GenericFakeBackend

* Remove from docs

* Revert privatization

* Apply review comments

* Add reno

* Fix lint

* Apply suggestions from Matt's code review

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

* Apply comments from code review

* Fix lint

* Rename to GenericBackendV2 and adjust docs.

* Fix lint

* Apply comments from code review

* It's not 2023 anymore

* Fix conflict

* Fix test conflict.

---------

Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Elena Peña Tapia <epenatap@gmail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Kevin Hartman <kevin@hart.mn>
2024-01-29 21:36:15 +00:00
Jake Lishman 052d889a7e
Revert memory-owning `expr.Var` nodes (#11667)
This commit is a roll-up reversion of the following commits (PR):

* commit a79e879664 (#10977)
* commit ba161e9294 (#10974)
* commit 50e8137467 (#10944)

This is being done to clear the 1.0 branch of memory-owning `expr.Var`
variables and `Store` instructions.  It should be re-applied once 1.0 is
released.

This wasn't done by individual `revert` operations, because there were
also significant structural changes introduced in those PRs that were
very valid and should be maintained.  Cross-references to `Var` nodes
from other functions have been removed for now.

Making `Var` and `types.Type` hashable is maintained, as is the
`Var.standalone` function, in order to prepare the ground for the
inclusion of proper `Var` nodes in a minor release.
2024-01-29 19:48:57 +00:00