Commit Graph

8786 Commits

Author SHA1 Message Date
Jake Lishman c3b468c832
Fix pass-manager drawing tests for pydot 3.0 (#12775)
* Fix pass-manager drawing tests for pydot 3.0

Two changes in pydot 3 changed the reference output:

1. previously, attributes were sorted before being output.  Pydot 3
   stores them in declaration order.  Here, we sort our attributes to
   maintain the closest behaviour between the two versions.

2. Text fields (like `label`) that contain special characters now have
   their values enclosed in quote marks.  This is a difference between
   the two versions, and we update the reference files to the new
   version since that's what we'll be using in CI.

Qiskit is still compatible with pydot 2 in general usage, it's just our
tests that are a little more tied to the current version.

* Add test-only constraint on pydot
2024-07-16 13:24:21 +00:00
Matthew Treinish 1191fcbc72
Oxidize two qubit local invariance functions (#12739)
* Oxidize two qubit local invariance functions

This commit migrates the two functions in the private module
`qiskit.synthesis.two_qubit.local_invariance` to primarily be
implemented in rust. Since the two_qubit_local_invariants() function is
being used in #12727 premptively porting these functions to rust will
both potentially speed up the new transpiler pass in that PR and also
facilitate a future porting of that pass to rust. The two python space
functions continue to exist as a small wrapper to do input type
checking/conversion and rounding of the result (since the python API for
rounding is simpler). There is no release note included for these
functions as they are internal utilities in Qiskit and not exposed as a
public interface.

* Add docstring to rust function with citation

* Store adjoint magic array statically

* Use arraview1 instead of slice for local_equivalence()

* Fix rustfmt
2024-07-13 02:58:10 +00:00
Elena Peña Tapia 3e2a6e8dcf
Finalize Rust representation for standard gates (#12709)
* Add missing gate definitions

* Reorder gates, following number of qubits and a sort of alphabetical order. Make definitions and matrices consistent with new gate order. Remove C4XGate (second mcx) from list.
2024-07-12 21:07:41 +00:00
Raynel Sanchez 2a2b806c1b
Make `CircuitData` inner data accessible in Rust (#12766)
* Add: `iter()` method to `CircuitData`
- Make `PackedInstruction` public.

* Docs: Remove "rust-native method" from docstring.
2024-07-12 16:54:23 +00:00
dependabot[bot] 59a62d9e2e
Bump thiserror from 1.0.61 to 1.0.62 (#12768)
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.61 to 1.0.62.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.61...1.0.62)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-12 12:38:41 +00:00
Luciano Bello 99032fc042
Remove some of the entries in allow_DeprecationWarning (#12721)
* remove some of the entries

* fixing obscure expcetion handleing for comparison

* remove all the modules

* ignore "Treating CircuitInstruction as an iterable is deprecated" in Aer

* remove allow_DeprecationWarning_module and revert ignore/default

* revert
2024-07-11 15:40:08 +00:00
Shelly Garion 41267ecf5d
Add clifford gates to collect_cliffords (#12750)
* add clifford gates to collect_cliffords

* replace hard coded clifford names by clifford_circuit names

* move import

* replace hard coded clifford names in random_clifford_circuit

* add release notes

* add permutation to collect_clifford gate list
2024-07-11 14:10:27 +00:00
Sebastian Brandhofer a306cb67c8
Barebone generic backend options (#12747)
* Update generic_backend_v2.py

* reno

* Update barebone-backend-option-675c86df4382a443.yaml

* ...

* suggestions from code review

* Update barebone-backend-option-675c86df4382a443.yaml

* tests, typo
2024-07-11 13:40:01 +00:00
Matthew Treinish 99ae318d89
Use rustworkx 0.15.0 features in DAGCircuit.remove_op_node (#12756)
This commit updates the minimum rustworkx version to 0.15.0 to pull in
the new PyDiGraph.remove_node_retain_edges_by_id() method introduced
in that release. This new function is used for the
DAGCircuit.remove_op_node() method instead of the
PyDiGraph.remove_node_retain_edges() function. This new method has much
better scaling characteristics and should improve the performance
characteristics of removing very wide operations from a DAGCircuit.

Fixes #11677
Part of #12156
2024-07-11 11:58:47 +00:00
Luciano Bello 4c9ca6edda
Randomized errors are failing because Aer uses deprecated functionality (#12722) 2024-07-11 11:27:56 +00:00
Luciano Bello 61805c8e16
Some formatting issues in Pauli docs (#12753)
* some formatting issues in Pauli docs

* Update qiskit/quantum_info/operators/symplectic/pauli.py

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

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
2024-07-11 10:36:14 +00:00
Matthew Treinish 1e8205e43d
Avoid Python op creation in BasisTranslator (#12705)
This commit updates the BasisTranslator transpiler pass. It builds off
of #12692 and #12701 to adjust access patterns in the python transpiler
path to avoid eagerly creating a Python space operation object. The goal
of this PR is to mitigate the performance regression introduced by the
extra conversion cost of #12459 on the BasisTranslator.
2024-07-10 13:48:08 +00:00
Alexander Ivrii fa3d6df04f
Adding QFT gate to natively reason about Quantum Fourier Transforms (#11463)
* initial commit

* release notes

* fixing synthesis plugin options

* finalize merge conflicts

* fixing default option values for qft plugins'

* additional tests for qft plugins

* renaming QftGate to QFTGate

* Also renaming Qft to QFT in synthesis method names

* appplying Jake's suggestion from code review

* inlining _basic_definition into _define

* docstring improvements

* more docstring improvements

* renaming do_swaps to reverse_qubits in the new code

* typos

* adding synth_qft_full to __init__

* round of suggestions from code review

* another round of code review suggestions

* fixes

* also adding QFTGate plugins to the docs
2024-07-10 08:27:55 +00:00
Elena Peña Tapia d86f995851
Fix `C3SXGate` `to_matrix` method (#12742)
* Fix c3sx matrix

* Apply Jake's suggestion
2024-07-09 10:25:54 +00:00
Matthew Treinish 4fe9dbc6a8
Use rust gates for ConsolidateBlocks (#12704)
* Use rust gates for ConsolidateBlocks

This commit moves to use rust gates for the ConsolidateBlocks transpiler
pass. Instead of generating the unitary matrices for the gates in a 2q
block Python side and passing that list to a rust function this commit
switches to passing a list of DAGOpNodes to the rust and then generating
the matrices inside the rust function directly. This is similar to what
was done in #12650 for Optimize1qGatesDecomposition. Besides being faster
to get the matrix for standard gates, it also reduces the eager
construction of Python gate objects which was a significant source of
overhead after #12459. To that end this builds on the thread of work in
the two PRs #12692 and #12701 which changed the access patterns for
other passes to minimize eager gate object construction.

* Add rust filter function for DAGCircuit.collect_2q_runs()

* Update crates/accelerate/src/convert_2q_block_matrix.rs

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
2024-07-08 19:47:23 +00:00
Elena Peña Tapia 4867e8aae3
Add Rust representation for most controlled gates (#12659)
* Add C3X (MCX), extend rust tests to multi-controlled gates.

* Add macro to generate multi-controlled gates. Add CU, CU1, CU3, C3SX, C4X, CCZ.

* Kill C4XGate

* Finish adding gates, add circuit construction methods when possible.

* Add import paths, fix drawer test.

* Establish CGates with non-default control states as non-standard in circuit_instruction.rs. Add unit test.

* Fix merge conflicts

* Apply macro on missing gates

* Add RCCX gate and RC3X (RCCCX) gate.

* Make equivalence tests more explicit

* Fix lint

* Modify circuit methods for consistency

* Fix default ctrl state for 3q+ gates, add test for CCZ

* Apply comments from Matt's code review

* Fix ctrl_state logic

* Rename c3x to mcx?

* Brackets didn't match explanation

* Make sure controlled test doesn't use custom ControlledGate instances.

* Rename c4x to mcx in Rust space.

* Return PyResult rather than panic on error

* Add suggestion from Matt's code review

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>
2024-07-08 16:54:00 +00:00
Max Rossmannek 008dde3d56
Improve the performance of the `ProductFormula` synthesizers (#12724)
* [WIP] adds the output argument to the internal atomic evolution

* meta: modernize type hints

* refactor: change callable structure of atomic evolution

This changes the structure of the `atomic_evolution` callable in the
`ProductFormula` synthesis class. This is motivated by the significant
performance improvements that can be obtained by appending to the
existing circuit directly rather than building out individual evolution
circuits and iteratively composing them.

* refactor: deprecate the legacy atomic_evolution signature

* refactor: add the wrap argument to ProductFormula

This can be used to recover the previous behavior in which the single
individually evolved Pauli terms get wrapped into gate objects.

* fix: insert the missing barriers between LieTrotter repetitions

* refactor: align SuzukiTrotter and LieTrotter

* Propoagate deprecation notice

* fix: the labels of wrapped Pauli evolutions

* fix: respect the insert_barriers setting

* docs: add a release note

* Apply suggestions from code review

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

* fix: missing `wrap` forward in SuzukiTrotter

* docs: improve documentation of the `atomic_evolution` argument

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

* docs: also document the deprecated form of `atomic_evolution`

* docs: call out ProductFormula docs in release note

* refactor: change to PendingDeprecationWarning

* refactor: explicitly convert to Gate when wrapping

This is slightly faster than the `.compose`-based operation done
previously as it performs fewer checks. Thanks to @jakelishman for the
suggestion offline.

* Update qiskit/synthesis/evolution/lie_trotter.py

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

* docs: update after pending deprecation

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
2024-07-08 16:25:34 +00:00
dependabot[bot] e5533fde0a
Bump pypa/cibuildwheel from 2.19.1 to 2.19.2 in the github_actions group (#12733)
Bumps the github_actions group with 1 update: [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel).


Updates `pypa/cibuildwheel` from 2.19.1 to 2.19.2
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.19.1...v2.19.2)

---
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github_actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-08 15:30:19 +00:00
Julien Gacon d19224cb38
Add ``PySequenceIndex::convert_index`` to convert Python-like indices to unsigned (#12716)
* Implement convert_index

This allows to convert a Python-like signed index into an unsigned index suitable in Rust notation.

* Jake's comments

- refactor PySeqIndex.with_len to use convert_idx
- cleanup the tests
2024-07-08 13:45:45 +00:00
Elena Peña Tapia 865081e4af
Remove DenseLayout from default pipeline (#12731)
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2024-07-08 09:53:10 +00:00
abbycross e11c4c1bbb
Minor updates to the readme language (#10701)
* capitalize unless in code font

* so many "quantum"s in one sentence

* tighten text

* ambiguous "them"

* code review
2024-07-07 07:56:01 +00:00
Rafaella Vale ee41b187b8
Improved MCXVChain with dirty auxiliary qubits (#9687)
* improved mcxvchain with dirty aux qubits

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* tests for improved mcxvchain with dirty aux qubits

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-Authored-By: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* black

* lint

* Update x.py

* Update test_controlled_gate.py

fix test_mcxvchain_dirty_ancilla_relative_phase
reduce number of controls in test_mcxvchain_dirty_ancilla_action_only and test_mcxvchain_dirty_ancilla_relative_phase

* Update test_controlled_gate.py

* release notes

* removing non existend module

* removing U1 and U2 gates MCXVChain

* black

* using the quantum_circuit.operation(qubit_indices) notation

* mcx

* comments

* lint

* rearranging transpile import

---------

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>
2024-07-07 06:33:44 +00:00
Luciano Bello bb60891a60
Simplify base TestCases (#12720)
* Merge base classes for testing

* Update test/utils/base.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update test/utils/base.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-07-05 11:19:10 +00:00
Luciano Bello 7f1cc7fa98
Revert "set a dummy QISKIT_SETTINGS so tests do not interact with local env (…" (#12723)
This reverts commit 63b459eb12.
2024-07-05 08:36:47 +00:00
Julien Gacon 722a5bc7ef
Oxidize `synth_cnot_count_full_pmh` (#12588)
* port PMH synth to Rust

* Raise an error if the section size is invalid

Co-authored-by: Abdalla01001 <abdall.elhendawy50@gmail.com>
Co-authored-by: Tarun-Kumar07 <tarunkumar00137@gmail.com>

* Review comments of Shelly & Sasha

---------

Co-authored-by: Abdalla01001 <abdall.elhendawy50@gmail.com>
Co-authored-by: Tarun-Kumar07 <tarunkumar00137@gmail.com>
2024-07-04 11:49:35 +00:00
Luciano Bello 63b459eb12
set a dummy QISKIT_SETTINGS so tests do not interact with local env (#12463)
* mock QISKIT_SETTINGS to avoid interfering with my own env

* set a dummy QISKIT_SETTINGS to avoid interfering with local env

* apply to all of them

* revert
2024-07-04 09:15:10 +00:00
Matthew Treinish 2c3ddf1e6f
Optimize DAGCircuit.collect_1q_runs() filter function (#12719)
In the recently merged #12650 a new rust function was added for the
filter function of the collect_1q_runs() method's internal filter
function. As part of this we need to do exclude any non-DAGOpNode dag
nodes passed to the filter function. This was previously implemented
using the pyo3 extract() method so that if the pyobject can be coerced
into a DAGOpNode for later use we continue but if it errors we know the
input object is not a DAGOpNode and return false. However, as we don't
need to return the error to python we should be using downcast instead
of extract (as per the pyo3 performance guide [1]) to avoid the error
conversion cost. This was an oversight in #12650 and I only used
extract() out of habit.

[1] https://pyo3.rs/v0.22.0/performance#extract-versus-downcast
2024-07-03 20:56:55 +00:00
Shraddha Aangiras 51bf91e6eb
Fixed typo in RZZGate example eqn (#12678)
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
2024-07-03 18:04:10 +00:00
John Lapeyre a897d707f7
Accept `Option<&str>` instead of `&Option<String>`, etc (#12593)
* Accept Option<&str> instead of &Option<String>, etc

In a few places, this removes unnecessary object copies.

Accept a wider range of input types, and more idiomatic input types
in a few functions. This affects code added in the gates-in-rust PR.

The great majority of the changes here were obsoleted by #12594.
The original commit has been cherry picked on top of main.

* Remove unnecessary as_ref()
2024-07-03 16:26:15 +00:00
Hwa eed8f45245
Add warning about Tweedledum support in ClassicalFunction (#12652)
* Add warning about Tweedledum support in ClassicalFunction

* Update qiskit/circuit/classicalfunction/__init__.py

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

* Update __init__.py

line break to comply to pylint

---------

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
2024-07-03 15:53:25 +00:00
Shraddha Aangiras 5a4d598966
Fixed typo leading to missing examples (#12689) 2024-07-03 14:24:31 +00:00
Matthew Treinish 9571ea1b3a
Avoid Python op creation in commutative cancellation (#12701)
* Avoid Python op creation in commutative cancellation

This commit updates the commutative cancellation and commutation
analysis transpiler pass. It builds off of #12692 to adjust access
patterns in the python transpiler path to avoid eagerly creating a
Python space operation object. The goal of this PR is to mitigate the
performance regression on these passes introduced by the extra
conversion cost of #12459.

* Remove stray print

* Don't add __array__ to DAGOpNode or CircuitInstruction
2024-07-03 14:00:10 +00:00
Alexander Ivrii 419f40e9e7
fixing synthesis release notes (#12715) 2024-07-03 11:04:47 +00:00
Hirmay Sandesara ba486b739d
Add Uniform State Preparation (#12112)
* Update state_preparation.py

* Update state_preparation.py

* Add files via upload

* Update __init__.py

* Update test_generalized_uniform_superposition_gate.py

* Update test_generalized_uniform_superposition_gate.py

* Update test_gate_definitions.py

* made the format consistent with StatePreparation class

* Put description and arguments in init

* replaced assert with raise ValueError

* small mistake in Returns

* added test cases for ValueError cases

* Update state_preparation.py

* incorporate Steve's helpful suggestions

* small bug

* test_case fix

* function for returning M

* oops..forgot "" marks

* Update state_preparation.py

* removed get methods for num_qubit and M

* added power of 2 condition

* included test function when num_qubits is None

* blacked init

* blacked state_prep

* blacked test_generalized_uniform_superposition_gate.py

* reblacked state_prep

* reblacked test_generalized_uniform_superposition_gate.py

* shorterned max line length

* reblacked state_prep

* reblacked state_prep

* for pyline

* pylinted state_preparation.py

* pylinted test_generalized_uniform_superposition_gate.py

* pylinted test_gate_definitions.py

* pylinted test_generalized_uniform_superposition_gate.py

* Added GeneralizedUniformSuperposition gate

Added GeneralizedUniformSuperposition gate class to the StatePreparation file in Circuit library.

* modified:   releasenotes/notes/generalized-uniform-superposition-gate-3bd95ffdf05ef18c.yaml

* Updated release notes based on Steve's suggestions

* Update release note

* implemented the changes

* fixed error

* Update test_uniform_superposition_gate.py

* Update uniform-superposition-gate-3bd95ffdf05ef18c.yaml

* Update uniform-superposition-gate-3bd95ffdf05ef18c.yaml

* Update qiskit/circuit/library/data_preparation/state_preparation.py

Sounds good!

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

* Update qiskit/circuit/library/data_preparation/state_preparation.py

Okay!

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

* Update qiskit/circuit/library/data_preparation/state_preparation.py

oh that's interesting...I didn't know that. Thanks for the info!

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

* Update releasenotes/notes/uniform-superposition-gate-3bd95ffdf05ef18c.yaml

Ahhh...that's nice!

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

* Update releasenotes/notes/uniform-superposition-gate-3bd95ffdf05ef18c.yaml

You're quite right, will help for others who might look at the code in future.

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

* Update state_preparation.py

incorporated Julien's changes!

* Update test_uniform_superposition_gate.py

Incorporated Julien's optimization suggestion.

* Update uniform-superposition-gate-3bd95ffdf05ef18c.yaml

implemented both reviewers' suggestions.

* Update uniform-superposition-gate-3bd95ffdf05ef18c.yaml

removed SV24

* Update state_preparation.py

* Update state_preparation.py

* Update test_uniform_superposition_gate.py

* Update uniform-superposition-gate-3bd95ffdf05ef18c.yaml

* Update qiskit/circuit/library/data_preparation/state_preparation.py

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

* blacked state_preparation.py

* Update test_uniform_superposition_gate.py

* pylinted state_preparation.py

* removed transpile test_uniform_superposition_gate.py

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
2024-07-03 06:47:55 +00:00
Alexander Ivrii 0f585bd75d
Port `synth_clifford_greedy` to Rust (#12601)
* starting to experiment

* porting code

* messy code porting

* printing statements to enable debugging

* fixes

* fixing phase

* removing some of the printing statements

* fixing inaccuracy for cost computation

* Moving some of the functionality to SymplecticMatrix class

* reducing the number of warnings

* formatting

* replacing expensive adjoint and compose operations for symplectic matrices by significantly cheaper in-place prepend operations

* resolving merge conflicts

* cleanup

* code cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* using fast lookup

* cleanup

* clippy

* including params in gate_seq to avoid mapping

* removing unnecessary inner function

* cleanup

* renaming

* changes on the python side

* reno

* adding error handling

* improved error handling

* removing redundant Ok(Some(...))

* using random_clifford in tests

* reorganizing clifford code

* fixes

* formatting

* improved error handling

* do not panic

* formatting

* Applying refactoring suggestions d/utils.rs from code review

* release notes update

* adding comment
2024-07-03 06:42:41 +00:00
Matthew Treinish bfc69a499c
Use rust gates for Optimize1QGatesDecomposition (#12650)
* Use rust gates for Optimize1QGatesDecomposition

This commit moves to using rust gates for the Optimize1QGatesDecomposition
transpiler pass. It takes in a sequence of runs (which are a list of
DAGOpNodes) from the python side of the transpiler pass which are
generated from DAGCircuit.collect_1q_runs() (which in the future should
be moved to rust after #12550 merges). The rust portion of the pass now
iterates over each run, performs the matrix multiplication to compute the
unitary of the run, then synthesizes that unitary, computes the
estimated error of the circuit synthesis and returns a tuple of the
circuit sequence in terms of rust StandardGate enums. The python portion
of the code then takes those sequences and does inplace substitution of
each run with the sequence returned from rust.

Once #12550 merges we should be able to move the input collect_1q_runs()
call and perform the output node substitions in rust making the full
pass execute in the rust domain without any python interaction.

Additionally, the OneQubitEulerDecomposer class is updated to use
rust for circuit generation instead of doing this python side. The
internal changes done to use rust gates in the transpiler pass meant we
were half way to this already by emitting rust StandardGates instead of
python gate objects. The dag handling is still done in Python however
until #12550 merges.

This also includes an implementation of the r gate, I temporarily added
this to unblock this effort as it was the only gate missing needed to
complete this. We can rebase this if a standalone implementation of the
gate merges before this.

* Cache target decompositions for each qubit

Previously this PR was re-computing the target bases to synthesize with
for each run found in the circuit. But in cases where there were
multiple runs repeated on a qubit this was unecessary work. Prior to
moving this code to rust there was already caching code to make this
optimization, but the rust path short circuited around this. This commit
fixes this so we're caching the target bases for each qubit and only
computing it once.

* Optimize rust implementation slightly

* Avoid extra allocations by inlining matrix multiplication

* Remove unnecessary comment

* Remove stray code block

* Add import path for rust gate

* Use rust gate in circuit constructor

* Remove duplicated op_name getter and just use existing name getter

* Apply suggestions from code review

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

* Simplify construction of target_basis_vec

* Fix rebase issue

* Update crates/accelerate/src/euler_one_qubit_decomposer.rs

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

* Update crates/accelerate/src/euler_one_qubit_decomposer.rs

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
2024-07-03 04:18:40 +00:00
Matthew Treinish 3fb175390d
Fix cargo clippy and rustfmt for Rust 1.79 (#12710)
After the recently merged #12543 when working with Rust 1.79 cargo fmt
makes a small formatting change that rust 1.70 wouldn't and clippy makes
flags a &Vec<_> that should be a slice &[_] instead. This commit makes
these two small chagnes so they're not an issue for people building with
the latest stable version of rust, not just our MSRV.
2024-07-02 19:13:48 +00:00
Julien Gacon c674913e68
Oxidize `synth_permutation_acg` (#12543)
* Move utility functions _inverse_pattern and _get_ordered_swap to Rust

* fix formatting and pylint issues

* Changed input type to `PyArrayLike1<i64, AllowTypeChange>`

* Refactor `permutation.rs`, clean up imports, fix coverage error

* fix docstring for `_inverse_pattern`

Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>

* fix docstring for `_get_ordered_swap`

Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>

* remove pymodule nesting

* remove explicit `AllowTypeChange`

* Move input validation out of `_inverse_pattern` and `_get_ordered_swap`

* oxidization attempt no. 1

* working version!

maybe faster possible...

* move more into rust & fix clones

* layouting & comments

* dangling comment

* circuit construction in rust

* remove dangling code

* more lint

* add reno

* drop redundant Ok(expect())

* Implements Shelly's suggestions

* simplify code a little

---------

Co-authored-by: jpacold <jpacold@gmail.com>
Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
2024-07-02 15:09:30 +00:00
dependabot[bot] 283a880329
Bump thiserror from 1.0.59 to 1.0.61 (#12707)
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.59 to 1.0.61.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.59...1.0.61)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-02 13:06:12 +00:00
dependabot[bot] b399ec30d6
Bump rustworkx-core from 0.15.0 to 0.15.1 (#12708)
Bumps [rustworkx-core](https://github.com/Qiskit/rustworkx) from 0.15.0 to 0.15.1.
- [Release notes](https://github.com/Qiskit/rustworkx/releases)
- [Commits](https://github.com/Qiskit/rustworkx/compare/0.15.0...0.15.1)

---
updated-dependencies:
- dependency-name: rustworkx-core
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-02 13:00:47 +00:00
Matthew Treinish d2ab4dfb48
Enable avoiding Python operation creation in transpiler (#12692)
* Avoid Python operation creation in transpiler

Since #12459 accessing `node.op` in the transpiler eagerly creates a
Python object on access. This is because we now are no longer storing a
Python object internally and we need to rebuild the object to return the
python object as expected by the api. This is causing a significant
performance regression because of the extra overhead. The longer term
goal is to move as much of the performance critical passes to operate in
rust which will eliminate this overhead. But in the meantime we can
mitigate the performance overhead by changing the Python access patterns
to avoid the operation object creation. This commit adds some new getter
methods to DAGOpNode to give access to the inner rust data so that we
can avoid the extra overhead. As a proof of concept this updates the
unitary synthesis pass in isolation. Doing this fixes the regression
caused by #12459 for that pass. We can continue this migration for
everything else in follow up PRs. This commit is mostly to establish the
pattern and add the python space access methods.

* Remove unused import

* Add path to avoid StandardGate conversion in circuit_to_dag

* Add fast path through dag_to_circuit
2024-07-02 08:13:26 +00:00
Guillermo Abad López 05d5b98304
Fix bad Sphinx syntax in several release notes and in API documentaiton (#12604)
* Fix ' into `

* More typos on release notes and on API documentation

* change `self.filter` for `Schedule.filter`

* change `Schedule` -> `ScheduleBlock` in its `filter()` reference
2024-07-01 20:50:06 +00:00
Raynel Sanchez 5db984ae0c
Initial: Expose operation conversion methods to other crates. (#12698)
- Expose `operation_type_to_py`, `operation_type_and_data_to_py`, `convert_py_to_operation_type`, methods to other rust crates.
- Expose `OperationTypeConstruct` struct to other crates.
2024-07-01 19:01:12 +00:00
Guillermo Abad López ed87f2fa50
Add warning for bad `justify` input, in `circuit_drawer` (#12458)
* add warning for bad justify input in circuit_drawer

* change justify after raising error

* typo indentation + improving warning string

* Undo max_lenght limit by autoformater (120 > 105)

* Make lines fullfill 105 max lenght requirement

* Solve regex matching parenthesis problem and don't trigger the wanring for default value

* Change justify default value to "left", & add deprecation wrapper

* Change and extend warnings tests

* Solve various layers of same argument DeprecationWarning

* Added a clarification comment for the solution, about multiple deprecationwarnings

* Ignore cyclic import error, as above

* Apply suggestions from code review

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* Apply suggestions from code review

* Improve DeprecationWarning readability, and fix warning checks tests

* Remove `_is_valid_justify_arg` from `@deprecate_arg`, for solving circular import

* in `deprecate_arg` change `since` to "1.2.0"

* black formater suggestion

* negate conditions for `predicate` in `@deprecate_arg`

* remove `pending=True`, since then warning is not raised

* change qiskit version on tests

* remove assert Regex for DeprecationWarning

* Add release note, and remove two undesired changes in imports

* changing release note naming from "_" to "-"

* Add extra line in the end, for lint

* Redid release file from start, with shorter name, and correct spacings

* Remove final spaces in all lines...

* Try without deprecations_visualization section..

* Solve, bad Sphinx spacing, go back to deprecations_visualization

* Go back to `None` as default value

* Simplifying deprecation logic

* Remove unused imports and changed missing default value

* Improve docstring for public methods

* Improve error readbility and testing of it with regex

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
2024-07-01 14:57:00 +00:00
Julien Gacon 67fd35a2ea
Fix `replace_block_with_op` on operations with wrong number of qubits (#12637)
* fix illegal op insertion

* rm dangling print

* fix PauliEvolution

* Update qiskit/dagcircuit/dagcircuit.py

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

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
2024-07-01 14:45:52 +00:00
Alexander Ivrii 5deed7a738
improving `quantum_causal_cone` method in python (#12668)
* improving quantum_causal_cone

* fixing release note
2024-07-01 13:02:14 +00:00
Jake Lishman 373e8a68c8
Encapsulate Python sequence-like indexers (#12669)
This encapsulates a lot of the common logic around Python sequence-like
indexers (`SliceOrInt`) into iterators that handle adapting negative
indices and slices in `usize` for containers of a given size.

These indexers now all implement `ExactSizeIterator` and
`DoubleEndedIterator`, so they can be used with all `Iterator` methods,
and can be used (with `Iterator::map` and friends) as inputs to
`PyList::new_bound`, which makes code simpler at all points of use.

The special-cased uses of this kind of thing from `CircuitData` are
replaced with the new forms.  This had no measurable impact on
performance on my machine, and removes a lot noise from error-handling
and highly specialised functions.
2024-07-01 12:59:21 +00:00
Elena Peña Tapia a7fc2daf4c
Add Rust representation for CHGate, CPhaseGate, CSGate, CSdgGate, CSXGate, CSwapGate (#12639)
* Add CHGate, CPhaseGate, CSGate, CSdgGate, CSXGate, CSwapGate

* Fix tests, add labels

* Fix oversights in gate definitions

* Fix test

* Add ctrl_state 1 to rust building path.
2024-07-01 12:49:06 +00:00
dependabot[bot] c452694d70
Bump rustworkx-core from 0.14.2 to 0.15.0 (#12682)
Bumps [rustworkx-core](https://github.com/Qiskit/rustworkx) from 0.14.2 to 0.15.0.
- [Release notes](https://github.com/Qiskit/rustworkx/releases)
- [Commits](https://github.com/Qiskit/rustworkx/compare/0.14.2...0.15.0)

---
updated-dependencies:
- dependency-name: rustworkx-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2024-07-01 12:27:45 +00:00
Eli Arbel 7056198242
Add Rust representation for RXX, RYY, RZZ & RZX gates (#12672)
* Updating tables

* Updating mapping tables

* Adding remaining functionality

* Handling Black, clippy, fmt
2024-07-01 10:02:51 +00:00