Skip to content

Commit

Permalink
Merge branch 'main' into update_serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri authored Mar 15, 2024
2 parents b866e26 + 0f4822b commit 0dc1a1c
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 71 deletions.
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.9', '3.10', '3.11']
python-version: ['3.10', '3.11']
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.9', '3.10', '3.11']
python-version: ['3.10', '3.11']
runs-on: windows-2019
steps:
- uses: actions/checkout@v4
Expand All @@ -70,7 +70,7 @@ jobs:
name: Pytest MacOS
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/isolated-base.env.txt
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Misc
run: check/misc
Expand All @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: pip install -r dev_tools/requirements/deps/packaging.txt
Expand All @@ -46,7 +46,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: pip install -r dev_tools/requirements/deps/format.txt
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install mypy
run: pip install -r dev_tools/requirements/mypy.env.txt
Expand All @@ -74,7 +74,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install changed files test dependencies
run: dev_tools/conf/pip-install-minimal-for-pytest-changed-files.sh
Expand All @@ -87,7 +87,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install pylint
run: pip install -r dev_tools/requirements/pylint.env.txt
Expand All @@ -102,7 +102,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/dev.env.txt
Expand All @@ -117,7 +117,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/deps/tensorflow-docs.txt
Expand All @@ -139,7 +139,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: pip install -r dev_tools/requirements/isolated-base.env.txt
Expand All @@ -149,7 +149,7 @@ jobs:
name: Pytest Ubuntu
strategy:
matrix:
python-version: [ '3.9', '3.10', '3.11' ]
python-version: [ '3.10', '3.11' ]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: pip install pip-tools
Expand All @@ -194,7 +194,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: |
Expand All @@ -210,7 +210,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- uses: actions/cache@v4
with:
Expand All @@ -234,7 +234,7 @@ jobs:
name: Pytest Windows
strategy:
matrix:
python-version: [ '3.9', '3.10', '3.11' ]
python-version: [ '3.10', '3.11' ]
runs-on: windows-2019
steps:
- uses: actions/checkout@v4
Expand All @@ -259,7 +259,7 @@ jobs:
name: Pytest MacOS
strategy:
matrix:
python-version: [ '3.9', '3.10', '3.11' ]
python-version: [ '3.10', '3.11' ]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -292,7 +292,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/isolated-base.env.txt
Expand All @@ -310,7 +310,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/notebooks.env.txt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-slim AS cirq_base
FROM python:3.10-slim AS cirq_base

# Install dependencies.
# rm -rf /var/lib/apt/lists/* cleans up apt cache. See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
Expand Down
2 changes: 1 addition & 1 deletion asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dvcs": "git",
"environment_type": "virtualenv",
"show_commit_url": "https://github.com/quantumlib/Cirq/commit/",
"pythons": ["3.9"],
"pythons": ["3.10"],
"matrix": {"env_nobuild": {"PYTHONOPTIMIZE": ["-O", ""]}},
"benchmark_dir": "benchmarks",
"env_dir": ".asv/env",
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To run all benchmarks, navigate to the root Cirq directory at the command line a

You can also pass arguments to the script, which would be forwarded to the `asv run` command. For eg:
```bash
./check/asv_run --quick --bench bench_examples --python 3.9
./check/asv_run --quick --bench bench_examples --python 3.10
```

Please refer [Running Benchmarks guide by ASV](https://asv.readthedocs.io/en/stable/using.html#running-benchmarks) for more information.
Expand Down
21 changes: 14 additions & 7 deletions cirq-core/cirq/experiments/t1_decay_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Optional, TYPE_CHECKING
from typing import Any, Optional, Sequence, TYPE_CHECKING, cast

import warnings
import pandas as pd
Expand Down Expand Up @@ -77,7 +77,12 @@ def t1_decay(

var = sympy.Symbol('delay_ns')

sweep = study.Linspace(var, start=min_delay_nanos, stop=max_delay_nanos, length=num_points)
if min_delay_nanos == 0:
min_delay_nanos = 0.4
sweep_vals_ns = np.unique(
np.round(np.logspace(np.log10(min_delay_nanos), np.log10(max_delay_nanos), num_points))
)
sweep = study.Points(var, cast(Sequence[float], sweep_vals_ns))

circuit = circuits.Circuit(
ops.X(qubit), ops.wait(qubit, nanos=var), ops.measure(qubit, key='output')
Expand Down Expand Up @@ -118,8 +123,8 @@ def data(self) -> pd.DataFrame:
def constant(self) -> float:
"""The t1 decay constant."""

def exp_decay(x, t1):
return np.exp(-x / t1)
def exp_decay(x, t1, a, b):
return a * np.exp(-x / t1) + b

xs = self._data['delay_ns']
ts = self._data['true_count']
Expand All @@ -132,8 +137,8 @@ def exp_decay(x, t1):

# Fit to exponential decay to find the t1 constant
try:
popt, _ = optimize.curve_fit(exp_decay, xs, probs, p0=[t1_guess])
t1 = popt[0]
self.popt, _ = optimize.curve_fit(exp_decay, xs, probs, p0=[t1_guess, 1.0, 0.0])
t1 = self.popt[0]
return t1
except RuntimeError:
warnings.warn("Optimal parameters could not be found for curve fit", RuntimeWarning)
Expand Down Expand Up @@ -166,7 +171,9 @@ def plot(
ax.plot(xs, ts / (fs + ts), 'ro-', **plot_kwargs)

if include_fit and not np.isnan(self.constant):
ax.plot(xs, np.exp(-xs / self.constant), label='curve fit')
t1 = self.constant
t1, a, b = self.popt
ax.plot(xs, a * np.exp(-xs / t1) + b, label='curve fit')
plt.legend()

ax.set_xlabel(r"Delay between initialization and measurement (nanoseconds)")
Expand Down
40 changes: 14 additions & 26 deletions cirq-core/cirq/experiments/t1_decay_experiment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def noisy_moment(self, moment, system_qubits):
repetitions=10,
max_delay=cirq.Duration(nanos=500),
)
results.plot()
results.plot(include_fit=True)


def test_result_eq():
eq = cirq.testing.EqualsTester()
eq.make_equality_group(
lambda: cirq.experiments.T1DecayResult(
data=pd.DataFrame(
columns=['delay_ns', 'false_count', 'true_count'], index=[0], data=[[100.0, 2, 8]]
columns=['delay_ns', 'false_count', 'true_count'], index=[0], data=[[100, 2, 8]]
)
)
)
Expand Down Expand Up @@ -103,7 +103,7 @@ def noisy_moment(self, moment, system_qubits):
data=pd.DataFrame(
columns=['delay_ns', 'false_count', 'true_count'],
index=range(4),
data=[[100.0, 0, 10], [400.0, 0, 10], [700.0, 10, 0], [1000.0, 10, 0]],
data=[[100.0, 0, 10], [215.0, 0, 10], [464.0, 0, 10], [1000.0, 10, 0]],
)
)

Expand All @@ -117,13 +117,14 @@ def test_all_on_results():
min_delay=cirq.Duration(nanos=100),
max_delay=cirq.Duration(micros=1),
)
assert results == cirq.experiments.T1DecayResult(
desired = cirq.experiments.T1DecayResult(
data=pd.DataFrame(
columns=['delay_ns', 'false_count', 'true_count'],
index=range(4),
data=[[100.0, 0, 10], [400.0, 0, 10], [700.0, 0, 10], [1000.0, 0, 10]],
data=[[100.0, 0, 10], [215.0, 0, 10], [464.0, 0, 10], [1000.0, 0, 10]],
)
)
assert results == desired, f'{results.data=} {desired.data=}'


def test_all_off_results():
Expand All @@ -135,13 +136,14 @@ def test_all_off_results():
min_delay=cirq.Duration(nanos=100),
max_delay=cirq.Duration(micros=1),
)
assert results == cirq.experiments.T1DecayResult(
desired = cirq.experiments.T1DecayResult(
data=pd.DataFrame(
columns=['delay_ns', 'false_count', 'true_count'],
index=range(4),
data=[[100.0, 10, 0], [400.0, 10, 0], [700.0, 10, 0], [1000.0, 10, 0]],
data=[[100.0, 10, 0], [215.0, 10, 0], [464.0, 10, 0], [1000.0, 10, 0]],
)
)
assert results == desired, f'{results.data=} {desired.data=}'


@pytest.mark.usefixtures('closefigures')
Expand All @@ -150,28 +152,14 @@ def test_curve_fit_plot_works():
data=pd.DataFrame(
columns=['delay_ns', 'false_count', 'true_count'],
index=range(4),
data=[[100.0, 6, 4], [400.0, 10, 0], [700.0, 10, 0], [1000.0, 10, 0]],
data=[[100.0, 6, 4], [215.0, 10, 0], [464.0, 10, 0], [1000.0, 10, 0]],
)
)

good_fit.plot(include_fit=True)


@pytest.mark.usefixtures('closefigures')
def test_curve_fit_plot_warning():
bad_fit = cirq.experiments.T1DecayResult(
data=pd.DataFrame(
columns=['delay_ns', 'false_count', 'true_count'],
index=range(4),
data=[[100.0, 10, 0], [400.0, 10, 0], [700.0, 10, 0], [1000.0, 10, 0]],
)
)

with pytest.warns(RuntimeWarning, match='Optimal parameters could not be found for curve fit'):
bad_fit.plot(include_fit=True)


@pytest.mark.parametrize('t1', [200, 500, 700])
@pytest.mark.parametrize('t1', [200.0, 500.0, 700.0])
def test_noise_model_continous(t1):
class GradualDecay(cirq.NoiseModel):
def __init__(self, t1: float):
Expand All @@ -196,10 +184,10 @@ def noisy_moment(self, moment, system_qubits):
results = cirq.experiments.t1_decay(
sampler=cirq.DensityMatrixSimulator(noise=GradualDecay(t1)),
qubit=cirq.GridQubit(0, 0),
num_points=4,
num_points=10,
repetitions=10,
min_delay=cirq.Duration(nanos=100),
max_delay=cirq.Duration(micros=1),
min_delay=cirq.Duration(nanos=1),
max_delay=cirq.Duration(micros=10),
)

assert np.isclose(results.constant, t1, 50)
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/packaging/packaging_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trap '{ rm -rf "${tmp_dir}"; }' EXIT

# New virtual environment
echo "Working in a fresh virtualenv at ${tmp_dir}/env"
python3.9 -m venv "${tmp_dir}/env"
python3.10 -m venv "${tmp_dir}/env"

export CIRQ_PRE_RELEASE_VERSION
CIRQ_PRE_RELEASE_VERSION=$(dev_tools/packaging/generate-dev-version-id.sh)
Expand Down
Loading

0 comments on commit 0dc1a1c

Please sign in to comment.