Commit Graph

8955 Commits

Author SHA1 Message Date
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
Shelly Garion e9208a6339
binary matrices utils in rust (#12456)
* gaussian elimination in rust

* handle lint errors

* replace python function by rust function for gauss elimination

* change matrix elements type from bool to i8

* add parallelization in row operations

* update matrices in place

* change matrix type in rust code to bool

* handle type in python code

* update filter following review

* remove parallelization using rayon

* move _gauss_elimination_with_perm to rust

* fix fmt error

* simplify _gauss_elimination function

* update _compute_rank_after_gauss_elim to rust

* update _row_op and _col_op

* transfer _row_op and _col_op from python to rust

* fix code due to failing tests

* minor update of types

* move calc_inverse_matrix to rust, add _binary_matmul in rust

* fix failing tests, by changing mat type from int to bool

* update rust docstrings

* add function _add_row_or_col to rust code

* improve binary_matmul

* proper error handling

* unified format of function names

* move compute_rank from python to rust, update errors

* update type of mat in compute_rank

* move random_invertible_binary_matrix and check_invertible_binary_matrix to rust

* Updating HighLevelSynthesis tests that depend on the specific random number

* Updating LinearSynthesis tests to pass seeds

* Updating tests in test_linear_function

* changing the matrix type in random dyhedral to be a matrix of ints rather than bools

* updating cx_cz synthesis tests

* updating clifford tests

* remove unused imports

* add option seed=None

* enhance rust docs

* add release notes

* remove unnecessary copy in python

* another copy fix

* another copy fix

* update rust docstrings

* update release notes

---------

Co-authored-by: AlexanderIvrii <alexi@il.ibm.com>
2024-06-28 20:18:17 +00:00
Jake Lishman 44fe59b040
Relax CI constraint on Rustworkx 0.15.0 (#12690)
The release of Rustworkx 0.15.1 fixes the bug that was previously
blocking CI.
2024-06-28 19:39:56 +00:00
dependabot[bot] 3af991856f
Bump num-bigint from 0.4.5 to 0.4.6 (#12681)
Bumps [num-bigint](https://github.com/rust-num/num-bigint) from 0.4.5 to 0.4.6.
- [Changelog](https://github.com/rust-num/num-bigint/blob/master/RELEASES.md)
- [Commits](https://github.com/rust-num/num-bigint/compare/num-bigint-0.4.5...num-bigint-0.4.6)

---
updated-dependencies:
- dependency-name: num-bigint
  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-06-28 16:14:30 +00:00
Matthew Treinish 24ee7c69b5
Fix clippy warnings on latest stable rust (#12675)
In Rust 1.79.0 several new clippy rules were added and/or enabled by
default. This was causing some new issues to be flagged when building
qiskit with the this release of Rust. This commit fixes these issues
flagged by clippy.

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-06-28 16:03:37 +00:00
Julien Gacon 9b0a5849f6
Port CRX/Y/Z gates to Rust (#12648)
* v0 of CR-Pauli gates

* fix inevitable matrix typos

* update multiply_param

and prepare for U1/2/3 PR

* fix num params/qubits

* cct methods to append rust gates

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-06-28 15:34:30 +00:00
Jake Lishman 3adcd5d3df
Suppress nonsense `DeprecationWarning` caused by `unittest` (#12676)
* Suppress nonsense `DeprecationWarning` caused by `unittest`

`unittest.TestCase.assertWarns` in context-manager form has an awkward
habit of querying the `__warningregistry__` attribute on every module in
existence.  This interacts poorly with a Numpy 2 deprecation warning
trigger for code that's attempting to import functions from modules that
became private in Numpy 2, if a warning has previously been triggered
out of `numpy.linalg._linalg`.

This simply suppresses that particular warning from the test suite.

* Refine filter

* Pin Rustworkx to avoid buggy graphviz drawing

* 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-06-28 13:36:32 +00:00
John Lapeyre ea5a54b9da
Add constant abbreviations for some values and types. (#12651)
This PR introduces some abbreviations for repetitive Rust code. Motivations are reducing
clutter, improving readability, and perhaps modest support for rapid development.

* Use the definition of `const fn 64` that was introduced in #12459 uniformly in all crates.

* Define some complex constants `C_ONE`, `C_ZERO`, `IM`, etc.

* Introduce type definitions for arrays representing gates. For example:
     `GateArray1Q = [[Complex64; 2]; 2];`
2024-06-27 19:38:36 +00:00
Takashi Imamichi 76af5b475b
Enable the new efficient MCX decompose (#12628)
* enable the new efficient MCX decompose

* fix tests

* revert explicit

* apply review comments

* update test_circuit_qasm.py

* update test_decompose.py

* revert C3X C4X names

* fix qasm2 exporter tests

use regex to fetch the mcx_<random id> name

* fix lint and add reno

---------

Co-authored-by: Julien Gacon <jules.gacon@googlemail.com>
2024-06-27 13:58:52 +00:00
John Lapeyre 6447941885
Implement RGate in Rust (#12662)
* Implement RGate in Rust

* Update crates/circuit/src/operations.rs

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

* Fix error in decomposition of RGate

There is an error in the expression for decomposition of the R gate
in the port to Rust.

This fixes the error and re-enables the skipped test that failed because
of the incorrect expression.

* Factor cloning the Param enum in Rust

To clone the enum, each variant must be handled separately.  This is currently used once,
but can be used each time a `Param` is cloned. In case more work needs to be done within
match arms, one might choose not to use this function, but rather clone in each of these
arms.

* Run cargo fmt

* Implement and use addition for enum Param

This handles `Float` and `ParameterExpression` variants uniformly.

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-06-27 09:08:24 +00:00
Eli Arbel 2fab2007e3
Add Rust representation for DCXGate (#12644)
* Updating tables

* Adding remaining code

* Appending the Rust representation directly

* Fix fmt

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-06-26 15:15:10 +00:00
Matthew Treinish 39b2c90b81
Add test case to validate the rust->Python gate conversion (#12623)
This commit adds a test to the test_rust_equivalence module to assert
that the Python gate objects returned from the Rust CircuitData is
the correct type.
2024-06-26 13:48:25 +00:00
Luciano Bello 26680dcecf
adapting test/randomized/test_transpiler_equivalence.py to #12640 (#12663)
* addapting to #12640

* more instances
2024-06-26 12:45:24 +00:00
Matthew Treinish 4d3821b01a
Simplify QuantumCircuit._from_circuit_data bit handling (#12661)
* Simplify QuantumCircuit._from_circuit_data bit handling

This commit simplifies the logic around bit handling in the
`QuantumCircuit._from_circuit_data()` constructor. Previously it was
calling `add_bits()` for each bit in the `CircuitData` object to update
the output circuit's accounting for each qubit. But this was needlessly
heavy as the `CircuitData` is already the source of truth for the bits
in a circuit and we just need to update the indices dictionary. The
`add_bits()` method attempts to add the bits to the `CircuitData` too
but this is wasted overhead because the `CircuitData` already has the
bits as that's where the came from. This changes the constructor to just
directly set the bit indices as needed and return the circuit.

* Use a dict comprehension instead of a for loop
2024-06-26 12:06:23 +00:00
Luciano Bello e36027c01a
GenericBackendV2 should fail when the backend cannot allocate the basis gate because its size (#12653)
* GenericBackendV2 should fail when the backend cannot allocate the basis gate because its size

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

* reno

* Update releasenotes/notes/fixes_GenericBackendV2-668e40596e1f070d.yaml

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

* another single qubit backend

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-06-26 07:41:11 +00:00
Julien Gacon 6974b4500f
Fix some bugs in loading Solovay Kitaev decompositions (#12579)
* fix store & load

- fix access via .item()
- fix storing of global phase
- fix storing ofgate sequence labels

* undangle a dangling print

* fix import order

* Update releasenotes/notes/fix-sk-load-from-file-02c6eabbbd7fcda3.yaml

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-06-26 06:29:34 +00:00
Elena Peña Tapia 1ed5951a98
Pin scipy to 1.13.1 to bypass CI failures (#12654)
* Pin scipy to 1.13.1 to bypass CI failures

* whoops

* double whoops
2024-06-25 10:53:54 +00:00
Jake Lishman 8b1f75ffaf
Deprecate tuple-like access to `CircuitInstruction` (#12640)
This has been the legacy path since `CircuitInstruction` was added in
gh-8093.  It's more performant to use the attribute-access patterns, and
with more of the internals moving to Rust and potentially needing more
use of additional class methods and attributes, we need to start
shifting people away from the old form.
2024-06-24 18:21:20 +00:00
Elena Peña Tapia b20a7ceb58
Add placeholders for all mising standard gates in Rust (#12646)
* Add placeholders for all gates, mark TODOs

* Update name for CPhase

* Remove todo from Ux gates
2024-06-24 18:16:16 +00:00
dependabot[bot] 35f6297f20
Bump faer from 0.19.0 to 0.19.1 (#12645)
Bumps [faer](https://github.com/sarah-ek/faer-rs) from 0.19.0 to 0.19.1.
- [Changelog](https://github.com/sarah-ek/faer-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sarah-ek/faer-rs/commits)

---
updated-dependencies:
- dependency-name: faer
  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-06-24 15:23:42 +00:00
Matthew Treinish bf8f398fa4
Add rust representation for the u1, u2, and u3 gates (#12572)
* Add rust representation for the u1, u2, and u3 gates

This commit adds the rust representation of the U1Gate, U2Gate, and
U3Gate to the `StandardGates` enum in rust.

Part of #12566

* Update crates/circuit/src/imports.rs

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

* Fix test failures

* Fix pylint pedantry

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
2024-06-24 14:05:06 +00:00
Julien Gacon de6c6eb2f9
Follow up on #12327: circuit construction in Rust (#12605)
* Follow up on #12327

also port circuit construction to rust and add a reno

* move _get_ordered_swap to Rust only

* drop redundant Ok(expect())

* proper synthesis structure
2024-06-24 08:02:31 +00:00
Elena Peña Tapia 87aa89c193
Add Rust representation for `XXMinusYYGate` and `XXPlusYYGate` (#12606)
* Add XXMinusYYGate and XXPlusYYGate, implement parameter multiplication function (naive approach).

Co-authored by: Julien Gacon jul@zurich.ibm.com

* * Format code

* Use multiply_param in RZGate

* Fix signs and indices
2024-06-21 15:25:59 +00:00
Jake Lishman 22c145aa0e
Fix `CircuitInstruction` legacy iterable typing (#12630)
The legacy 3-tuple format of `CircuitInstruction` still exposes the
object in the old tuple-like way of `(Operation, list[Qubit],
list[Clbit])`, rather than the new-style attribute access using tuples
for the qargs and cargs.  This was inadvertantly changed when it moved
to Rust.
2024-06-21 12:28:57 +00:00
Jim Garrison 8752f900f0
Add remaining tests for `ParameterVector` and tweak its `repr` (#12597) 2024-06-21 12:18:28 +00:00
Tiago R. Cunha 91f0c70885
Fix type hint in SolovayKitaevDecomposition (#12627)
The return type hint of `find_basic_approximation` method changes from `Gate` to `GateSequence` in `SolovayKitaevDecomposition` class, as implied by `self.basic_approximations`.

With no remaining mentions of `Gate`, its corresponding import statement is removed.
2024-06-21 11:29:48 +00:00
Jake Lishman b8de17f908
Localise `py_op` caching data in `RefCell` (#12594)
This localises the caching concerns of the `PackedInstruction::py_op`
field into a method `unpack_py_op`, which can now update the cache
through an immutable reference (if no other immutable references are
taken out).  Having the new method to encapsulate the `cache_pyops`
feature simplifies the large `#[cfg(feature = "cache_pyop")]` gates.
2024-06-21 10:15:07 +00:00
Jake Lishman b6c6166127
Invalidate `parameters` cache on circuit copy (#12619)
Previously, the caching of the parameter view could persist between
copies of the circuit because it was part of the `copy.copy`.
2024-06-20 17:15:25 +00:00
Naoki Kanazawa 7d1731b60d
Fix v2 pulse drawer (#12608)
* fix error when V2 model is set

* Apply suggestions from code review

* Fix black

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Elena Peña Tapia <epenatap@gmail.com>
2024-06-20 13:01:56 +00:00
Julien Gacon 591260f069
use compose instead of + (#12609) 2024-06-20 09:09:00 +00:00
Luis J Camargo 0f513577b3
Spellcheck Done [Unitary Hack 2024] (#12501)
* spell check iter1

* spell check iter 2

* Fix fmt

* Update qiskit/_numpy_compat.py

* Update qiskit/synthesis/evolution/product_formula.py

* Update qiskit/synthesis/evolution/product_formula.py

* Update releasenotes/notes/0.13/qinfo-states-7f67e2432cf0c12c.yaml

* undo some corrections

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Julien Gacon <jules.gacon@googlemail.com>
2024-06-19 15:50:03 +00:00
Joe Schulte 53667d167e
Remove consider-using-f-string lint rule and updates (#12423)
* remove consider-using-f-string lint rule and updates

* reverting a latex update

* f-string update based on review

* Update qiskit/circuit/library/hamiltonian_gate.py

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

* Update qiskit/circuit/tools/pi_check.py

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

* Update qiskit/circuit/tools/pi_check.py

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

* updates after merge

* Update qiskit/providers/models/backendproperties.py

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

* Update qiskit/synthesis/linear/cnot_synth.py

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

* updates from PR

* latex fixes

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
2024-06-19 07:05:56 +00:00