From 4de05e6fa3cfb27cd2ef1bd0f4a2a3881f94ac1c Mon Sep 17 00:00:00 2001 From: vtomole Date: Sat, 2 Jul 2022 23:44:25 -0500 Subject: [PATCH 01/11] Assert equivalent repr for SingleQubitCliffordgate and CliffordTableau --- cirq-core/cirq/ops/clifford_gate.py | 11 +--- cirq-core/cirq/ops/clifford_gate_test.py | 2 +- cirq-core/cirq/qis/clifford_tableau.py | 60 ++++++++++++++------- cirq-core/cirq/qis/clifford_tableau_test.py | 3 +- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/cirq-core/cirq/ops/clifford_gate.py b/cirq-core/cirq/ops/clifford_gate.py index 5c359a0d337..a74f12f1c7c 100644 --- a/cirq-core/cirq/ops/clifford_gate.py +++ b/cirq-core/cirq/ops/clifford_gate.py @@ -879,16 +879,7 @@ def equivalent_gate_before(self, after: 'SingleQubitCliffordGate') -> 'SingleQub return self.merged_with(after).merged_with(self**-1) def __repr__(self) -> str: - x = self.pauli_tuple(pauli_gates.X) - y = self.pauli_tuple(pauli_gates.Y) - z = self.pauli_tuple(pauli_gates.Z) - x_sign = '-' if x[1] else '+' - y_sign = '-' if y[1] else '+' - z_sign = '-' if z[1] else '+' - return ( - f'cirq.SingleQubitCliffordGate(X:{x_sign}{x[0]!s}, ' - f'Y:{y_sign}{y[0]!s}, Z:{z_sign}{z[0]!s})' - ) + return f'cirq.SingleQubitCliffordGate(_clifford_tableau={repr(self._clifford_tableau)})' def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' diff --git a/cirq-core/cirq/ops/clifford_gate_test.py b/cirq-core/cirq/ops/clifford_gate_test.py index 0c65c780966..1b26ca5848c 100644 --- a/cirq-core/cirq/ops/clifford_gate_test.py +++ b/cirq-core/cirq/ops/clifford_gate_test.py @@ -338,7 +338,7 @@ def test_eq_ne_and_hash(): ), ) def test_repr(gate, rep): - assert repr(gate) == rep + cirq.testing.assert_equivalent_repr(gate) @pytest.mark.parametrize( diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index f88d43d521c..11ae8c7dae4 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -13,10 +13,11 @@ # limitations under the License. import abc -from typing import Any, Dict, List, Sequence, TYPE_CHECKING +from typing import Any, Dict, List, Optional, Sequence, TYPE_CHECKING import numpy as np from cirq import protocols +from cirq._compat import proper_repr from cirq.qis import quantum_state_representation from cirq.value import big_endian_int_to_digits, linear_dict @@ -137,7 +138,14 @@ class CliffordTableau(StabilizerState): an eigenoperator of the state vector with eigenvalue one: P|psi> = |psi>. """ - def __init__(self, num_qubits, initial_state: int = 0): + def __init__( + self, + num_qubits, + initial_state: int = 0, + rs: Optional[np.ndarray] = None, + xs: Optional[np.ndarray] = None, + zs: Optional[np.ndarray] = None, + ): """Initializes CliffordTableau Args: num_qubits: The number of qubits in the system. @@ -145,22 +153,32 @@ def __init__(self, num_qubits, initial_state: int = 0): state as a big endian int. """ self.n = num_qubits + self.initial_state = initial_state + + if rs is None: + # The last row (`2n+1`-th row) is the scratch row used in _measurement + # computation process only. It should not be exposed to external usage. + self._rs = np.zeros(2 * self.n + 1, dtype=bool) + for (i, val) in enumerate( + big_endian_int_to_digits(initial_state, digit_count=num_qubits, base=2) + ): + self._rs[self.n + i] = bool(val) + else: + self._rs = rs + + if xs is None: + self._xs = np.zeros((2 * self.n + 1, self.n), dtype=bool) + for i in range(self.n): + self._xs[i, i] = True + else: + self._xs = xs - # The last row (`2n+1`-th row) is the scratch row used in _measurement - # computation process only. It should not be exposed to external usage. - self._rs = np.zeros(2 * self.n + 1, dtype=bool) - - for (i, val) in enumerate( - big_endian_int_to_digits(initial_state, digit_count=num_qubits, base=2) - ): - self._rs[self.n + i] = bool(val) - - self._xs = np.zeros((2 * self.n + 1, self.n), dtype=bool) - self._zs = np.zeros((2 * self.n + 1, self.n), dtype=bool) - - for i in range(self.n): - self._xs[i, i] = True - self._zs[self.n + i, i] = True + if xs is None: + self._zs = np.zeros((2 * self.n + 1, self.n), dtype=bool) + for i in range(self.n): + self._zs[self.n + i, i] = True + else: + self._zs = zs @property def xs(self) -> np.ndarray: @@ -233,8 +251,12 @@ def copy(self, deep_copy_buffers: bool = True) -> 'CliffordTableau': return state def __repr__(self) -> str: - stabilizers = ", ".join([repr(stab) for stab in self.stabilizers()]) - return f'stabilizers: [{stabilizers}]' + return ( + f"cirq.CliffordTableau({self.n},rs={proper_repr(self._rs)}, " + f"xs={proper_repr(self._xs)}," + f"zs={proper_repr(self._zs)}, " + f"initial_state={self.initial_state})" + ) def __str__(self) -> str: string = '' diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index b8d5add1d47..ccb309a60c4 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -271,8 +271,7 @@ def test_str(): def test_repr(): - t = cirq.CliffordTableau(num_qubits=1) - assert repr(t) == "stabilizers: [cirq.DensePauliString('Z', coefficient=(1+0j))]" + cirq.testing.assert_equivalent_repr(cirq.CliffordTableau(num_qubits=1)) def test_str_full(): From 7363251c4b3ee46e52a7e52534dc13357db7a612 Mon Sep 17 00:00:00 2001 From: vtomole Date: Sun, 3 Jul 2022 00:02:27 -0500 Subject: [PATCH 02/11] Add previosuly failing example --- cirq-core/cirq/ops/clifford_gate_test.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cirq-core/cirq/ops/clifford_gate_test.py b/cirq-core/cirq/ops/clifford_gate_test.py index 1b26ca5848c..d6581419aaf 100644 --- a/cirq-core/cirq/ops/clifford_gate_test.py +++ b/cirq-core/cirq/ops/clifford_gate_test.py @@ -329,18 +329,24 @@ def test_eq_ne_and_hash(): @pytest.mark.parametrize( - 'gate,rep', + 'gate', ( - (cirq.SingleQubitCliffordGate.I, 'cirq.SingleQubitCliffordGate(X:+X, Y:+Y, Z:+Z)'), - (cirq.SingleQubitCliffordGate.H, 'cirq.SingleQubitCliffordGate(X:+Z, Y:-Y, Z:+X)'), - (cirq.SingleQubitCliffordGate.X, 'cirq.SingleQubitCliffordGate(X:+X, Y:-Y, Z:-Z)'), - (cirq.SingleQubitCliffordGate.X_sqrt, 'cirq.SingleQubitCliffordGate(X:+X, Y:+Z, Z:-Y)'), + cirq.SingleQubitCliffordGate.I, + cirq.SingleQubitCliffordGate.H, + cirq.SingleQubitCliffordGate.X, + cirq.SingleQubitCliffordGate.X_sqrt, ), ) -def test_repr(gate, rep): +def test_repr_gate(gate): cirq.testing.assert_equivalent_repr(gate) +def test_repr_operation(): + cirq.testing.assert_equivalent_repr( + cirq.SingleQubitCliffordGate.from_pauli(cirq.Z).on(cirq.LineQubit(2)) + ) + + @pytest.mark.parametrize( 'gate,trans_y', ( From 14b6a80f163e6ca8bf6bd38328b28755056dad52 Mon Sep 17 00:00:00 2001 From: vtomole Date: Sun, 3 Jul 2022 00:07:37 -0500 Subject: [PATCH 03/11] Clean up --- cirq-core/cirq/ops/clifford_gate.py | 2 +- cirq-core/cirq/qis/clifford_tableau.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/ops/clifford_gate.py b/cirq-core/cirq/ops/clifford_gate.py index a74f12f1c7c..9ccae78f6d1 100644 --- a/cirq-core/cirq/ops/clifford_gate.py +++ b/cirq-core/cirq/ops/clifford_gate.py @@ -879,7 +879,7 @@ def equivalent_gate_before(self, after: 'SingleQubitCliffordGate') -> 'SingleQub return self.merged_with(after).merged_with(self**-1) def __repr__(self) -> str: - return f'cirq.SingleQubitCliffordGate(_clifford_tableau={repr(self._clifford_tableau)})' + return f'cirq.SingleQubitCliffordGate(_clifford_tableau={self._clifford_tableau!r})' def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 11ae8c7dae4..ea85e9dcfdc 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -160,7 +160,7 @@ def __init__( # computation process only. It should not be exposed to external usage. self._rs = np.zeros(2 * self.n + 1, dtype=bool) for (i, val) in enumerate( - big_endian_int_to_digits(initial_state, digit_count=num_qubits, base=2) + big_endian_int_to_digits(self.initial_state, digit_count=num_qubits, base=2) ): self._rs[self.n + i] = bool(val) else: From cae0b4eb98eea1a5c537b0022a311811069d6ded Mon Sep 17 00:00:00 2001 From: vtomole Date: Sun, 3 Jul 2022 00:09:58 -0500 Subject: [PATCH 04/11] Minor format to repr --- cirq-core/cirq/qis/clifford_tableau.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index ea85e9dcfdc..4b3eac211d5 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -252,7 +252,8 @@ def copy(self, deep_copy_buffers: bool = True) -> 'CliffordTableau': def __repr__(self) -> str: return ( - f"cirq.CliffordTableau({self.n},rs={proper_repr(self._rs)}, " + f"cirq.CliffordTableau({self.n}," + f"rs={proper_repr(self._rs)}, " f"xs={proper_repr(self._xs)}," f"zs={proper_repr(self._zs)}, " f"initial_state={self.initial_state})" From 48542a46eeaa0f2470aa3bbef21df444115f0d40 Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 14:01:12 -0500 Subject: [PATCH 05/11] respond to review --- cirq-core/cirq/ops/clifford_gate.py | 2 +- cirq-core/cirq/qis/clifford_tableau.py | 71 +++++++++++++++++---- cirq-core/cirq/qis/clifford_tableau_test.py | 9 +++ 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/cirq-core/cirq/ops/clifford_gate.py b/cirq-core/cirq/ops/clifford_gate.py index 9ccae78f6d1..7c9b47e0787 100644 --- a/cirq-core/cirq/ops/clifford_gate.py +++ b/cirq-core/cirq/ops/clifford_gate.py @@ -879,7 +879,7 @@ def equivalent_gate_before(self, after: 'SingleQubitCliffordGate') -> 'SingleQub return self.merged_with(after).merged_with(self**-1) def __repr__(self) -> str: - return f'cirq.SingleQubitCliffordGate(_clifford_tableau={self._clifford_tableau!r})' + return f'cirq.CliffordGate.from_clifford_tableau({self.clifford_tableau!r})' def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 4b3eac211d5..209cf5189d3 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -154,31 +154,74 @@ def __init__( """ self.n = num_qubits self.initial_state = initial_state + self._rs = self._reconstruct_rs(rs) + self._xs = self._reconstruct_xs(xs) + self._zs = self._reconstruct_zs(zs) + def _reconstruct_rs(self, rs: Optional[np.ndarray]) -> np.ndarray: if rs is None: # The last row (`2n+1`-th row) is the scratch row used in _measurement # computation process only. It should not be exposed to external usage. - self._rs = np.zeros(2 * self.n + 1, dtype=bool) + new_rs = np.zeros(2 * self.n + 1, dtype=bool) for (i, val) in enumerate( - big_endian_int_to_digits(self.initial_state, digit_count=num_qubits, base=2) + big_endian_int_to_digits(self.initial_state, digit_count=self.n, base=2) ): - self._rs[self.n + i] = bool(val) + new_rs[self.n + i] = bool(val) else: - self._rs = rs + shape = rs.shape + if len(shape) == 1 and shape[0] == 2 * self.n and rs.dtype == np.dtype(bool): + new_rs = np.append(rs, np.zeros(1, dtype=bool)) + else: + raise ValueError( + f"The value you passed for rs is not the correct shape and/or type. " + f"Please confirm that it's 1 row, of even length and of type bool" + ) + return new_rs + def _reconstruct_xs(self, xs: Optional[np.ndarray]) -> np.ndarray: if xs is None: - self._xs = np.zeros((2 * self.n + 1, self.n), dtype=bool) + new_xs = np.zeros((2 * self.n + 1, self.n), dtype=bool) for i in range(self.n): - self._xs[i, i] = True + new_xs[i, i] = True else: - self._xs = xs + shape = xs.shape + if ( + len(shape) == 2 + and shape[0] == 2 * self.n + and shape[1] == self.n + and xs.dtype == np.dtype(bool) + ): + new_xs = np.append(xs, np.zeros((1, self.n), dtype=bool), axis=0) + else: + raise ValueError( + f"The value you passed for xs is not the correct shape and/or type. " + f"Please confirm that it's 2*num_qubits rows, num_qubits columns, " + f"and of type bool." + ) + return new_xs - if xs is None: - self._zs = np.zeros((2 * self.n + 1, self.n), dtype=bool) + def _reconstruct_zs(self, zs: Optional[np.ndarray]) -> np.ndarray: + + if zs is None: + new_zs = np.zeros((2 * self.n + 1, self.n), dtype=bool) for i in range(self.n): - self._zs[self.n + i, i] = True + new_zs[self.n + i, i] = True else: - self._zs = zs + shape = zs.shape + if ( + len(shape) == 2 + and shape[0] == 2 * self.n + and shape[1] == self.n + and zs.dtype == np.dtype(bool) + ): + new_zs = np.append(zs, np.zeros((1, self.n), dtype=bool), axis=0) + else: + raise ValueError( + f"The value you passed for zs is not the correct shape and/or type. " + f"Please confirm that it's 2*num_qubits rows,num_qubits columns, " + f"and of type bool." + ) + return new_zs @property def xs(self) -> np.ndarray: @@ -253,9 +296,9 @@ def copy(self, deep_copy_buffers: bool = True) -> 'CliffordTableau': def __repr__(self) -> str: return ( f"cirq.CliffordTableau({self.n}," - f"rs={proper_repr(self._rs)}, " - f"xs={proper_repr(self._xs)}," - f"zs={proper_repr(self._zs)}, " + f"rs={proper_repr(np.delete(self._rs, len(self._rs)-1))}, " + f"xs={proper_repr(np.delete(self._xs, len(self._xs)-1, axis=0))}," + f"zs={proper_repr(np.delete(self._zs, len(self._zs)-1, axis=0))}, " f"initial_state={self.initial_state})" ) diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index ccb309a60c4..6904dc199cd 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -54,6 +54,15 @@ def test_tableau_initial_state_string(num_qubits): expected_string = sign + 'I ' * n + 'Z ' + 'I ' * (num_qubits - n - 1) assert splitted_represent_string[n] == expected_string +def test_tableau_imvalid_initial_state(): + with pytest.raises(ValueError, match="1 row, of even length and of type bool"): + cirq.CliffordTableau(1, rs=np.zeros(1, dtype=bool)) + + with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool"): + cirq.CliffordTableau(1, xs=np.zeros(1, dtype=bool)) + + with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool"): + cirq.CliffordTableau(1, zs=np.zeros(1, dtype=bool)) def test_stabilizers(): # Note: the stabilizers are not unique for one state. We just use the one From a129ae293d5e84f7385838fba9295c741f78e3bd Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 14:02:52 -0500 Subject: [PATCH 06/11] Format --- cirq-core/cirq/qis/clifford_tableau_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index 6904dc199cd..3774a36a7c5 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -54,6 +54,7 @@ def test_tableau_initial_state_string(num_qubits): expected_string = sign + 'I ' * n + 'Z ' + 'I ' * (num_qubits - n - 1) assert splitted_represent_string[n] == expected_string + def test_tableau_imvalid_initial_state(): with pytest.raises(ValueError, match="1 row, of even length and of type bool"): cirq.CliffordTableau(1, rs=np.zeros(1, dtype=bool)) @@ -64,6 +65,7 @@ def test_tableau_imvalid_initial_state(): with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool"): cirq.CliffordTableau(1, zs=np.zeros(1, dtype=bool)) + def test_stabilizers(): # Note: the stabilizers are not unique for one state. We just use the one # produced by the tableau algorithm. From 9ed5e77c9c22c788a86665516eeb22e37958fbc2 Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 14:07:32 -0500 Subject: [PATCH 07/11] Minor space --- cirq-core/cirq/qis/clifford_tableau.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 209cf5189d3..9baf5d35ba8 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -218,7 +218,7 @@ def _reconstruct_zs(self, zs: Optional[np.ndarray]) -> np.ndarray: else: raise ValueError( f"The value you passed for zs is not the correct shape and/or type. " - f"Please confirm that it's 2*num_qubits rows,num_qubits columns, " + f"Please confirm that it's 2*num_qubits rows, num_qubits columns, " f"and of type bool." ) return new_zs From eb9ef39af8c65e260167fdc5afad612915340b84 Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 14:12:38 -0500 Subject: [PATCH 08/11] Move minor comments --- cirq-core/cirq/qis/clifford_tableau.py | 5 +++-- cirq-core/cirq/qis/clifford_tableau_test.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 9baf5d35ba8..1e2adbf0877 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -154,14 +154,15 @@ def __init__( """ self.n = num_qubits self.initial_state = initial_state + # _reconstruct_* adds the last row (`2n+1`-th row) to the input arrays, + # which is the scratch row used in _measurement + # computation process only. It should not be exposed to external usage. self._rs = self._reconstruct_rs(rs) self._xs = self._reconstruct_xs(xs) self._zs = self._reconstruct_zs(zs) def _reconstruct_rs(self, rs: Optional[np.ndarray]) -> np.ndarray: if rs is None: - # The last row (`2n+1`-th row) is the scratch row used in _measurement - # computation process only. It should not be exposed to external usage. new_rs = np.zeros(2 * self.n + 1, dtype=bool) for (i, val) in enumerate( big_endian_int_to_digits(self.initial_state, digit_count=self.n, base=2) diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index 3774a36a7c5..6ae15dacf8f 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -55,7 +55,7 @@ def test_tableau_initial_state_string(num_qubits): assert splitted_represent_string[n] == expected_string -def test_tableau_imvalid_initial_state(): +def test_tableau_ivalid_initial_state(): with pytest.raises(ValueError, match="1 row, of even length and of type bool"): cirq.CliffordTableau(1, rs=np.zeros(1, dtype=bool)) From 6bf975f28c1ccab17804d6da2438001cfbc9be8c Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 14:20:45 -0500 Subject: [PATCH 09/11] Full stop --- cirq-core/cirq/qis/clifford_tableau.py | 2 +- cirq-core/cirq/qis/clifford_tableau_test.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 1e2adbf0877..4bbaca48ec8 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -175,7 +175,7 @@ def _reconstruct_rs(self, rs: Optional[np.ndarray]) -> np.ndarray: else: raise ValueError( f"The value you passed for rs is not the correct shape and/or type. " - f"Please confirm that it's 1 row, of even length and of type bool" + f"Please confirm that it's 1 row, of even length and of type bool." ) return new_rs diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index 6ae15dacf8f..0d402413cc8 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -56,13 +56,13 @@ def test_tableau_initial_state_string(num_qubits): def test_tableau_ivalid_initial_state(): - with pytest.raises(ValueError, match="1 row, of even length and of type bool"): + with pytest.raises(ValueError, match="1 row, of even length and of type bool."): cirq.CliffordTableau(1, rs=np.zeros(1, dtype=bool)) - with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool"): + with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool."): cirq.CliffordTableau(1, xs=np.zeros(1, dtype=bool)) - with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool"): + with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool."): cirq.CliffordTableau(1, zs=np.zeros(1, dtype=bool)) From dd98f55f448499659bb061f1dd5eb75bf8692b13 Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 14:37:38 -0500 Subject: [PATCH 10/11] Lint --- cirq-core/cirq/qis/clifford_tableau_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index 0d402413cc8..fa9d6a2a70b 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -59,10 +59,14 @@ def test_tableau_ivalid_initial_state(): with pytest.raises(ValueError, match="1 row, of even length and of type bool."): cirq.CliffordTableau(1, rs=np.zeros(1, dtype=bool)) - with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool."): + with pytest.raises( + ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool." + ): cirq.CliffordTableau(1, xs=np.zeros(1, dtype=bool)) - with pytest.raises(ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool."): + with pytest.raises( + ValueError, match="2*num_qubits rows, num_qubits columns, and of type bool." + ): cirq.CliffordTableau(1, zs=np.zeros(1, dtype=bool)) From f99da28d3f6904bfe5653b67e9b78d5c04775077 Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 7 Jul 2022 17:45:30 -0500 Subject: [PATCH 11/11] Review 2 --- cirq-core/cirq/qis/clifford_tableau.py | 3 ++- cirq-core/cirq/qis/clifford_tableau_test.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 5aac6647328..a0f19f459ef 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -175,7 +175,8 @@ def _reconstruct_rs(self, rs: Optional[np.ndarray]) -> np.ndarray: else: raise ValueError( f"The value you passed for rs is not the correct shape and/or type. " - f"Please confirm that it's 1 row, of even length and of type bool." + f"Please confirm that it's a single row with 2*num_qubits columns " + f"and of type bool." ) return new_rs diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index fa9d6a2a70b..63d98471b43 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -55,8 +55,8 @@ def test_tableau_initial_state_string(num_qubits): assert splitted_represent_string[n] == expected_string -def test_tableau_ivalid_initial_state(): - with pytest.raises(ValueError, match="1 row, of even length and of type bool."): +def test_tableau_invalid_initial_state(): + with pytest.raises(ValueError, match="2*num_qubits columns and of type bool."): cirq.CliffordTableau(1, rs=np.zeros(1, dtype=bool)) with pytest.raises(