Skip to content

Commit

Permalink
Merge pull request #163 from q-optimize/release/1.4
Browse files Browse the repository at this point in the history
Release/1.4

Maintenance updates to code quality and implementation along with some useful utility functions and example notebooks.
  • Loading branch information
lazyoracle committed Dec 23, 2021
2 parents dcdb2be + 435ec20 commit 3208a84
Show file tree
Hide file tree
Showing 65 changed files with 4,005 additions and 566 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python Package Build
name: Build and Test

on:
push:
Expand All @@ -8,12 +8,12 @@ on:
workflow_dispatch:

jobs:
build:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-18.04, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/integration_test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/nightly_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-18.04, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-18.04, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ This Changelog tracks all past changes to this project as well as details about
- `fixed` for any bug fixes.
- `security` in case of vulnerabilities.

## Version `1.4` - 23 Dec 2021

### Summary

Maintenance updates to code quality and implementation along with some useful utility functions and example notebooks.

### Details

- `added` experimental support for Runge Kutta 4 solving of EOM #144
- `changed` the experiment and model classes for handling different propagation methods #144
- `changed` The generator now can handle any list of devices that forms a directed graph #129
- `removed` official support for Python 3.6 #156
- `added` a method to HJSON dump current parameter values #149
- `added` example for the log reader CLI #137
- `added` human readable saving of current best point for the optimizer #140
- `fixed` handling of anharmonicity in transmons with two levels #146
- `added` an example notebook with entangling two-qubit gates #154
- `fixed` Broken State Fidelity #135

## Version `1.3` - 20 Jul 2021

### Summary
Expand Down Expand Up @@ -117,4 +136,4 @@ This is the first major and properly packaged release of the `c3-toolset` librar
- `added`, `fixed` Compatibility with Windows and MacOS
- `added` Better Examples and Docs
- `added` pip installation configs
- `added` pip-test deployment github actions
- `added` pip-test deployment github actions
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ We use the [CHANGELOG.md](CHANGELOG.md) as a living document that not only recor

## Continuous Integration Checks

As previously discussed, tests are an inherent part of good code. All Pull Requests made to the repository are automatically tested on Windows, MacOS and Ubuntu with Python 3.6, 3.7, 3.8 and 3.9, which come up in the PR as `Checks`, notifying you whenever a particular check is failing on any platform. Except the `Code Complexity`, all checks should be passing for your PR to be ready for review/merge. The `Codecov` bot will also comment on the PR with a report on the change in the test coverage for that particular PR. If your PR reduces the overall test coverage of the codebase, it is not yet ready and you need to add more tests.
As previously discussed, tests are an inherent part of good code. All Pull Requests made to the repository are automatically tested on Windows, MacOS and Ubuntu with Python 3.7, 3.8 and 3.9, which come up in the PR as `Checks`, notifying you whenever a particular check is failing on any platform. Except the `Code Complexity`, all checks should be passing for your PR to be ready for review/merge. The `Codecov` bot will also comment on the PR with a report on the change in the test coverage for that particular PR. If your PR reduces the overall test coverage of the codebase, it is not yet ready and you need to add more tests.

## Contributor License Agreement

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![codecov](https://codecov.io/gh/q-optimize/c3/branch/dev/graph/badge.svg)](https://codecov.io/gh/q-optimize/c3)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/q-optimize/c3.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/q-optimize/c3/context:python)
<a href="https://codeclimate.com/github/q-optimize/c3/maintainability"><img src="https://api.codeclimate.com/v1/badges/a090831b106f863dc223/maintainability" /></a>
[![Build and Test](https://github.com/q-optimize/c3/actions/workflows/build_package.yml/badge.svg)](https://github.com/q-optimize/c3/actions/workflows/build_package.yml)
[![Documentation Status](https://readthedocs.org/projects/c3-toolset/badge/?version=latest)](https://c3-toolset.readthedocs.io/en/latest/?badge=latest)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PyPI version fury.io](https://badge.fury.io/py/c3-toolset.svg)](https://pypi.python.org/pypi/c3-toolset/)
Expand Down Expand Up @@ -38,3 +39,20 @@ Examples are available in the `examples/` directory and can also be run online u
If you wish to contribute, please check out the issues tab and also the `CONTRIBUTING.md` for useful resources.

The source code is available on Github at [https://github.com/q-optimize/c3](https://github.com/q-optimize/c3).

## Citation

If you use `c3-toolset` in your research, please cite it as below:

```
@article{Wittler2021,
title={Integrated Tool Set for Control, Calibration, and Characterization of Quantum Devices Applied to Superconducting Qubits},
volume={15},
DOI={10.1103/physrevapplied.15.034080},
number={3},
journal={Physical Review Applied},
author={Wittler, Nicolas and Roy, Federico and Pack, Kevin and Werninghaus, Max and Saha Roy, Anurag and Egger, Daniel J. and Filipp, Stefan and Wilhelm, Frank K. and Machnes, Shai},
year={2021},
month={Mar}
}
```
2 changes: 1 addition & 1 deletion c3/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3"
__version__ = "1.4"
62 changes: 34 additions & 28 deletions c3/c3objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,57 +123,57 @@ def asdict(self) -> dict:

def __add__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() + other, extend_bounds=True)
out_val._set_value_extend(self.get_value() + other)
return out_val

def __radd__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() + other, extend_bounds=True)
out_val._set_value_extend(self.get_value() + other)
return out_val

def __sub__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() - other, extend_bounds=True)
out_val._set_value_extend(self.get_value() - other)
return out_val

def __rsub__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(other - self.get_value(), extend_bounds=True)
out_val._set_value_extend(other - self.get_value())
return out_val

def __mul__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() * other, extend_bounds=True)
out_val._set_value_extend(self.get_value() * other)
return out_val

def __rmul__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() * other, extend_bounds=True)
out_val._set_value_extend(self.get_value() * other)
return out_val

def __pow__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() ** other, extend_bounds=True)
out_val._set_value_extend(self.get_value() ** other)
return out_val

def __rpow__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(other ** self.get_value(), extend_bounds=True)
out_val._set_value_extend(other ** self.get_value())
return out_val

def __truediv__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() / other, extend_bounds=True)
out_val._set_value_extend(self.get_value() / other)
return out_val

def __rtruediv__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(other / self.get_value(), extend_bounds=True)
out_val._set_value_extend(other / self.get_value())
return out_val

def __mod__(self, other):
out_val = copy.deepcopy(self)
out_val.set_value(self.get_value() % other, extend_bounds=True)
out_val._set_value_extend(self.get_value() % other)
return out_val

def __lt__(self, other):
Expand Down Expand Up @@ -253,7 +253,13 @@ def get_value(self, val: tf.float64 = None, dtype: tf.dtypes = None) -> tf.Tenso
value = self.scale * (val + 1) / 2 + self.offset
return tf.cast(value, dtype)

def set_value(self, val, extend_bounds=False) -> None:
def set_value(self, val, extend_bounds=False):
if extend_bounds:
self._set_value_extend(val)
else:
self._set_value(val)

def _set_value(self, val) -> None:
"""Set the value of this quantity as tensorflow. Value needs to be
within specified min and max."""
# setting can be numpyish
Expand All @@ -264,25 +270,25 @@ def set_value(self, val, extend_bounds=False) -> None:

tmp = 2 * (val * self.pref - self.offset) / self.scale - 1

if extend_bounds and tf.math.abs(tmp) > 1:
min_val, max_val = self.get_limits()
# Extra bounds included to not be directly at border due to differentiability
minmax = [val * 0.9, val * 1.1, min_val, max_val]
min_val = tf.math.reduce_min(minmax)
max_val = tf.math.reduce_max(minmax)
self.set_limits(min_val, max_val)
tmp = 2 * (val * self.pref - self.offset) / self.scale - 1

tf.debugging.assert_less_equal(
tf.math.abs(tmp),
tf.constant(1.0, tf.float64),
f"Value {val.numpy()}{self.unit} out of bounds for quantity with "
f"min_val: {num3str(self.get_limits()[0])}{self.unit} and "
f"max_val: {num3str(self.get_limits()[1])}{self.unit}",
)
if np.any(tf.math.abs(tmp) > tf.constant(1.0, tf.float64)):
raise Exception(
f"Value {val.numpy()}{self.unit} out of bounds for quantity with "
f"min_val: {num3str(self.get_limits()[0])}{self.unit} and "
f"max_val: {num3str(self.get_limits()[1])}{self.unit}",
)

self.value = tf.cast(tmp, tf.float64)

def _set_value_extend(self, val) -> None:
"""Set the value of this quantity as tensorflow. If needed, limits will be extended."""
min_val, max_val = self.get_limits()
# Extra bounds included to not be directly at border due to differentiability
minmax = [val * 0.9, val * 1.1, min_val, max_val]
min_val = tf.math.reduce_min(minmax)
max_val = tf.math.reduce_max(minmax)
self.set_limits(min_val, max_val)
self._set_value(val)

def get_opt_value(self) -> np.ndarray:
"""Get an optimizer friendly representation of the value."""
return self.value.numpy().flatten()
Expand Down
Loading

0 comments on commit 3208a84

Please sign in to comment.