diff --git a/cirq-core/cirq/ops/qubit_manager.py b/cirq-core/cirq/ops/qubit_manager.py index 1d1263daa19..85820762f12 100644 --- a/cirq-core/cirq/ops/qubit_manager.py +++ b/cirq-core/cirq/ops/qubit_manager.py @@ -14,7 +14,7 @@ import abc import dataclasses -from typing import Iterable, List, TYPE_CHECKING +from typing import Iterable, List, TYPE_CHECKING, Tuple from cirq.ops import raw_types if TYPE_CHECKING: @@ -41,16 +41,19 @@ class _BaseAncillaQid(raw_types.Qid): dim: int = 2 prefix: str = '' - def _comparison_key(self) -> int: - return self.id + def _comparison_key(self) -> Tuple[str, int]: + return self.prefix, self.id @property def dimension(self) -> int: return self.dim + def with_dimension(self, dimension: int) -> '_BaseAncillaQid': + return dataclasses.replace(self, dim=dimension) + def __repr__(self) -> str: dim_str = f', dim={self.dim}' if self.dim != 2 else '' - prefix_str = f', prefix={self.prefix}' if self.prefix != '' else '' + prefix_str = f', prefix={self.prefix!r}' if self.prefix != '' else '' return f"cirq.ops.{type(self).__name__}({self.id}{dim_str}{prefix_str})" diff --git a/cirq-core/cirq/ops/qubit_manager_test.py b/cirq-core/cirq/ops/qubit_manager_test.py index 56c32292b35..f65b95e1379 100644 --- a/cirq-core/cirq/ops/qubit_manager_test.py +++ b/cirq-core/cirq/ops/qubit_manager_test.py @@ -27,12 +27,27 @@ def test_clean_qubits(): q = cqi.CleanQubit(2, dim=3) assert q.id == 2 assert q.dimension == 3 + assert q.with_dimension(4) == cqi.CleanQubit(2, dim=4) assert str(q) == '_c(2) (d=3)' assert repr(q) == 'cirq.ops.CleanQubit(2, dim=3)' + q = cqi.CleanQubit(3, dim=4, prefix="a") + assert str(q) == 'a_c(3) (d=4)' + assert repr(q) == "cirq.ops.CleanQubit(3, dim=4, prefix='a')" + assert cqi.CleanQubit(1) < cqi.CleanQubit(2) +def test_ancilla_qubits_prefix(): + assert cqi.CleanQubit(1, prefix="1") != cqi.CleanQubit(1, prefix="2") + assert cqi.CleanQubit(1, prefix="1") < cqi.CleanQubit(1, prefix="2") + assert cqi.CleanQubit(1, prefix="1") < cqi.CleanQubit(2, prefix="1") + assert cqi.BorrowableQubit(1, prefix="1") != cqi.BorrowableQubit(1, prefix="2") + assert cqi.BorrowableQubit(1, prefix="1") < cqi.BorrowableQubit(1, prefix="2") + assert cqi.BorrowableQubit(1, prefix="1") < cqi.BorrowableQubit(2, prefix="1") + assert cqi.CleanQubit(1, prefix="1") != cqi.BorrowableQubit(1, prefix="1") + + def test_borrow_qubits(): q = cqi.BorrowableQubit(10) assert q.id == 10 @@ -43,9 +58,14 @@ def test_borrow_qubits(): q = cqi.BorrowableQubit(20, dim=4) assert q.id == 20 assert q.dimension == 4 + assert q.with_dimension(10) == cqi.BorrowableQubit(20, dim=10) assert str(q) == '_b(20) (d=4)' assert repr(q) == 'cirq.ops.BorrowableQubit(20, dim=4)' + q = cqi.BorrowableQubit(30, dim=4, prefix="a") + assert str(q) == 'a_b(30) (d=4)' + assert repr(q) == "cirq.ops.BorrowableQubit(30, dim=4, prefix='a')" + assert cqi.BorrowableQubit(1) < cqi.BorrowableQubit(2) diff --git a/dev_tools/packaging/verify-published-package.sh b/dev_tools/packaging/verify-published-package.sh index 1434153b041..b2a1c16fce7 100755 --- a/dev_tools/packaging/verify-published-package.sh +++ b/dev_tools/packaging/verify-published-package.sh @@ -16,8 +16,7 @@ ################################################################################ # Downloads and tests cirq wheels from the pypi package repository. -# Can verify prod, test, or pre-release versions. -# --pre: pre-release cirq from prod pypi +# Can verify test or prod versions. # --test: cirq from test pypi # --prod: cirq from prod pypi # @@ -27,7 +26,7 @@ # dependencies disagree, the tests can spuriously fail. # # Usage: -# dev_tools/packaging/verify-published-package.sh PACKAGE_VERSION --test|--prod|--pre +# dev_tools/packaging/verify-published-package.sh PACKAGE_VERSION --test|--prod ################################################################################ set -e @@ -51,12 +50,8 @@ elif [ "${PROD_SWITCH}" = "--prod" ]; then PIP_FLAGS='' PYPI_REPO_NAME="PROD" PYPI_PROJECT_NAME="cirq" -elif [ "${PROD_SWITCH}" = "--pre" ]; then - PIP_FLAGS='--pre' - PYPI_REPO_NAME="PROD" - PYPI_PROJECT_NAME="cirq" else - echo -e "\033[31mSecond argument must be '--prod' or '--test' or '--pre'.\033[0m" + echo -e "\033[31mSecond argument must be '--test' or '--prod'.\033[0m" exit 1 fi