Skip to content

Commit

Permalink
Merge branch 'main' into clib-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Dec 3, 2024
2 parents 8d67df1 + 8e2aaad commit f4a4429
Show file tree
Hide file tree
Showing 83 changed files with 747 additions and 498 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "Apache-2.0"
# Each crate can add on specific features freely as it inherits.
[workspace.dependencies]
bytemuck = "1.20"
indexmap.version = "2.6.0"
indexmap.version = "2.7.0"
hashbrown.version = "0.14.5"
num-bigint = "0.4"
num-complex = "0.4"
Expand Down
10 changes: 5 additions & 5 deletions crates/accelerate/src/rayon_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct ParUnevenChunksMut<'len, 'data, T> {
data: &'data mut [T],
}

impl<'len, 'data, T: Send + 'data> ParallelIterator for ParUnevenChunksMut<'len, 'data, T> {
impl<'data, T: Send + 'data> ParallelIterator for ParUnevenChunksMut<'_, 'data, T> {
type Item = &'data mut [T];

#[track_caller]
Expand All @@ -61,7 +61,7 @@ impl<'len, 'data, T: Send + 'data> ParallelIterator for ParUnevenChunksMut<'len,
}
}

impl<'len, 'data, T: Send + 'data> IndexedParallelIterator for ParUnevenChunksMut<'len, 'data, T> {
impl<'data, T: Send + 'data> IndexedParallelIterator for ParUnevenChunksMut<'_, 'data, T> {
#[track_caller]
fn drive<C: Consumer<Self::Item>>(self, consumer: C) -> C::Result {
bridge(self, consumer)
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'len, 'data, T> UnevenChunksMutIter<'len, 'data, T> {
}
}

impl<'len, 'data, T> Iterator for UnevenChunksMutIter<'len, 'data, T> {
impl<'data, T> Iterator for UnevenChunksMutIter<'_, 'data, T> {
type Item = &'data mut [T];

#[track_caller]
Expand All @@ -154,8 +154,8 @@ impl<'len, 'data, T> Iterator for UnevenChunksMutIter<'len, 'data, T> {
(self.chunk_lengths.len(), Some(self.chunk_lengths.len()))
}
}
impl<'len, 'data, T> ExactSizeIterator for UnevenChunksMutIter<'len, 'data, T> {}
impl<'len, 'data, T> DoubleEndedIterator for UnevenChunksMutIter<'len, 'data, T> {
impl<T> ExactSizeIterator for UnevenChunksMutIter<'_, '_, T> {}
impl<T> DoubleEndedIterator for UnevenChunksMutIter<'_, '_, T> {
#[track_caller]
fn next_back(&mut self) -> Option<Self::Item> {
if self.chunk_lengths.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion crates/accelerate/src/sabre/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct RoutingState<'a, 'b> {
seed: u64,
}

impl<'a, 'b> RoutingState<'a, 'b> {
impl RoutingState<'_, '_> {
/// Apply a swap to the program-state structures (front layer, extended set and current
/// layout).
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions crates/accelerate/src/sparse_observable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ pub struct SparseTermView<'a> {
pub bit_terms: &'a [BitTerm],
pub indices: &'a [u32],
}
impl<'a> SparseTermView<'a> {
impl SparseTermView<'_> {
/// Convert this `SparseTermView` into an owning [SparseTerm] of the same data.
pub fn to_term(&self) -> SparseTerm {
SparseTerm {
Expand Down Expand Up @@ -2618,8 +2618,8 @@ impl<'a> Iterator for IterMut<'a> {
(self.coeffs.len(), Some(self.coeffs.len()))
}
}
impl<'a> ExactSizeIterator for IterMut<'a> {}
impl<'a> ::std::iter::FusedIterator for IterMut<'a> {}
impl ExactSizeIterator for IterMut<'_> {}
impl ::std::iter::FusedIterator for IterMut<'_> {}

/// Helper class of `ArrayView` that denotes the slot of the `SparseObservable` we're looking at.
#[derive(Clone, Copy, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/accelerate/src/sparse_pauli_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub struct ZXPaulisView<'py> {
coeffs: ArrayView1<'py, Complex64>,
}

impl<'py> ZXPaulisView<'py> {
impl ZXPaulisView<'_> {
/// The number of qubits this operator acts on.
pub fn num_qubits(&self) -> usize {
self.x.shape()[1]
Expand Down
16 changes: 8 additions & 8 deletions crates/accelerate/src/synthesis/multi_controlled/mcmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ use smallvec::{smallvec, SmallVec};

use crate::QiskitError;

type CCXChainItem = PyResult<(
PackedOperation,
SmallVec<[Param; 3]>,
Vec<Qubit>,
Vec<Clbit>,
)>;

/// A Toffoli chain, implementing a multi-control condition on all controls using
/// ``controls.len() - 1`` auxiliary qubits.
///
Expand All @@ -42,14 +49,7 @@ use crate::QiskitError;
fn ccx_chain<'a>(
controls: &'a [usize],
auxiliaries: &'a [usize],
) -> impl DoubleEndedIterator<
Item = PyResult<(
PackedOperation,
SmallVec<[Param; 3]>,
Vec<Qubit>,
Vec<Clbit>,
)>,
> + 'a {
) -> impl DoubleEndedIterator<Item = CCXChainItem> + 'a {
let n = controls.len() - 1; // number of chain elements
std::iter::once((controls[0], controls[1], auxiliaries[0]))
.chain((0..n - 1).map(|i| (controls[i + 2], auxiliaries[i], auxiliaries[i + 1])))
Expand Down
6 changes: 3 additions & 3 deletions crates/accelerate/src/target_transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,10 @@ impl Target {
// TODO: Remove once `Target` is being consumed.
#[allow(dead_code)]
pub fn operations(&self) -> impl Iterator<Item = &NormalOperation> {
return self._gate_name_map.values().filter_map(|oper| match oper {
self._gate_name_map.values().filter_map(|oper| match oper {
TargetOperation::Normal(oper) => Some(oper),
_ => None,
});
})
}

/// Get the error rate of a given instruction in the target
Expand Down Expand Up @@ -1025,7 +1025,7 @@ impl Target {
} else if self.non_global_basis.is_some() {
return self.non_global_basis.as_deref();
}
return Some(self.generate_non_global_op_names(strict_direction));
Some(self.generate_non_global_op_names(strict_direction))
}

/// Gets all the operation names that use these qargs. Rust native equivalent of ``BaseTarget.operation_names_for_qargs()``
Expand Down
6 changes: 3 additions & 3 deletions crates/accelerate/src/target_transpiler/nullable_index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {
impl<K, V> ExactSizeIterator for Iter<'_, K, V> {
fn len(&self) -> usize {
self.map.len() + self.null_value.is_some() as usize
}
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
impl<K, V> ExactSizeIterator for Keys<'_, K, V> {
fn len(&self) -> usize {
self.map_keys.len() + self.null_value as usize
}
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
impl<K, V> ExactSizeIterator for Values<'_, K, V> {
fn len(&self) -> usize {
self.map_values.len() + self.null_value.is_some() as usize
}
Expand Down
4 changes: 3 additions & 1 deletion crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ import_exception!(qiskit.circuit.exceptions, CircuitError);
///
/// For example,
///
/// .. code-block::
/// .. plot::
/// :include-source:
/// :no-figs:
///
/// qubits = [Qubit()]
/// data = CircuitData(qubits)
Expand Down
2 changes: 1 addition & 1 deletion crates/circuit/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub enum OperationRef<'a> {
Operation(&'a PyOperation),
}

impl<'a> Operation for OperationRef<'a> {
impl Operation for OperationRef<'_> {
#[inline]
fn name(&self) -> &str {
match self {
Expand Down
2 changes: 1 addition & 1 deletion crates/circuit/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'py> FromPyObject<'py> for PySequenceIndex<'py> {
}
}

impl<'py> PySequenceIndex<'py> {
impl PySequenceIndex<'_> {
/// Specialize this index to a collection of the given `len`, returning a Rust-native type.
pub fn with_len(&self, len: usize) -> Result<SequenceIndex, PySequenceIndexError> {
match self {
Expand Down
2 changes: 1 addition & 1 deletion crates/qasm2/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> Position<'a> {
}
}

impl<'a> std::fmt::Display for &Position<'a> {
impl std::fmt::Display for &Position<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion crates/qasm2/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub struct ExprParser<'a> {
pub strict: bool,
}

impl<'a> ExprParser<'a> {
impl ExprParser<'_> {
/// Get the next token available in the stack of token streams, popping and removing any
/// complete streams, except the base case. Will only return `None` once all streams are
/// exhausted.
Expand Down
5 changes: 4 additions & 1 deletion crates/qasm3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ name = "qiskit_qasm3"
doctest = false

[dependencies]
pyo3.workspace = true
indexmap.workspace = true
hashbrown.workspace = true
oq3_semantics = "0.7.0"
ahash.workspace = true

[dependencies.pyo3]
workspace = true
features = ["py-clone"]
6 changes: 3 additions & 3 deletions crates/qasm3/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'py> Iterator for BroadcastQubitsIter<'py> {
(self.len - self.offset, Some(self.len - self.offset))
}
}
impl<'py> ExactSizeIterator for BroadcastQubitsIter<'py> {}
impl ExactSizeIterator for BroadcastQubitsIter<'_> {}

struct BroadcastMeasureIter<'a, 'py> {
py: Python<'py>,
Expand All @@ -142,7 +142,7 @@ struct BroadcastMeasureIter<'a, 'py> {
carg: &'a BroadcastItem,
}

impl<'a, 'py> Iterator for BroadcastMeasureIter<'a, 'py> {
impl<'py> Iterator for BroadcastMeasureIter<'_, 'py> {
type Item = (Bound<'py, PyTuple>, Bound<'py, PyTuple>);

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -165,7 +165,7 @@ impl<'a, 'py> Iterator for BroadcastMeasureIter<'a, 'py> {
(self.len - self.offset, Some(self.len - self.offset))
}
}
impl<'a, 'py> ExactSizeIterator for BroadcastMeasureIter<'a, 'py> {}
impl ExactSizeIterator for BroadcastMeasureIter<'_, '_> {}

fn broadcast_bits_for_identifier<T: PyRegister>(
py: Python,
Expand Down
15 changes: 11 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@
# documentation created by autosummary uses a template file (in autosummary in the templates path),
# which likely overrides the autodoc defaults.

# These options impact when using `.. autoclass::` manually.
# They do not impact the `.. autosummary::` templates.
autodoc_default_options = {
"show-inheritance": True,
}

# Move type hints from signatures to the parameter descriptions (except in overload cases, where
# that's not possible).
autodoc_typehints = "description"
# Only add type hints from signature to description body if the parameter has documentation. The
# return type is always added to the description (if in the signature).
autodoc_typehints_description_target = "documented_params"

autoclass_content = "both"
# Some type hints are too long to be understandable. So, we set up aliases to be used instead.
autodoc_type_aliases = {
"EstimatorPubLike": "EstimatorPubLike",
"SamplerPubLike": "SamplerPubLike",
}

autosummary_generate = True
autosummary_generate_overwrite = False
Expand Down
4 changes: 3 additions & 1 deletion qiskit/assembler/assemble_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ def assemble_circuits(
Examples:
.. code-block:: python
.. plot::
:include-source:
:nofigs:
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.assembler import assemble_circuits
Expand Down
4 changes: 3 additions & 1 deletion qiskit/assembler/assemble_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def assemble_schedules(
Examples:
.. code-block:: python
.. plot::
:include-source:
:nofigs:
from qiskit import pulse
from qiskit.assembler import assemble_schedules
Expand Down
4 changes: 3 additions & 1 deletion qiskit/assembler/disassemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def disassemble(qobj) -> Union[CircuitModule, PulseModule]:
Examples:
.. code-block:: python
.. plot::
:include-source:
:nofigs:
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.compiler.assembler import assemble
Expand Down
6 changes: 5 additions & 1 deletion qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@
The :class:`Barrier` instruction can span an arbitrary number of qubits and clbits, and is a no-op
in hardware. During transpilation and optimization, however, it blocks any optimizations from
"crossing" the barrier; that is, in::
"crossing" the barrier; that is, in:
.. plot::
:include-source:
:nofigs:
from qiskit.circuit import QuantumCircuit
Expand Down
5 changes: 4 additions & 1 deletion qiskit/circuit/classical/types/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ def cast_kind(from_: Type, to_: Type, /) -> CastKind:
Examples:
.. code-block:: python
.. plot::
:include-source:
:nofigs:
>>> from qiskit.circuit.classical import types
>>> types.cast_kind(types.Bool(), types.Bool())
Expand Down
4 changes: 3 additions & 1 deletion qiskit/circuit/classicalfunction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
how to synthesize a simple boolean function defined using Python into a
QuantumCircuit:
.. code-block::
.. code-block:: python
from qiskit.circuit.classicalfunction import classical_function
from qiskit.circuit.classicalfunction.types import Int1
Expand All @@ -37,6 +37,8 @@ def grover_oracle(a: Int1, b: Int1, c: Int1, d: Int1) -> Int1:
quantum_circuit = grover_oracle.synth(registerless=False)
quantum_circuit.draw('text')
.. code-block:: text
a: ──o──
b: ──■──
Expand Down
8 changes: 6 additions & 2 deletions qiskit/circuit/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@
For example:
.. code-block::
.. plot::
:include-source:
:nofigs:
from qiskit.circuit.library import XGate
gate = XGate()
Expand Down Expand Up @@ -619,7 +621,9 @@
In this example, the identity constant in a template is checked:
.. code-block::
.. plot::
:include-source:
:nofigs:
from qiskit.circuit.library.templates import template_nct_4b_1
from qiskit.quantum_info import Operator
Expand Down
4 changes: 3 additions & 1 deletion qiskit/circuit/library/generalized_gates/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class UnitaryGate(Gate):
quantum circuit. The matrix can also be directly applied to the quantum
circuit, see :meth:`.QuantumCircuit.unitary`.
.. code-block:: python
.. plot::
:include-source:
:nofigs:
from qiskit import QuantumCircuit
from qiskit.circuit.library import UnitaryGate
Expand Down
Loading

0 comments on commit f4a4429

Please sign in to comment.