Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def __init__(
known_qubit_count: int | None,
use_unicode_characters: bool,
precision: int | None,
label_map: dict[cirq.LabelEntity, int] | None,
label_map: dict[LabelEntity, int] | None,
include_tags: bool = True,
transpose: bool = False,
) -> None:
Expand Down
10 changes: 5 additions & 5 deletions cirq-core/cirq/transformers/transformer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class TRANSFORMER(Protocol):
>>> def convert_to_cz(
... circuit: cirq.AbstractCircuit,
... *,
... context: 'Optional[cirq.TransformerContext]' = None,
... context: cirq.TransformerContext | None = None,
... atol: float = 1e-8,
... ) -> cirq.Circuit:
... ...
Expand All @@ -245,7 +245,7 @@ class TRANSFORMER(Protocol):
... self,
... circuit: cirq.AbstractCircuit,
... *,
... context: 'Optional[cirq.TransformerContext]' = None,
... context: cirq.TransformerContext | None = None,
... ) -> cirq.AbstractCircuit:
... ...
"""
Expand Down Expand Up @@ -288,7 +288,7 @@ def transformer(cls_or_func: Any = None, *, add_deep_support: bool = False) -> A

>>> @cirq.transformer
... def convert_to_cz(
... circuit: cirq.AbstractCircuit, *, context: 'Optional[cirq.TransformerContext]' = None
... circuit: cirq.AbstractCircuit, *, context: cirq.TransformerContext | None = None
... ) -> cirq.Circuit:
... ...

Expand All @@ -302,7 +302,7 @@ def transformer(cls_or_func: Any = None, *, add_deep_support: bool = False) -> A
... self,
... circuit: cirq.AbstractCircuit,
... *,
... context: 'Optional[cirq.TransformerContext]' = None,
... context: cirq.TransformerContext | None = None,
... ) -> cirq.Circuit:
... ...

Expand All @@ -313,7 +313,7 @@ def transformer(cls_or_func: Any = None, *, add_deep_support: bool = False) -> A
... def convert_to_sqrt_iswap(
... circuit: cirq.AbstractCircuit,
... *,
... context: 'Optional[cirq.TransformerContext]' = None,
... context: cirq.TransformerContext | None = None,
... atol: float = 1e-8,
... sqrt_iswap_gate: cirq.ISwapPowGate = cirq.SQRT_ISWAP_INV,
... cleanup_operations: bool = True,
Expand Down
8 changes: 4 additions & 4 deletions docs/dev/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ interactive session. The recommended way to achieve that is illustrated in the
example below.

```python
from typing import Any, List, Optional
from typing import Any
import matplotlib.pyplot as plt

class Foo:
...
def plot(self, ax: Optional[plt.Axes]=None, **plot_kwargs: Any) -> plt.Axes:
def plot(self, ax: plt.Axes | None = None, **plot_kwargs: Any) -> plt.Axes:
show_plot = not ax
if ax is None:
fig, ax = plt.subplots(1, 1) # or your favorite figure setup
Expand Down Expand Up @@ -78,8 +78,8 @@ not sufficient. The `plot` method of such a class should take an optional
```python
class Foo:
...
def plot(self, axes: Optional[List[plt.Axes]]=None,
**plot_kwargs: Any) -> List[plt.Axes]:
def plot(self, axes: list[plt.Axes] | None = None,
**plot_kwargs: Any) -> list[plt.Axes]:
show_plot = not axes
if axes is None:
fig, axes = plt.subplots(1, 2) # or your favorite figure setup
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ qubit = cirq.NamedQubit('a')
```
The one exception to this is for the typing code, where we prefer the direct import
```python
from typing import List
from typing import Mapping
```
This exception allows typing hints to be more compact.

Expand Down
16 changes: 8 additions & 8 deletions docs/experiments/shor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"\n",
"import numpy as np\n",
"import sympy\n",
"from typing import Callable, Iterable, List, Optional, Sequence\n",
"from typing import Callable, Iterable, Sequence\n",
"\n",
"import cirq"
]
Expand Down Expand Up @@ -165,7 +165,7 @@
"outputs": [],
"source": [
"\"\"\"Function to compute the elements of Z_n.\"\"\"\n",
"def multiplicative_group(n: int) -> List[int]:\n",
"def multiplicative_group(n: int) -> list[int]:\n",
" \"\"\"Returns the multiplicative group modulo n.\n",
" \n",
" Args:\n",
Expand Down Expand Up @@ -245,7 +245,7 @@
"outputs": [],
"source": [
"\"\"\"Function for classically computing the order of an element of Z_n.\"\"\"\n",
"def classical_order_finder(x: int, n: int) -> Optional[int]:\n",
"def classical_order_finder(x: int, n: int) -> int | None:\n",
" \"\"\"Computes smallest positive r such that x**r mod n == 1.\n",
"\n",
" Args:\n",
Expand Down Expand Up @@ -828,7 +828,7 @@
},
"outputs": [],
"source": [
"def process_measurement(result: cirq.Result, x: int, n: int) -> Optional[int]:\n",
"def process_measurement(result: cirq.Result, x: int, n: int) -> int | None:\n",
" \"\"\"Interprets the output of the order finding circuit.\n",
"\n",
" Specifically, it determines s/r such that exp(2πis/r) is an eigenvalue\n",
Expand Down Expand Up @@ -936,7 +936,7 @@
},
"outputs": [],
"source": [
"def quantum_order_finder(x: int, n: int) -> Optional[int]:\n",
"def quantum_order_finder(x: int, n: int) -> int | None:\n",
" \"\"\"Computes smallest positive r such that x**r mod n == 1.\n",
" \n",
" Args:\n",
Expand Down Expand Up @@ -1004,7 +1004,7 @@
"outputs": [],
"source": [
"\"\"\"Functions for factoring from start to finish.\"\"\"\n",
"def find_factor_of_prime_power(n: int) -> Optional[int]:\n",
"def find_factor_of_prime_power(n: int) -> int | None:\n",
" \"\"\"Returns non-trivial factor of n if n is a prime power, else None.\"\"\"\n",
" for k in range(2, math.floor(math.log2(n)) + 1):\n",
" c = math.pow(n, 1 / k)\n",
Expand All @@ -1019,9 +1019,9 @@
"\n",
"def find_factor(\n",
" n: int,\n",
" order_finder: Callable[[int, int], Optional[int]] = quantum_order_finder,\n",
" order_finder: Callable[[int, int], int | None] = quantum_order_finder,\n",
" max_attempts: int = 30\n",
") -> Optional[int]:\n",
") -> int | None:\n",
" \"\"\"Returns a non-trivial factor of composite integer n.\n",
"\n",
" Args:\n",
Expand Down
2 changes: 0 additions & 2 deletions docs/named_topologies.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
},
"outputs": [],
"source": [
"from typing import Iterable, List, Optional, Sequence\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import networkx as nx"
Expand Down
6 changes: 3 additions & 3 deletions docs/noise/qcvv/xeb_calibration_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@
"outputs": [],
"source": [
"#@title Helper functions\n",
"from typing import Optional, Sequence\n",
"from typing import Sequence\n",
"\n",
"\n",
"def create_random_circuit(\n",
" qubits: Sequence[cirq.GridQubit],\n",
" cycles: int,\n",
" twoq_gate: cirq.Gate = cirq.FSimGate(np.pi / 4, 0.0),\n",
" seed: Optional[int] = None,\n",
" seed: int | None = None,\n",
") -> cirq.Circuit:\n",
" return rqcg.random_rotations_between_grid_interaction_layers_circuit(\n",
" qubits, \n",
Expand All @@ -191,7 +191,7 @@
" qubits: Sequence[cirq.GridQubit],\n",
" cycles: int,\n",
" twoq_gate: cirq.Gate = cirq.FSimGate(np.pi / 4, 0.0),\n",
" seed: Optional[int] = None,\n",
" seed: int | None = None,\n",
") -> cirq.Circuit:\n",
" \"\"\"Returns a Loschmidt echo circuit using a random unitary U.\n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/google/echoes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
},
"outputs": [],
"source": [
"from typing import Optional, Sequence\n",
"from typing import Sequence\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
Expand Down Expand Up @@ -201,8 +201,8 @@
" qubits: Sequence[cirq.GridQubit],\n",
" cycles: int,\n",
" twoq_gate: cirq.Gate = cirq.FSimGate(np.pi / 4, 0.0),\n",
" pause: Optional[cirq.Duration] = None,\n",
" seed: Optional[int] = None,\n",
" pause: cirq.Duration | None = None,\n",
" seed: int | None = None,\n",
") -> cirq.Circuit:\n",
" \"\"\"Returns a Loschmidt echo circuit using a random unitary U.\n",
" \n",
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/google/spin_echoes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"outputs": [],
"source": [
"# @markdown Helper functions.\n",
"from typing import Optional, Sequence\n",
"from typing import Sequence\n",
"from cirq.experiments import random_rotations_between_grid_interaction_layers_circuit\n",
"\n",
"\n",
Expand All @@ -172,7 +172,7 @@
" qubits: Sequence[cirq.GridQubit],\n",
" cycles: int,\n",
" twoq_gate: cirq.Gate = cirq.SQRT_ISWAP,\n",
" seed: Optional[int] = None,\n",
" seed: int | None = None,\n",
" with_optimization: bool = False,\n",
" with_alignment: bool = False,\n",
" with_spin_echoes: bool = False,\n",
Expand Down