Skip to content

Commit 52de5b9

Browse files
authored
Merge branch 'master' into timeout
2 parents 03d2a95 + 5a28c4a commit 52de5b9

File tree

14 files changed

+59
-131
lines changed

14 files changed

+59
-131
lines changed

Diff for: check/pylint

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ cd "$(git rev-parse --show-toplevel)"
1414
CIRQ_MODULES=$(env PYTHONPATH=. python dev_tools/modules.py list --mode package-path)
1515

1616
# Add dev_tools to $PYTHONPATH so that pylint can find custom checkers
17-
env PYTHONPATH=dev_tools pylint --rcfile=dev_tools/conf/.pylintrc "$@" $CIRQ_MODULES dev_tools examples
17+
env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc "$@" $CIRQ_MODULES dev_tools examples

Diff for: check/pylint-changed-files

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ echo "Found ${num_changed} lintable files associated with changes." >&2
6666
if [ "${num_changed}" -eq 0 ]; then
6767
exit 0
6868
fi
69-
env PYTHONPATH=dev_tools pylint --rcfile=dev_tools/conf/.pylintrc "${changed[@]}"
69+
env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc "${changed[@]}"

Diff for: cirq-core/cirq/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@
404404
transformer,
405405
two_qubit_matrix_to_cz_operations,
406406
two_qubit_matrix_to_diagonal_and_cz_operations,
407-
two_qubit_matrix_to_diagonal_and_operations,
408-
two_qubit_matrix_to_operations,
409407
two_qubit_matrix_to_sqrt_iswap_operations,
410408
two_qubit_gate_product_tabulation,
411409
TwoQubitCompilationTargetGateset,

Diff for: cirq-core/cirq/ops/clifford_gate.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -610,18 +610,18 @@ def I(cls):
610610
@property
611611
def X(cls):
612612
if getattr(cls, '_X', None) is None:
613-
cls._Z = cls._generate_clifford_from_known_gate(1, pauli_gates.X)
614-
return cls._Z
613+
cls._X = cls._generate_clifford_from_known_gate(1, pauli_gates.X)
614+
return cls._X
615615

616616
@property
617617
def Y(cls):
618-
if getattr(cls, '_X', None) is None:
619-
cls._Z = cls._generate_clifford_from_known_gate(1, pauli_gates.Y)
620-
return cls._Z
618+
if getattr(cls, '_Y', None) is None:
619+
cls._Y = cls._generate_clifford_from_known_gate(1, pauli_gates.Y)
620+
return cls._Y
621621

622622
@property
623623
def Z(cls):
624-
if getattr(cls, '_X', None) is None:
624+
if getattr(cls, '_Z', None) is None:
625625
cls._Z = cls._generate_clifford_from_known_gate(1, pauli_gates.Z)
626626
return cls._Z
627627

Diff for: cirq-core/cirq/ops/clifford_gate_test.py

+29-12
Original file line numberDiff line numberDiff line change
@@ -529,18 +529,26 @@ def test_text_diagram_info(gate, sym, exp):
529529
)
530530

531531

532-
def test_from_unitary():
533-
def _test(clifford_gate):
534-
u = cirq.unitary(clifford_gate)
535-
result_gate = cirq.SingleQubitCliffordGate.from_unitary(u)
536-
assert result_gate == clifford_gate
537-
538-
_test(cirq.SingleQubitCliffordGate.I)
539-
_test(cirq.SingleQubitCliffordGate.H)
540-
_test(cirq.SingleQubitCliffordGate.X)
541-
_test(cirq.SingleQubitCliffordGate.Y)
542-
_test(cirq.SingleQubitCliffordGate.Z)
543-
_test(cirq.SingleQubitCliffordGate.X_nsqrt)
532+
@pytest.mark.parametrize(
533+
"clifford_gate",
534+
(
535+
cirq.SingleQubitCliffordGate.I,
536+
cirq.SingleQubitCliffordGate.H,
537+
cirq.SingleQubitCliffordGate.X,
538+
cirq.SingleQubitCliffordGate.Y,
539+
cirq.SingleQubitCliffordGate.Z,
540+
cirq.SingleQubitCliffordGate.X_sqrt,
541+
cirq.SingleQubitCliffordGate.Y_sqrt,
542+
cirq.SingleQubitCliffordGate.Z_sqrt,
543+
cirq.SingleQubitCliffordGate.X_nsqrt,
544+
cirq.SingleQubitCliffordGate.Y_nsqrt,
545+
cirq.SingleQubitCliffordGate.Z_nsqrt,
546+
),
547+
)
548+
def test_from_unitary(clifford_gate):
549+
u = cirq.unitary(clifford_gate)
550+
result_gate = cirq.SingleQubitCliffordGate.from_unitary(u)
551+
assert result_gate == clifford_gate
544552

545553

546554
def test_from_unitary_with_phase_shift():
@@ -612,6 +620,15 @@ def test_common_clifford_gate(clifford_gate, standard_gate):
612620
cirq.testing.assert_allclose_up_to_global_phase(u_c, u_s, atol=1e-8)
613621

614622

623+
@pytest.mark.parametrize('clifford_gate_name', ("I", "X", "Y", "Z", "H", "S", "CNOT", "CZ", "SWAP"))
624+
def test_common_clifford_gate_caching(clifford_gate_name):
625+
cache_name = f"_{clifford_gate_name}"
626+
delattr(cirq.CliffordGate, cache_name)
627+
assert not hasattr(cirq.CliffordGate, cache_name)
628+
_ = getattr(cirq.CliffordGate, clifford_gate_name)
629+
assert hasattr(cirq.CliffordGate, cache_name)
630+
631+
615632
def test_multi_qubit_clifford_pow():
616633
assert cirq.CliffordGate.X ** -1 == cirq.CliffordGate.X
617634
assert cirq.CliffordGate.H ** -1 == cirq.CliffordGate.H

Diff for: cirq-core/cirq/optimizers/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@
8484
three_qubit_matrix_to_operations,
8585
two_qubit_matrix_to_cz_operations,
8686
two_qubit_matrix_to_diagonal_and_cz_operations,
87-
two_qubit_matrix_to_diagonal_and_operations,
88-
two_qubit_matrix_to_operations,
8987
two_qubit_matrix_to_sqrt_iswap_operations,
9088
)
9189

Diff for: cirq-core/cirq/transformers/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
three_qubit_matrix_to_operations,
3434
two_qubit_matrix_to_cz_operations,
3535
two_qubit_matrix_to_diagonal_and_cz_operations,
36-
two_qubit_matrix_to_diagonal_and_operations,
37-
two_qubit_matrix_to_operations,
3836
two_qubit_matrix_to_sqrt_iswap_operations,
3937
)
4038

Diff for: cirq-core/cirq/transformers/analytical_decompositions/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
from cirq.transformers.analytical_decompositions.two_qubit_to_cz import (
4545
two_qubit_matrix_to_cz_operations,
4646
two_qubit_matrix_to_diagonal_and_cz_operations,
47-
two_qubit_matrix_to_diagonal_and_operations,
48-
two_qubit_matrix_to_operations,
4947
)
5048

5149
from cirq.transformers.analytical_decompositions.two_qubit_to_fsim import (

Diff for: cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_cz.py

-62
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import numpy as np
2020

21-
from cirq import _compat
2221
from cirq.linalg import predicates
2322
from cirq.linalg.decompositions import num_cnots_required, extract_right_diag
2423

@@ -32,33 +31,6 @@
3231
import cirq
3332

3433

35-
@_compat.deprecated(fix='Please use cirq.two_qubit_matrix_to_cz_operations', deadline='v0.15')
36-
def two_qubit_matrix_to_operations(
37-
q0: 'cirq.Qid',
38-
q1: 'cirq.Qid',
39-
mat: np.ndarray,
40-
allow_partial_czs: bool,
41-
atol: float = 1e-8,
42-
clean_operations: bool = True,
43-
) -> List[ops.Operation]:
44-
"""Decomposes a two-qubit operation into Z/XY/CZ gates.
45-
46-
Args:
47-
q0: The first qubit being operated on.
48-
q1: The other qubit being operated on.
49-
mat: Defines the operation to apply to the pair of qubits.
50-
allow_partial_czs: Enables the use of Partial-CZ gates.
51-
atol: A limit on the amount of absolute error introduced by the
52-
construction.
53-
clean_operations: Enables optimizing resulting operation list by
54-
merging operations and ejecting phased Paulis and Z operations.
55-
56-
Returns:
57-
A list of operations implementing the matrix.
58-
"""
59-
return two_qubit_matrix_to_cz_operations(q0, q1, mat, allow_partial_czs, atol, clean_operations)
60-
61-
6234
def two_qubit_matrix_to_cz_operations(
6335
q0: 'cirq.Qid',
6436
q1: 'cirq.Qid',
@@ -89,40 +61,6 @@ def two_qubit_matrix_to_cz_operations(
8961
return operations
9062

9163

92-
@_compat.deprecated(
93-
fix='Please use cirq.two_qubit_matrix_to_diagonal_and_cz_operations', deadline='v0.15'
94-
)
95-
def two_qubit_matrix_to_diagonal_and_operations(
96-
q0: 'cirq.Qid',
97-
q1: 'cirq.Qid',
98-
mat: np.ndarray,
99-
allow_partial_czs: bool = False,
100-
atol: float = 1e-8,
101-
clean_operations: bool = True,
102-
) -> Tuple[np.ndarray, List['cirq.Operation']]:
103-
"""Decomposes a 2-qubit unitary to a diagonal and the remaining operations.
104-
105-
For a 2-qubit unitary V, return ops, a list of operations and
106-
D diagonal unitary, so that:
107-
V = cirq.Circuit(ops) @ D
108-
109-
Args:
110-
q0: The first qubit being operated on.
111-
q1: The other qubit being operated on.
112-
mat: the input unitary
113-
allow_partial_czs: Enables the use of Partial-CZ gates.
114-
atol: A limit on the amount of absolute error introduced by the
115-
construction.
116-
clean_operations: Enables optimizing resulting operation list by
117-
merging operations and ejecting phased Paulis and Z operations.
118-
Returns:
119-
tuple(ops,D): operations `ops`, and the diagonal `D`
120-
"""
121-
return two_qubit_matrix_to_diagonal_and_cz_operations(
122-
q0, q1, mat, allow_partial_czs, atol, clean_operations
123-
)
124-
125-
12664
def two_qubit_matrix_to_diagonal_and_cz_operations(
12765
q0: 'cirq.Qid',
12866
q1: 'cirq.Qid',

Diff for: cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py

-20
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,6 @@ def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01)
121121
assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
122122

123123

124-
def test_two_qubit_matrix_to_operations_deprecated():
125-
q0 = cirq.NamedQubit('q0')
126-
q1 = cirq.NamedQubit('q1')
127-
effect = np.array(
128-
[
129-
[0, 0, 0, 1],
130-
[0, 0, 1, 0],
131-
[0, 1, 0, 0],
132-
[1, 0, 0, 0j],
133-
]
134-
)
135-
136-
with cirq.testing.assert_deprecated('two_qubit_matrix_to_cz_operations', deadline='v0.15'):
137-
_ = cirq.two_qubit_matrix_to_operations(q0, q1, effect, True)
138-
with cirq.testing.assert_deprecated(
139-
'two_qubit_matrix_to_diagonal_and_cz_operations', deadline='v0.15'
140-
):
141-
_ = cirq.two_qubit_matrix_to_diagonal_and_operations(q0, q1, effect, True)
142-
143-
144124
@pytest.mark.parametrize(
145125
'max_partial_cz_depth,max_full_cz_depth,effect',
146126
[

Diff for: cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ def test_fsim_gate_with_symbols():
294294
c_new_sqrt_iswap_inv = cirq.Circuit(
295295
cirq.parameterized_2q_op_to_sqrt_iswap_operations(op, use_sqrt_iswap_inv=True)
296296
)
297-
for theta_val in np.linspace(0, 2 * np.pi, 12):
298-
for phi_val in np.linspace(0, 2 * np.pi, 12):
297+
for theta_val in np.linspace(0, 2 * np.pi, 4):
298+
for phi_val in np.linspace(0, 2 * np.pi, 6):
299299
cirq.testing.assert_allclose_up_to_global_phase(
300300
cirq.unitary(cirq.resolve_parameters(op, {'theta': theta_val, 'phi': phi_val})),
301301
cirq.unitary(

Diff for: cirq-web/cirq_ts/package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dev_tools/bash_scripts_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def test_pylint_changed_files_file_selection(tmpdir_factory):
638638
)
639639

640640
intercepted_prefix = (
641-
'INTERCEPTED env PYTHONPATH=dev_tools pylint --rcfile=dev_tools/conf/.pylintrc '
641+
'INTERCEPTED env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc '
642642
)
643643

644644
result = run(

Diff for: docs/noise.ipynb

+16-15
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"id": "708b5b720a74"
117117
},
118118
"source": [
119-
"Cirq defines many commonly used quantum channels in [`ops/common_channels.py`](https://github.com/quantumlib/Cirq/blob/master/cirq/ops/common_channels.py). For example, the single-qubit bit-flip channel\n",
119+
"Cirq defines many commonly used quantum channels in [`ops/common_channels.py`](https://github.com/quantumlib/Cirq/blob/master/cirq-core/cirq/ops/common_channels.py). For example, the single-qubit bit-flip channel\n",
120120
"\n",
121121
"$$\n",
122122
"\\rho \\rightarrow (1 - p) \\rho + p X \\rho X\n",
@@ -145,7 +145,7 @@
145145
"id": "f1f501177e53"
146146
},
147147
"source": [
148-
"To see the Kraus operators of a channel, the `cirq.channel` protocol can be used. (See the [protocols guide](./protocols.ipynb).)"
148+
"To see the Kraus operators of a channel, the `cirq.kraus` protocol can be used. (See the [protocols guide](./protocols.ipynb).)"
149149
]
150150
},
151151
{
@@ -282,7 +282,7 @@
282282
"id": "ddbc622c98da"
283283
},
284284
"source": [
285-
"## The `channel` and `mixture` protocols"
285+
"## The `kraus` and `mixture` protocols"
286286
]
287287
},
288288
{
@@ -291,7 +291,7 @@
291291
"id": "2dee355d2ae8"
292292
},
293293
"source": [
294-
"We have seen the `cirq.channel` protocol which returns the Kraus operators of a channel. Some channels have the interpretation of randomly applying a single unitary Kraus operator $U_k$ with probability $p_k$, namely\n",
294+
"We have seen the `cirq.kraus` protocol which returns the Kraus operators of a channel. Some channels have the interpretation of randomly applying a single unitary Kraus operator $U_k$ with probability $p_k$, namely\n",
295295
"\n",
296296
"$$\n",
297297
"\\rho \\rightarrow \\sum_k p_k U_k \\rho U_k^\\dagger {\\rm ~where~} \\sum_k p_k =1 {\\rm ~and~ U_k U_k^\\dagger= I}.\n",
@@ -361,9 +361,9 @@
361361
"source": [
362362
"To summarize:\n",
363363
"\n",
364-
"* Every `Gate` in Cirq supports the `cirq.channel` protocol.\n",
365-
" - If magic method `_kraus_` is not defined, `cirq.channel` looks for `_mixture_` then for `_unitary_`.\n",
366-
"* A subset of channels which support `cirq.channel` also support the `cirq.mixture` protocol.\n",
364+
"* Every `Gate` in Cirq supports the `cirq.kraus` protocol.\n",
365+
" - If magic method `_kraus_` is not defined, `cirq.kraus` looks for `_mixture_` then for `_unitary_`.\n",
366+
"* A subset of channels which support `cirq.kraus` also support the `cirq.mixture` protocol.\n",
367367
" - If magic method `_mixture_` is not defined, `cirq.mixture` looks for `_unitary_`.\n",
368368
"* A subset of channels which support `cirq.mixture` also support the `cirq.unitary` protocol."
369369
]
@@ -377,11 +377,11 @@
377377
"For concrete examples, consider `cirq.X`, `cirq.BitFlipChannel`, and `cirq.AmplitudeDampingChannel` which are all subclasses of `cirq.Gate`.\n",
378378
"\n",
379379
"* `cirq.X` defines the `_unitary_` method. \n",
380-
" - As a result, it supports the `cirq.unitary` protocol, the `cirq.mixture` protocol, and the `cirq.channel` protocol.\n",
380+
" - As a result, it supports the `cirq.unitary` protocol, the `cirq.mixture` protocol, and the `cirq.kraus` protocol.\n",
381381
"* `cirq.BitFlipChannel` defines the `_mixture_` method but not the `_unitary_` method.\n",
382-
" - As a result, it only supports the `cirq.mixture` protocol and the `cirq.channel` protocol.\n",
382+
" - As a result, it only supports the `cirq.mixture` protocol and the `cirq.kraus` protocol.\n",
383383
"* `cirq.AmplitudeDampingChannel` defines the `_kraus_` method, but not the `_mixture_` method or the `_unitary_` method.\n",
384-
" - As a result, it only supports the `cirq.channel` protocol."
384+
" - As a result, it only supports the `cirq.kraus` protocol."
385385
]
386386
},
387387
{
@@ -425,7 +425,7 @@
425425
" (0.9, np.array([[1, 0], [0, 1]], dtype=np.complex64)),\n",
426426
" (0.1, np.array([[0, 1], [1, 0]], dtype=np.complex64)),\n",
427427
"]\n",
428-
"bit_flip = cirq.MixedUnitaryChannel(mix)\n",
428+
"bit_flip_mix = cirq.MixedUnitaryChannel(mix)\n",
429429
"\n",
430430
"# This is equivalent to an X-basis measurement.\n",
431431
"ops = [\n",
@@ -436,7 +436,7 @@
436436
"\n",
437437
"# These circuits have the same behavior.\n",
438438
"circuit = cirq.Circuit(\n",
439-
" bit_flip.on(q0),\n",
439+
" bit_flip_mix.on(q0),\n",
440440
" cirq.H(q0),\n",
441441
" x_meas.on(q0),\n",
442442
")\n",
@@ -531,7 +531,7 @@
531531
"id": "72486a155131"
532532
},
533533
"source": [
534-
"Note: Since `_mixture_` is defined, the `cirq.channel` protocol can also be used."
534+
"Note: Since `_mixture_` is defined, the `cirq.kraus` protocol can also be used."
535535
]
536536
},
537537
{
@@ -890,7 +890,7 @@
890890
"id": "11b18c640767"
891891
},
892892
"source": [
893-
"Another technique is to pass a noise channel to the density matrix simulator as shown below."
893+
"Another technique is to directly pass a `cirq.NoiseModel`, or a value that can be trivially converted into one, to the density matrix simulator as shown below."
894894
]
895895
},
896896
{
@@ -901,7 +901,8 @@
901901
},
902902
"outputs": [],
903903
"source": [
904-
"\"\"\"Define a density matrix simulator with a noise model.\"\"\"\n",
904+
"\"\"\"Define a density matrix simulator with a `cirq.NOISE_MODEL_LIKE` object.\"\"\"\n",
905+
"\n",
905906
"noisy_dsim = cirq.DensityMatrixSimulator(\n",
906907
" noise=cirq.generalized_amplitude_damp(p=0.1, gamma=0.5)\n",
907908
")"

0 commit comments

Comments
 (0)