Skip to content
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
4dcef02
use ruff to auto fix union stuff
andrijapau Jul 11, 2025
21e16be
fix typing.py manually
andrijapau Jul 11, 2025
28e6eb7
fix qscript.py manually
andrijapau Jul 11, 2025
2415e88
fix shots.py manually
andrijapau Jul 11, 2025
ff6ddc8
fix typing_util.py manually
andrijapau Jul 11, 2025
c4e4d45
fix interface_utils.py
andrijapau Jul 11, 2025
d358f3f
fix remaining errors manually
andrijapau Jul 11, 2025
77408eb
Update pennylane/typing.py
andrijapau Jul 11, 2025
6c7c638
try removing Union from everywhere
andrijapau Jul 11, 2025
d4e0146
Merge branch 'random-improvements' of github.com:PennyLaneAI/pennylan…
andrijapau Jul 11, 2025
a92212e
fix union of strings
andrijapau Jul 11, 2025
b1c9334
fix interface utils
andrijapau Jul 11, 2025
52da4fe
fix
andrijapau Jul 11, 2025
4afbb51
Merge branch 'master' into random-improvements
andrijapau Jul 11, 2025
654f9fa
Update pennylane/data/base/typing_util.py
andrijapau Jul 11, 2025
450b0ad
fix
andrijapau Jul 11, 2025
8aa2372
Merge branch 'random-improvements' of github.com:PennyLaneAI/pennylan…
andrijapau Jul 11, 2025
a943fe6
commit pyupgrade work
andrijapau Jul 11, 2025
000755b
ruff fix imports automatically
andrijapau Jul 11, 2025
9aa71fa
revert cv.py
andrijapau Jul 11, 2025
dd912b8
revert files
andrijapau Jul 11, 2025
c5a564f
fix insert_ops.py
andrijapau Jul 11, 2025
900db76
Revert "fix insert_ops.py"
andrijapau Jul 11, 2025
4d3e373
fix insert_ops.py
andrijapau Jul 11, 2025
c059480
fix
andrijapau Jul 11, 2025
9c29486
update matrix.py in realspace
andrijapau Jul 11, 2025
63f4af1
use dict zip
andrijapau Jul 11, 2025
c4466a3
Merge branch 'master' into random-improvements
andrijapau Jul 14, 2025
bd7235f
Merge branch 'master' into random-improvements
JerryChen97 Jul 16, 2025
005428f
Merge branch 'master' into random-improvements
andrijapau Jul 16, 2025
5ef9464
run the pyup_dirs command again
andrijapau Jul 16, 2025
69240da
return source_info?
andrijapau Jul 16, 2025
1d3ed1c
merge master to this branch
andrijapau Jul 17, 2025
0afdcc3
Merge branch 'master' into random-improvements
andrijapau Jul 17, 2025
b418611
Update pennylane/devices/qubit_mixed/initialize_state.py
andrijapau Jul 17, 2025
c703826
Update pennylane/devices/qutrit_mixed/initialize_state.py
andrijapau Jul 17, 2025
bbbfecb
merge master into this branch
andrijapau Jul 17, 2025
f2f3a0a
changelog
andrijapau Jul 17, 2025
726df76
update mitigate.py
andrijapau Jul 17, 2025
8f94087
Update pennylane/math/interface_utils.py
andrijapau Jul 17, 2025
a8d895c
Update pennylane/math/interface_utils.py
andrijapau Jul 17, 2025
5f95371
shots.py
andrijapau Jul 17, 2025
74c03c5
Merge branch 'random-improvements' of github.com:PennyLaneAI/pennylan…
andrijapau Jul 17, 2025
c147fb7
Update pennylane/ops/op_math/controlled.py
andrijapau Jul 17, 2025
4fc0bc6
Update pennylane/ops/op_math/controlled.py
andrijapau Jul 17, 2025
e47ed9f
Update pennylane/ops/op_math/controlled.py
andrijapau Jul 17, 2025
6d163b5
Update pennylane/ops/op_math/controlled.py
andrijapau Jul 17, 2025
58585f8
Update pennylane/ops/op_math/controlled_ops.py
andrijapau Jul 18, 2025
12bc7ce
Update pennylane/qcut/kahypar.py
andrijapau Jul 18, 2025
b54547a
Update pennylane/qcut/kahypar.py
andrijapau Jul 18, 2025
5d3aa81
Update pennylane/ops/op_math/sprod.py
andrijapau Jul 18, 2025
8dcb4ff
Update pennylane/qcut/cutstrategy.py
andrijapau Jul 18, 2025
9f76dbd
Update pennylane/qcut/cutstrategy.py
andrijapau Jul 18, 2025
fc0325a
Update pennylane/ops/op_math/controlled_ops.py
andrijapau Jul 18, 2025
5cded42
Merge branch 'master' into random-improvements
andrijapau Jul 18, 2025
dde588a
remove wiresenum
andrijapau Jul 18, 2025
009dd66
fix
andrijapau Jul 18, 2025
df76cbb
fix
andrijapau Jul 18, 2025
d943657
add pyupgrade to pre-commit
andrijapau Jul 18, 2025
07102e7
fix
andrijapau Jul 18, 2025
9c9d318
fix precommit and makefile
andrijapau Jul 18, 2025
7da9201
fix both make and pre-commit
andrijapau Jul 18, 2025
52cc0c9
update makefile
andrijapau Jul 18, 2025
05700e5
fix
andrijapau Jul 18, 2025
3504d33
Update pennylane/measurements/shots.py
andrijapau Jul 18, 2025
bdb2203
Update doc/releases/changelog-dev.md
andrijapau Jul 18, 2025
7055ac0
Merge branch 'master' into random-improvements
andrijapau Jul 18, 2025
9041876
fix
andrijapau Jul 18, 2025
b8c2e3d
Merge branch 'master' into random-improvements
andrijapau Jul 18, 2025
c33ba7f
fix
andrijapau Jul 18, 2025
736f8c9
Merge branch 'master' into random-improvements
andrijapau Jul 18, 2025
0abbbc5
Merge branch 'master' into random-improvements
andrijapau Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@

<h3>Internal changes ⚙️</h3>

* Upgraded source code to use Python 3.11+ language features.
[(#7860)](https://github.com/PennyLaneAI/pennylane/pull/7860)

* Added a `dialects` submodule to `qml.compiler.python_compiler` which now houses all the xDSL dialects we create.
Additionally, the `MBQCDialect` and `QuantumDialect` dialects have been renamed to `MBQC` and `Quantum`.
[(#7897)](https://github.com/PennyLaneAI/pennylane/pull/7897)
Expand Down
5 changes: 1 addition & 4 deletions pennylane/_deprecated_observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def is_hermitian(self) -> bool:
"""All observables must be hermitian"""
return True

def compare(
self,
other: Union["Observable", "qml.ops.LinearCombination"],
) -> bool:
def compare(self, other: Union["Observable", "qml.ops.LinearCombination"]) -> bool:
r"""Compares with another :class:`~Observable`, to determine if they are equivalent.

.. warning::
Expand Down
4 changes: 2 additions & 2 deletions pennylane/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
This module contains the commands for allocating and deallocating wires dynamically.
"""
import uuid
from typing import Optional, Sequence
from collections.abc import Sequence

from pennylane.capture import enabled as capture_enabled
from pennylane.operation import Operator
Expand Down Expand Up @@ -73,7 +73,7 @@ class DynamicWire:
key (Optional[str]): a ``uuid4`` string to uniquely identify the dynamic wire.
"""

def __init__(self, key: Optional[uuid.UUID] = None):
def __init__(self, key: uuid.UUID | None = None):
self.key = key or uuid.uuid4()

def __eq__(self, other):
Expand Down
2 changes: 1 addition & 1 deletion pennylane/bose/bosonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def items(self):
@property
def wires(self):
r"""Return wires in a BoseWord."""
return set(i[1] for i in self.sorted_dic.keys())
return {i[1] for i in self.sorted_dic.keys()}

def __missing__(self, key):
r"""Return empty string for a missing key in BoseWord."""
Expand Down
7 changes: 3 additions & 4 deletions pennylane/bose/bosonic_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from collections import defaultdict
from functools import singledispatch
from typing import Union

import numpy as np

Expand All @@ -39,7 +38,7 @@ def _get_pauli_op(i, j, qub_id):


def binary_mapping(
bose_operator: Union[BoseWord, BoseSentence],
bose_operator: BoseWord | BoseSentence,
n_states: int = 2,
ps: bool = False,
wire_map: dict = None,
Expand Down Expand Up @@ -164,7 +163,7 @@ def _(bose_operator: BoseSentence, n_states, tol=None):


def unary_mapping(
bose_operator: Union[BoseWord, BoseSentence],
bose_operator: BoseWord | BoseSentence,
n_states: int = 2,
ps: bool = False,
wire_map: dict = None,
Expand Down Expand Up @@ -300,7 +299,7 @@ def _(bose_operator: BoseSentence, n_states, tol=None):


def christiansen_mapping(
bose_operator: Union[BoseWord, BoseSentence],
bose_operator: BoseWord | BoseSentence,
ps: bool = False,
wire_map: dict = None,
tol: float = None,
Expand Down
3 changes: 2 additions & 1 deletion pennylane/capture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class MyCustomOp(qml.operation.Operator):
def _(*args, **kwargs):
return type.__call__(MyCustomOp, *args, **kwargs)
"""
from typing import Callable, Type
from typing import Type
from collections.abc import Callable

from .switches import disable, enable, enabled, pause
from .capture_meta import CaptureMeta, ABCCaptureMeta
Expand Down
21 changes: 10 additions & 11 deletions pennylane/capture/autograph/ag_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"""
import copy
import functools
from typing import Any, Callable, Iterator, SupportsIndex, Tuple, Union
from collections.abc import Callable, Iterator
from typing import Any, SupportsIndex

from malt.core import config as ag_config
from malt.impl import api as ag_api
Expand Down Expand Up @@ -69,9 +70,9 @@ def if_stmt(
pred: bool,
true_fn: Callable[[], Any],
false_fn: Callable[[], Any],
get_state: Callable[[], Tuple],
set_state: Callable[[Tuple], None],
symbol_names: Tuple[str],
get_state: Callable[[], tuple],
set_state: Callable[[tuple], None],
symbol_names: tuple[str],
_num_results: int,
):
"""An implementation of the AutoGraph 'if' statement. The interface is defined by AutoGraph,
Expand Down Expand Up @@ -205,11 +206,11 @@ def functional_for(i, *iter_args):

def for_stmt(
iteration_target: Any,
_extra_test: Union[Callable[[], bool], None],
_extra_test: Callable[[], bool] | None,
body_fn: Callable[[int], None],
get_state: Callable[[], Tuple],
set_state: Callable[[Tuple], None],
symbol_names: Tuple[str],
get_state: Callable[[], tuple],
set_state: Callable[[tuple], None],
symbol_names: tuple[str],
_opts: dict,
):
"""An implementation of the AutoGraph 'for .. in ..' statement. The interface is defined by
Expand Down Expand Up @@ -486,9 +487,7 @@ def __contains__(self, __key: object) -> bool: # pragma: no cover
def __iter__(self) -> Iterator[int]: # pragma: no cover
return self.py_range.__iter__()

def __getitem__(
self, __key: Union[SupportsIndex, slice]
) -> Union[int, range]: # pragma: no cover
def __getitem__(self, __key: SupportsIndex | slice) -> int | range: # pragma: no cover
return self.py_range.__getitem__(__key)

def __reversed__(self) -> Iterator[int]: # pragma: no cover
Expand Down
5 changes: 3 additions & 2 deletions pennylane/capture/base_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"""
This submodule defines a strategy structure for defining custom plxpr interpreters
"""
from collections.abc import Callable, Sequence

# pylint: disable=no-self-use
from copy import copy
from functools import partial, wraps
from typing import Callable, Optional, Sequence

import jax

Expand All @@ -44,7 +45,7 @@
"""


def _fill_in_shape_with_dyn_shape(dyn_shape: tuple["jax.core.Tracer"], shape: tuple[Optional[int]]):
def _fill_in_shape_with_dyn_shape(dyn_shape: tuple["jax.core.Tracer"], shape: tuple[int | None]):
"""
A helper for broadcast_in_dim and iota to combine static dimensions and dynamic dimensions.

Expand Down
3 changes: 1 addition & 2 deletions pennylane/capture/custom_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# pylint: disable=abstract-method

from enum import Enum
from typing import Union

from jax.extend.core import Primitive

Expand Down Expand Up @@ -48,6 +47,6 @@ def prim_type(self):
return self._prim_type.value

@prim_type.setter
def prim_type(self, value: Union[str, PrimitiveType]):
def prim_type(self, value: str | PrimitiveType):
"""Setter for QmlPrimitive.prim_type."""
self._prim_type = PrimitiveType(value)
4 changes: 2 additions & 2 deletions pennylane/capture/dynamic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
Contains a utility for handling inputs with dynamically shaped arrays.
"""
from typing import Callable, Sequence, Union
from collections.abc import Callable, Sequence

has_jax = True
try:
Expand Down Expand Up @@ -189,7 +189,7 @@ def _tracer_and_outvar(

def custom_staging_rule(
jaxpr_trace: pe.DynamicJaxprTrace, source_info, *tracers: pe.DynamicJaxprTracer, **params
) -> Union[Sequence[pe.DynamicJaxprTracer], pe.DynamicJaxprTracer]:
) -> Sequence[pe.DynamicJaxprTracer] | pe.DynamicJaxprTracer:
"""
Add new jaxpr equation to the jaxpr_trace and return new tracers.
"""
Expand Down
2 changes: 1 addition & 1 deletion pennylane/capture/expand_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"""
Helper function for expanding transforms with program capture
"""
from collections.abc import Callable
from functools import wraps
from typing import Callable

from .base_interpreter import PlxprInterpreter

Expand Down
6 changes: 2 additions & 4 deletions pennylane/capture/make_plxpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""The make_plxpr function and helper methods"""

from typing import Callable, Sequence, Union
from collections.abc import Callable, Sequence

import pennylane as qml

Expand All @@ -27,9 +27,7 @@
has_jax = False


def make_plxpr(
func: Callable, static_argnums: Union[int, Sequence[int]] = (), autograph=True, **kwargs
):
def make_plxpr(func: Callable, static_argnums: int | Sequence[int] = (), autograph=True, **kwargs):
r"""Takes a function and returns a ``Callable`` that, when called, produces a PLxPR representing
the function with the given args.

Expand Down
10 changes: 5 additions & 5 deletions pennylane/circuit_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
representation of a quantum circuit from an Operator queue.
"""
from collections import defaultdict, namedtuple
from collections.abc import Sequence
from functools import cached_property
from typing import Optional, Sequence, Union

import numpy as np
import rustworkx as rx
Expand Down Expand Up @@ -97,11 +97,11 @@ class CircuitGraph:
# pylint: disable=too-many-arguments, too-many-positional-arguments
def __init__(
self,
ops: list[Union[Operator, MeasurementProcess]],
obs: list[Union[MeasurementProcess, Operator]],
ops: list[Operator | MeasurementProcess],
obs: list[MeasurementProcess | Operator],
wires: Wires,
par_info: Optional[list[dict]] = None,
trainable_params: Optional[set[int]] = None,
par_info: list[dict] | None = None,
trainable_params: set[int] | None = None,
):
self._operations = ops
self._observables = obs
Expand Down
5 changes: 2 additions & 3 deletions pennylane/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from collections import defaultdict
from importlib import metadata, reload
from sys import version_info
from typing import List, Optional

from packaging.version import Version

Expand Down Expand Up @@ -114,7 +113,7 @@ def _reload_compilers():
_refresh_compilers()


def available_compilers() -> List[str]:
def available_compilers() -> list[str]:
"""Load and return a list of available compilers that are
installed and compatible with the :func:`~.qjit` decorator.

Expand Down Expand Up @@ -169,7 +168,7 @@ def available(compiler="catalyst") -> bool:
return compiler in AvailableCompilers.names_entrypoints


def active_compiler() -> Optional[str]:
def active_compiler() -> str | None:
"""Check which compiler is activated inside a :func:`~.qjit` evaluation context.

This helper function may be used during implementation
Expand Down
4 changes: 2 additions & 2 deletions pennylane/compiler/python_compiler/dialects/mbqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
catalyst/mlir/include/MBQC/IR/MBQCDialect.td file in the catalyst repository.
"""

from typing import Optional, TypeAlias
from typing import TypeAlias

from xdsl.dialects.builtin import I32, Float64Type, IntegerAttr, IntegerType
from xdsl.ir import Dialect, EnumAttribute, Operation, SSAValue
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(
in_qubit: QubitSSAValue | Operation,
plane: MeasurementPlaneAttr,
angle: SSAValue[Float64Type],
postselect: Optional[int | IntegerAttr] = None,
postselect: int | IntegerAttr | None = None,
):
properties = {"plane": plane}

Expand Down
3 changes: 2 additions & 1 deletion pennylane/compiler/python_compiler/dialects/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

# pragma: no cover

from typing import Sequence, TypeAlias
from collections.abc import Sequence
from typing import TypeAlias

from xdsl.dialects.builtin import (
I32,
Expand Down
3 changes: 2 additions & 1 deletion pennylane/compiler/python_compiler/jax_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

"""Utilities for translating JAX to xDSL"""

from collections.abc import Callable
from functools import wraps
from typing import Callable, TypeAlias
from typing import TypeAlias

import jaxlib
from catalyst import QJIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Core API for registering xDSL transforms for use with PennyLane and Catalyst."""

from typing import Callable
from collections.abc import Callable

from catalyst.from_plxpr import register_transform
from xdsl.passes import ModulePass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

import io
from typing import Callable
from collections.abc import Callable

from catalyst.compiler import _quantum_opt # pylint: disable=protected-access
from xdsl.context import Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from abc import abstractmethod
from dataclasses import dataclass
from itertools import islice
from typing import Optional

import jax
import jax.numpy as jnp
Expand Down Expand Up @@ -233,7 +232,7 @@ def get_postprocessing_funcs_from_module_and_insert(
cls,
postprocessing_module: builtin.ModuleOp,
matched_op: ir.Operation,
name: Optional[str] = None,
name: str | None = None,
) -> func.FuncOp:
"""Get the post-processing FuncOp from `postprocessing_module` (and any helper functions
also contained in `postprocessing_module`) and insert it (them) immediately after the FuncOp
Expand Down
5 changes: 2 additions & 3 deletions pennylane/concurrency/executors/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""

from enum import Enum
from typing import Union

from .external import DaskExec, MPICommExec, MPIPoolExec
from .native import MPPoolExec, ProcPoolExec, SerialExec, ThreadPoolExec
Expand Down Expand Up @@ -62,7 +61,7 @@ def get_supported_backends():
return _ExecBackendsMap


def get_executor(backend: Union[ExecBackends, str] = ExecBackends.MP_Pool):
def get_executor(backend: ExecBackends | str = ExecBackends.MP_Pool):
"""
Return the associated class type from the provided enumerated backends.
"""
Expand All @@ -71,7 +70,7 @@ def get_executor(backend: Union[ExecBackends, str] = ExecBackends.MP_Pool):
return _ExecBackendsMap[backend]


def create_executor(backend: Union[ExecBackends, str] = ExecBackends.MP_Pool, **kwargs):
def create_executor(backend: ExecBackends | str = ExecBackends.MP_Pool, **kwargs):
"""
Create an instance of the specified executor backend with forwarded keyword arguments
"""
Expand Down
Loading
Loading