Skip to content

Commit

Permalink
Merge branch 'main' into prngs
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri authored Jul 11, 2024
2 parents b06f456 + 5d22a53 commit 770e8fe
Show file tree
Hide file tree
Showing 263 changed files with 2,903 additions and 13,836 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ P1 - I need this no later than the next release (end of quarter)
P2 - we should do it in the next couple of quarters
P3 - I'm not really blocked by it, it is an idea I'd like to discuss / suggestion based on principle

<!-- [optional] additional comment / context -->
<!-- [optional] additional comment / context -->
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/task.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Project task
about: Task to track larger efforts
about: Task to track larger efforts
title: ''
labels: 'kind/task'
assignees: ''
Expand All @@ -16,4 +16,4 @@ assignees: ''
<!-- optional, feel free to remove this section -->
**Related**

Related issues: #abc, #xyz, ...
Related issues: #abc, #xyz, ...
6 changes: 3 additions & 3 deletions .github/workflows/ci-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Pytest Ubuntu
strategy:
matrix:
python-version: ['3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
name: Pytest Windows
strategy:
matrix:
python-version: ['3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']
runs-on: windows-2019
steps:
- uses: actions/checkout@v4
Expand All @@ -70,7 +70,7 @@ jobs:
name: Pytest MacOS
strategy:
matrix:
python-version: ['3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']
# TODO(#6577): upgrade to macos-latest when it runs Python 3.10
runs-on: macos-13
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
- name: Install requirements
run: pip install -r dev_tools/requirements/dev.env.txt
- name: RST check
run: find . -type f -name "*.rst" | xargs rstcheck --report warning --ignore-directives autoclass,automodule
run: find . -type f -name "*.rst" | xargs rstcheck
- name: Doc check
run: check/doctest -q
nbformat:
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
- name: Install dependencies
run: pip install -r dev_tools/requirements/isolated-base.env.txt
- name: Test each module in isolation
run: pytest -n auto -m slow dev_tools/packaging/isolated_packages_test.py
run: pytest -n auto --enable-slow-tests dev_tools/packaging/isolated_packages_test.py
pytest:
name: Pytest Ubuntu
strategy:
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ harassment or threats to anyone's safety, we may take action without notice.

This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
2 changes: 1 addition & 1 deletion benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ You can also pass arguments to the script, which would be forwarded to the `asv
Please refer [Running Benchmarks guide by ASV](https://asv.readthedocs.io/en/stable/using.html#running-benchmarks) for more information.

## Results Database
TODO([#3838](https://github.com/quantumlib/Cirq/issues/3838)): Add details regarding GCP setup.
TODO([#3838](https://github.com/quantumlib/Cirq/issues/3838)): Add details regarding GCP setup.
17 changes: 9 additions & 8 deletions check/all
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ cd "${topdir}" || exit $?
errors=()

# Parse arguments.
apply_arg=""
apply_arg=( )
only_changed=0
rev=""
rev=( )
for arg in "$@"; do
if [[ "${arg}" == "--only-changed-files" ]]; then
only_changed=1
elif [[ "${arg}" == "--apply-format-changes" ]]; then
apply_arg="--apply"
elif [ -z "${rev}" ]; then
apply_arg=( "--apply" )
elif [[ "${#rev[@]}" == 0 ]]; then
if [ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]; then
echo -e "\033[31mNo revision '${arg}'.\033[0m" >&2
exit 1
fi
rev="${arg}"
rev=( "${arg}" )
else
echo -e "\033[31mInvalid arguments. Expected [BASE_REVISION] [--only-changed-files] [--apply-format].\033[0m" >&2
exit 1
Expand All @@ -73,15 +73,16 @@ echo "Running mypy"
check/mypy || errors+=( "check/mypy failed" )

echo "Running incremental format"
check/format-incremental "${rev}" "${apply_arg}" || errors+=( "check/format-incremental failed" )
check/format-incremental "${rev[@]}" "${apply_arg[@]}" ||
errors+=( "check/format-incremental failed" )

if [ ${only_changed} -ne 0 ]; then
echo "Running pytest and incremental coverage on changed files"
check/pytest-changed-files-and-incremental-coverage "${rev}" ||
check/pytest-changed-files-and-incremental-coverage "${rev[@]}" ||
errors+=( "check/pytest-changed-files-and-incremental-coverage failed" )
else
echo "Running pytest and incremental coverage"
check/pytest-and-incremental-coverage "${rev}" ||
check/pytest-and-incremental-coverage "${rev[@]}" ||
errors+=( "check/pytest-and-incremental-coverage failed" )
fi

Expand Down
4 changes: 2 additions & 2 deletions check/build-changed-protos
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cd "${topdir}" || exit $?

# Figure out which revision to compare against.
if [ -n "$1" ] && [[ $1 != -* ]]; then
if [ "$(git cat-file -t "$1" 2> /dev/null)" != "commit" ]; then
if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then
echo -e "\033[31mNo revision '$1'.\033[0m" >&2
exit 1
fi
Expand Down Expand Up @@ -62,7 +62,7 @@ dev_tools/build-protos.sh

# Filenames with spaces will be ugly (each part will be listed separately)
# but the error logic will still work.
uncommitted=$(git status --porcelain 2>/dev/null | grep -E "^?? cirq-google" | cut -d " " -f 3)
uncommitted=$(git status --porcelain 2>/dev/null | grep -E "^[?][?] cirq-google" | cut -d " " -f 3)

if [[ -n "$uncommitted" ]]; then
echo -e "\033[31mERROR: Uncommitted generated files found! Please generate and commit these files using dev_tools/build-protos.sh:\033[0m"
Expand Down
2 changes: 1 addition & 1 deletion check/format-incremental
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ for arg in "$@"; do
elif [[ "${arg}" == "--all" ]]; then
only_changed=0
elif [ -z "${rev}" ]; then
if [ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]; then
if ! git rev-parse --verify --quiet --no-revs "${arg}^{commit}"; then
echo -e "\033[31mNo revision '${arg}'.\033[0m" >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion check/pylint-changed-files
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cd "${topdir}" || exit $?

# Figure out which revision to compare against.
if [ -n "$1" ] && [[ $1 != -* ]]; then
if [ "$(git cat-file -t "$1" 2> /dev/null)" != "commit" ]; then
if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then
echo -e "\033[31mNo revision '$1'.\033[0m" >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion check/pytest-and-incremental-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ done

# Figure out which revision to compare against.
if [ -n "${BASEREV}" ]; then
if [ "$(git cat-file -t "${BASEREV}" 2> /dev/null)" != "commit" ]; then
if ! git rev-parse --verify --quiet --no-revs "${BASEREV}^{commit}"; then
echo -e "\033[31mNo revision '${BASEREV}'.\033[0m" >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion check/pytest-changed-files
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cd "${topdir}" || exit $?
# Figure out which branch to compare against.
rest=( "$@" )
if [ -n "$1" ] && [[ $1 != -* ]]; then
if [ "$(git cat-file -t "$1" 2> /dev/null)" != "commit" ]; then
if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then
echo -e "\033[31mNo revision '$1'.\033[0m" >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion check/pytest-changed-files-and-incremental-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cd "$(git rev-parse --show-toplevel)" || exit 1

# Figure out which revision to compare against.
if [ -n "$1" ] && [[ $1 != -* ]]; then
if [ "$(git cat-file -t "$1" 2> /dev/null)" != "commit" ]; then
if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then
echo -e "\033[31mNo revision '$1'.\033[0m" >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion cirq-aqt/cirq_aqt/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

"""Define version number here, read it from setup.py automatically"""

__version__ = "1.4.0.dev"
__version__ = "1.5.0.dev"
2 changes: 1 addition & 1 deletion cirq-aqt/cirq_aqt/_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


def test_version():
assert cirq_aqt.__version__ == "1.4.0.dev"
assert cirq_aqt.__version__ == "1.5.0.dev"
2 changes: 1 addition & 1 deletion cirq-aqt/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests~=2.18
requests~=2.18
1 change: 1 addition & 0 deletions cirq-core/cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
ZPowGate,
ZZ,
ZZPowGate,
UniformSuperpositionGate,
)

from cirq.transformers import (
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
'of cirq (e.g. "python -m pip install cirq==1.1.*")'
)

__version__ = "1.4.0.dev"
__version__ = "1.5.0.dev"
2 changes: 1 addition & 1 deletion cirq-core/cirq/_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


def test_version():
assert cirq.__version__ == "1.4.0.dev"
assert cirq.__version__ == "1.5.0.dev"
24 changes: 13 additions & 11 deletions cirq-core/cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,31 @@ class AbstractCircuit(abc.ABC):
"""

@classmethod
def from_moments(cls: Type[CIRCUIT_TYPE], *moments: 'cirq.OP_TREE') -> CIRCUIT_TYPE:
def from_moments(cls: Type[CIRCUIT_TYPE], *moments: Optional['cirq.OP_TREE']) -> CIRCUIT_TYPE:
"""Create a circuit from moment op trees.
Args:
*moments: Op tree for each moment. If an op tree is a moment, it
will be included directly in the new circuit. If an op tree is
a circuit, it will be frozen, wrapped in a CircuitOperation, and
included in its own moment in the new circuit. Otherwise, the
op tree will be passed to `cirq.Moment` to create a new moment
which is then included in the new circuit. Note that in the
latter case we have the normal restriction that operations in a
moment must be applied to disjoint sets of qubits.
*moments: Op trees for each moment, which can be one of the following:
- Moment: will be included directly in the new circuit.
- AbstractCircuit: will be frozen, wrapped in a CircuitOperation,
and included in its own moment in the new circuit.
- None: will be skipped and omitted from the circuit. This can be
used to include or skip a moment based on a conditional, for example.
- Other OP_TREE: will be passed to `cirq.Moment` to create a new moment
which is then included in the new circuit. Note that in this
case we have the normal restriction that operations in a
moment must be applied to disjoint sets of qubits.
"""
return cls._from_moments(cls._make_moments(moments))

@staticmethod
def _make_moments(moments: Iterable['cirq.OP_TREE']) -> Iterator['cirq.Moment']:
def _make_moments(moments: Iterable[Optional['cirq.OP_TREE']]) -> Iterator['cirq.Moment']:
for m in moments:
if isinstance(m, Moment):
yield m
elif isinstance(m, AbstractCircuit):
yield Moment(m.freeze().to_op())
else:
elif m is not None:
yield Moment(m)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions cirq-core/cirq/circuits/circuit_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ def test_repeat(add_measurements: bool, use_default_ids_for_initial_rep: bool) -
_ = op_base.repeat()

with pytest.raises(TypeError, match='Only integer or sympy repetitions are allowed'):
_ = op_base.repeat(1.3) # type: ignore[arg-type]
assert op_base.repeat(3.00000000001).repetitions == 3 # type: ignore[arg-type]
assert op_base.repeat(2.99999999999).repetitions == 3 # type: ignore[arg-type]
_ = op_base.repeat(1.3)
assert op_base.repeat(3.00000000001).repetitions == 3
assert op_base.repeat(2.99999999999).repetitions == 3


@pytest.mark.parametrize('add_measurements', [True, False])
Expand Down
1 change: 1 addition & 0 deletions cirq-core/cirq/circuits/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_from_moments():
[cirq.X(c)],
[],
cirq.Z(d),
None,
[cirq.measure(a, b, key='ab'), cirq.measure(c, d, key='cd')],
)
assert circuit == cirq.Circuit(
Expand Down
7 changes: 4 additions & 3 deletions cirq-core/cirq/experiments/qubit_characterizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import functools

from typing import (
Any,
cast,
Any,
Iterator,
List,
Optional,
Expand Down Expand Up @@ -107,7 +107,6 @@ def plot(self, ax: Optional[plt.Axes] = None, **plot_kwargs: Any) -> plt.Axes:
show_plot = not ax
if not ax:
fig, ax = plt.subplots(1, 1, figsize=(8, 8)) # pragma: no cover
ax = cast(plt.Axes, ax) # pragma: no cover
ax.set_ylim((0.0, 1.0)) # pragma: no cover
ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro', label='data', **plot_kwargs)
x = np.linspace(self._num_cfds_seq[0], self._num_cfds_seq[-1], 100)
Expand Down Expand Up @@ -304,7 +303,9 @@ def plot(self, axes: Optional[List[plt.Axes]] = None, **plot_kwargs: Any) -> Lis
"""
show_plot = axes is None
if axes is None:
fig, axes = plt.subplots(1, 2, figsize=(12.0, 5.0), subplot_kw={'projection': '3d'})
fig, axes_v = plt.subplots(1, 2, figsize=(12.0, 5.0), subplot_kw={'projection': '3d'})
axes_v = cast(np.ndarray, axes_v)
axes = list(axes_v)
elif len(axes) != 2:
raise ValueError('A TomographyResult needs 2 axes to plot.')
mat = self._density_matrix
Expand Down
Loading

0 comments on commit 770e8fe

Please sign in to comment.