Skip to content

Commit

Permalink
Merge branch 'main' into display-tags-via-str
Browse files Browse the repository at this point in the history
  • Loading branch information
pavoljuhas committed Apr 10, 2024
2 parents c67984d + 1bec6b5 commit 302bce0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
11 changes: 7 additions & 4 deletions cirq-core/cirq/ops/qubit_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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})"


Expand Down
20 changes: 20 additions & 0 deletions cirq-core/cirq/ops/qubit_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


Expand Down
11 changes: 3 additions & 8 deletions dev_tools/packaging/verify-published-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 302bce0

Please sign in to comment.