Skip to content

Commit 48b7917

Browse files
nwittlerlazyoracle
andauthored
Update dependencies (#243)
* Max version for tf probability * Update workflow to python 3.10 * Bump tf versions * Checking properties of tf objs compatible with tf 2.15 * Fix for qiskit? * Remove depricated use of int * Deprecated use of complex removed * Update requirements * Python version as string * Reblacked, fixed types * Interface to keras SGD * try to fix missing qiskit-aer dep --------- Co-authored-by: lazyoracle <contact@anuragsaharoy.me>
1 parent 57fc8d9 commit 48b7917

20 files changed

+40
-50
lines changed

.github/workflows/build_package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python-version: [3.9]
16+
python-version: ['3.10']
1717
env:
1818
OS: ${{ matrix.os }}
1919
PYTHON: ${{ matrix.python-version }}

.github/workflows/coverage.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [3.9]
16+
python-version: ['3.10']
1717
env:
1818
OS: 'ubuntu-latest'
19-
PYTHON: '3.9'
19+
PYTHON: '3.10'
2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Set up Python ${{ matrix.python-version }}

.github/workflows/format_lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [3.9]
16+
python-version: ['3.10']
1717
env:
1818
OS: 'ubuntu-latest'
19-
PYTHON: '3.9'
19+
PYTHON: '3.10'
2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Set up Python ${{ matrix.python-version }}

.github/workflows/nightly_pypi.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
- uses: actions/checkout@master
1212
with:
1313
ref: 'dev'
14-
- name: Set up Python 3.9
14+
- name: Set up Python 3.10
1515
uses: actions/setup-python@v1
1616
with:
17-
python-version: 3.9
17+
python-version: 3.10
1818
- name : Install Prerequisites
1919
run : |
2020
sudo apt-add-repository universe
@@ -49,7 +49,7 @@ jobs:
4949
strategy:
5050
matrix:
5151
os: [ubuntu-latest, macos-latest, windows-latest]
52-
python-version: [3.9]
52+
python-version: ['3.10']
5353
env:
5454
OS: ${{ matrix.os }}
5555
PYTHON: ${{ matrix.python-version }}

.github/workflows/notebook_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest]
16-
python-version: [3.9]
16+
python-version: ['3.10']
1717
env:
1818
OS: ${{ matrix.os }}
1919
PYTHON: ${{ matrix.python-version }}

.github/workflows/publish_pypi.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@master
13-
- name: Set up Python 3.9
13+
- name: Set up Python '3.10'
1414
uses: actions/setup-python@v1
1515
with:
16-
python-version: 3.9
16+
python-version: '3.10'
1717
- name : Install Prerequisites
1818
run : |
1919
sudo apt-add-repository universe
@@ -45,7 +45,7 @@ jobs:
4545
strategy:
4646
matrix:
4747
os: [ubuntu-latest, macos-latest, windows-latest]
48-
python-version: [3.9]
48+
python-version: ['3.10']
4949
env:
5050
OS: ${{ matrix.os }}
5151
PYTHON: ${{ matrix.python-version }}

c3/c3objs.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def __init__(self, name, desc="", comment="", params=None):
3737
if params:
3838
for pname, par in params.items():
3939
# TODO params here should be the dict representation only
40-
if isinstance(par, Quantity):
41-
self.params[pname] = par
42-
else:
40+
if isinstance(par, dict):
4341
self.params[pname] = Quantity(**par)
42+
else:
43+
self.params[pname] = par
4444

4545
def __str__(self) -> str:
4646
return hjson.dumps(self.asdict(), default=hjson_encode)
@@ -276,10 +276,7 @@ def _set_value(self, val) -> None:
276276
"""Set the value of this quantity as tensorflow. Value needs to be
277277
within specified min and max."""
278278
# setting can be numpyish
279-
if isinstance(val, ops.EagerTensor) or isinstance(val, ops.Tensor):
280-
val = tf.cast(val, tf.float64)
281-
else:
282-
val = tf.constant(val, tf.float64)
279+
val = tf.constant(val, tf.float64)
283280

284281
tmp = (
285282
2 * (tf.reshape(val, self.shape) * self.pref - self.offset) / self.scale - 1

c3/generator/devices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ def __init__(self, **props):
10201020

10211021
def get_noise(self, sig):
10221022
noise_amp = self.params["noise_amp"].get_value().numpy()
1023-
bfl_num = np.int(self.params["bfl_num"].get_value().numpy())
1023+
bfl_num = int(self.params["bfl_num"].get_value().numpy())
10241024
noise = []
10251025
bfls = 2 * np.random.randint(2, size=bfl_num) - 1
10261026
num_steps = len(sig)

c3/libraries/algorithms.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ def tf_fun():
284284

285285
opt_sgd = tf.keras.optimizers.SGD(learning_rate=learning_rate, momentum=momentum)
286286

287-
for _ in range(iters):
288-
step_count = opt_sgd.minimize(tf_fun, [var])
289-
print(f"epoch {step_count.numpy()}: func_value: {tf_fun()}")
287+
for ii in range(iters):
288+
opt_sgd.minimize(tf_fun, [var])
289+
print(f"iter {ii}: func_value: {tf_fun()}")
290290

291291
result = OptimizeResult(x=var.numpy(), success=True)
292292
return result
@@ -524,7 +524,6 @@ def cmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={}):
524524
es = cma.CMAEvolutionStrategy(x_init, spread, settings)
525525
iter = 0
526526
while not es.stop():
527-
528527
if shrunk_check:
529528
sigmas.append(es.sigma)
530529
if iter > sigma_conv:
@@ -627,7 +626,6 @@ def gcmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={}):
627626
es = cma.CMAEvolutionStrategy(x_init, spread, settings)
628627
iter = 0
629628
while not es.stop():
630-
631629
if shrinked_check:
632630
sigmas.append(es.sigma)
633631
if iter > sigma_conv:

c3/libraries/propagation.py

-2
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ def tf_expm_dynamic(A, acc=1e-5):
688688
def ode_solver(
689689
model: Model, gen: Generator, instr: Instruction, init_state, solver, step_function
690690
) -> Dict:
691-
692691
signal = gen.generate_signals(instr)
693692

694693
if model.lindbladian:
@@ -726,7 +725,6 @@ def ode_solver(
726725
def ode_solver_final_state(
727726
model: Model, gen: Generator, instr: Instruction, init_state, solver, step_function
728727
) -> Dict:
729-
730728
signal = gen.generate_signals(instr)
731729

732730
if model.lindbladian:

c3/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
logging.getLogger("tensorflow").disabled = True
2323

24+
2425
# flake8: noqa: C901
2526
def run_cfg(cfg, opt_config_filename, debug=False):
2627
"""Execute an optimization problem described in the cfg file.

c3/optimizers/modellearning.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(
8686

8787
super().__init__(pmap=pmap, algorithm=algorithm, logger=logger)
8888

89-
self.state_labels = {"all": None}
89+
self.state_labels: Dict[str, List] = {"all": []}
9090
for target, labels in state_labels.items():
9191
self.state_labels[target] = [tuple(lab) for lab in labels]
9292

@@ -106,7 +106,7 @@ def __init__(
106106
self.inverse = False
107107
self.options = options
108108

109-
self.learn_data = {}
109+
self.learn_data: Dict[str, np.ndarray] = {}
110110
self.read_data(datafiles)
111111
self.sampling = sampling
112112
self.batch_sizes = batch_sizes
@@ -298,13 +298,11 @@ def goal_run(self, current_params: tf.constant) -> tf.float64:
298298
# TODO: seq per point is not constant. Remove.
299299

300300
for target, data in self.learn_data.items():
301-
302301
self.learn_from = data["seqs_grouped_by_param_set"]
303302
self.gateset_opt_map = data["opt_map"]
304303
indeces = self.select_from_data(self.batch_sizes[target])
305304

306305
for ipar in indeces:
307-
308306
count += 1
309307
data_set = self.learn_from[ipar]
310308
m_vals = data_set["results"][:seqs_pp]
@@ -376,12 +374,10 @@ def goal_run_with_grad(self, current_params):
376374
count = 0
377375

378376
for target, data in self.learn_data.items():
379-
380377
self.learn_from = data["seqs_grouped_by_param_set"]
381378
self.gateset_opt_map = data["opt_map"]
382379
indeces = self.select_from_data(self.batch_sizes[target])
383380
for ipar in indeces:
384-
385381
count += 1
386382
data_set = self.learn_from[ipar]
387383

c3/optimizers/sensitivity.py

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def __init__(
6464
run_name: str = None,
6565
options={},
6666
) -> None:
67-
6867
super().__init__(
6968
sampling,
7069
batch_sizes,

c3/qiskit/c3_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def generate_shot_readout(self):
215215
# TODO a sophisticated readout/measurement routine (w/ SPAM)
216216
return (np.round(self.pops_array * self._shots)).astype("int32").tolist()
217217

218-
def run(self, qobj: qobj.Qobj, **backend_options) -> C3Job:
218+
def run(self, qobj: qobj.QasmQobj, **backend_options) -> C3Job:
219219
"""Parse and run a Qobj
220220
221221
Parameters

c3/utils/tf_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def tf_diff(l): # noqa
235235

236236
# MATRIX FUNCTIONS
237237

238+
238239
# TODO - change A.shape[: length-2] to tf.shape
239240
def Id_like(A):
240241
"""Identity of the same size as A."""

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ pytest-cov>=2.11.1
88
pytest-xdist>=2.2.1
99
python-dateutil>=2.8.1
1010
qiskit>=0.25.0
11+
qiskit-aer>=0.13.2
1112
rich>=9.2.0
1213
scipy>=1.5.2
1314
six>=1.15.0
1415
Sphinx>=3.2.1
1516
sphinx-autoapi>=1.4.0
16-
tensorflow>=2.4.1,<=2.14.1
17+
tensorflow>=2.15.0
1718
tensorflow-estimator>=2.4.0
1819
tensorflow-probability>=0.12.1

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Operating System :: MacOS",
2626
"Operating System :: Microsoft :: Windows :: Windows 10",
2727
"Operating System :: Unix",
28-
"Programming Language :: Python :: 3.9",
28+
"Programming Language :: Python :: 3.10",
2929
"Topic :: Scientific/Engineering :: Artificial Intelligence",
3030
"Topic :: Scientific/Engineering :: Physics",
3131
],
@@ -39,9 +39,9 @@
3939
"rich>=9.2.0",
4040
"numpy>=1.23.1",
4141
"scipy>=1.5.2",
42-
"tensorflow>=2.4.1,<=2.14.1",
42+
"tensorflow>=2.15.0",
4343
"tensorflow-estimator>=2.4.0",
4444
"tensorflow-probability>=0.12.1",
4545
],
46-
python_requires="~=3.9",
46+
python_requires="~=3.10",
4747
)

test/test_instruction.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,13 @@ def test_set_name_ideal():
189189
assert (instr.ideal == GATES["ry90p"]).all()
190190
instr.set_name("crzp")
191191
assert (instr.ideal == GATES["crzp"]).all()
192-
instr.name = 'ry90p'
192+
instr.name = "ry90p"
193193
assert (instr.ideal == GATES["ry90p"]).all()
194194

195195

196196
@pytest.mark.unit
197197
def test_correct_ideal_assignment() -> None:
198-
custom_gate = np.array([[1, 0, 0, 0],
199-
[0, 1, 0, 0],
200-
[0, 0, 0, 1],
201-
[0, 0, 1, 0]], dtype=np.complex)
198+
custom_gate = np.array([[1.0, 0j, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])
202199
propagators = {"custom": custom_gate}
203200
instructions = {"custom": Instruction("custom", ideal=custom_gate)}
204201
psi_0 = np.array([[1], [0], [0], [0]])
@@ -216,7 +213,7 @@ def test_correct_ideal_assignment() -> None:
216213
@pytest.mark.unit
217214
def test_correct_bloch_rotation_direction():
218215
# makes sure that the rotations on the bloch sphere are in the right direction
219-
GATE_NAME = 'ry90p[0]'
216+
GATE_NAME = "ry90p[0]"
220217
exp = create_experiment()
221218
exp.compute_propagators()
222219
# TODO - remove this line after the ideal updating bug gets fixed...
@@ -225,4 +222,6 @@ def test_correct_bloch_rotation_direction():
225222
ideal_gate = exp.pmap.instructions[GATE_NAME].get_ideal_gate(dims=[3])
226223
propagator = exp.propagators[GATE_NAME].numpy()
227224
# not equal to one because of imperfections in the propagation
228-
np.testing.assert_array_less(unitary_infid(ideal_gate, propagator, dims=[3]).numpy()[0], 0.05)
225+
np.testing.assert_array_less(
226+
unitary_infid(ideal_gate, propagator, dims=[3]).numpy()[0], 0.05
227+
)

test/test_parameter_map.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_parameter_extend() -> None:
256256
Test the setting in optimizer format. Parameter is out of bounds for the
257257
original pmap and should be extended.
258258
"""
259-
pmap.load_values("test/sample_optim_log.c3log",extend_bounds=True)
259+
pmap.load_values("test/sample_optim_log.c3log", extend_bounds=True)
260260
np.testing.assert_almost_equal(
261261
pmap.get_parameter(("rx90p[0]", "d1", "gauss", "freq_offset")).numpy(),
262262
-82997604.24565414,

test/test_qt_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_basis(get_test_dimensions) -> None:
3838
"""Testing orthonormality of basis vectors."""
3939
for dim in get_test_dimensions:
4040
pairs = [(i, j) for i in range(dim) for j in range(dim)]
41-
for (i, j) in pairs:
41+
for i, j in pairs:
4242
vi = basis(dim, i)
4343
vj = basis(dim, j)
4444
almost_equal(vi.T @ vj, 1 if i == j else 0)
@@ -60,7 +60,7 @@ def test_xy_basis(get_test_dimensions) -> None:
6060

6161
# overlap
6262
pairs = [(a, b) for a in names for b in names if b is not a]
63-
for (a, b) in pairs:
63+
for a, b in pairs:
6464
va_p = xy_basis(dim, a + "p")
6565
va_m = xy_basis(dim, a + "m")
6666
vb_p = xy_basis(dim, b + "p")
@@ -79,7 +79,7 @@ def test_basis_matrices(get_test_dimensions) -> None:
7979

8080
# orthogonality
8181
pairs = [(a, b) for a in matrices for b in matrices if b is not a]
82-
for (a, b) in pairs:
82+
for a, b in pairs:
8383
almost_equal(np.linalg.norm(np.multiply(a, b)), 0)
8484

8585
# normalisation

0 commit comments

Comments
 (0)