Skip to content

Commit

Permalink
Merge pull request #55 from ChitambarLab/update-qnetvo-version
Browse files Browse the repository at this point in the history
updating pennylane version
  • Loading branch information
bdoolittle authored Jul 25, 2024
2 parents 435517b + 728572f commit b516495
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 57 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/build_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ammaraskar/sphinx-action@master
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.4.1
with:
docs-folder: "docs/"
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r docs/requirements.txt
- name: Build Documentation
run: |
sphinx-build -b html docs/source/ docs/build/html
- name: Commit documentation changes
run: |
git clone https://github.com/ChitambarLab/qNetVO.git --branch gh-pages --single-branch gh-pages
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/check_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/"
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r docs/requirements.txt
- name: Build Documentation
run: |
sphinx-build -b html docs/source/ docs/build/html
2 changes: 1 addition & 1 deletion .github/workflows/formatting_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11

- name: Install dependencies
run: pip install black
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# qNetVO: The Quantum Network Variational Optimizer
# qNetVO: Quantum Network Variational Optimizer

*Simulate and optimize quantum communication networks using quantum computers.*

Expand Down Expand Up @@ -32,7 +32,7 @@ $ pip install qnetvo
Install PennyLane:

```
$ pip install pennylane==0.33
$ pip install pennylane==0.37
```

Import packages:
Expand All @@ -48,7 +48,7 @@ Note
</p>
<p>
For optimal use, qNetVO should be used with PennyLane.
QNetVO is currently compatible with PennyLane v0.33.
QNetVO is currently compatible with PennyLane v0.37.
</p>
</div>

Expand Down
8 changes: 4 additions & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.
sphinx>=3.0
sphinx
Pygments>=2.7.4
m2r2==0.3.3
sphinxcontrib-email==0.3.5
sphinx-mdinclude>=0.6
sphinxcontrib-email==0.3.6
furo
pennylane==0.28
pennylane==0.37
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"m2r2",
"sphinx_mdinclude",
"sphinxcontrib.email",
]
source_suffix = [".rst", ".md"]
Expand Down
6 changes: 2 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ channels:
- defaults
dependencies:
- python=3.11
- black
- sphinx
- black
- pytest
- notebook
- matplotlib
- pip
- pip:
- -r requirements.txt
- furo
- m2r2==0.3
- sphinxcontrib-email==0.3.5
- -r docs/requirements.txt
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pennylane~=0.33
qiskit==0.34
pennylane-qiskit==0.20
pennylane==0.37
qiskit>=1
pennylane-qiskit==0.37
tensorflow>=2.0,<3.0
dask[delayed]==2022.5
tensornetwork>=0.3,<0.4
flaky==3.7
pytest-rerunfailures
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ classifiers =
package_dir =
= src
packages = find:
python_requires = >=3.8
python_requires = >=3.9
install_requires =
pennylane~=0.33
pennylane==0.37

[options.packages.find]
where = src
8 changes: 5 additions & 3 deletions src/qnetvo/gradient_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ def gradient_descent(
if not (isinstance(settings, list)):
settings = [settings]
elif interface == "tf":
# opt.minimize updates settings in place
tf_cost = lambda: cost(*settings)
opt.minimize(tf_cost, settings)
with tf.GradientTape() as tape:
tf_cost = cost(*settings)

gradients = tape.gradient(tf_cost, settings)
opt.apply_gradients(zip(gradients, settings))

elapsed = time.time() - start

Expand Down
1 change: 1 addition & 0 deletions src/qnetvo/lazy_dask_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Lazily imports dask when needed.
Throws an error if the user does not have dask[delayed] installed.
"""

try:
import dask

Expand Down
1 change: 1 addition & 0 deletions src/qnetvo/lazy_tensorflow_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Lazily imports tensorflow when needed.
Throws an error if the user does not have tensorflow installed.
"""

try:
import tensorflow

Expand Down
5 changes: 2 additions & 3 deletions test/chsh_gradient_descent_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from flaky import flaky
import pennylane as qml
from pennylane import numpy as np

Expand Down Expand Up @@ -81,7 +80,7 @@ def test_chsh_gradient_descent_inhomogeneous_settings(self):

assert np.isclose(opt_dict["opt_score"], 2 * np.sqrt(2), atol=1e-3)

@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_parallel_chsh_gradient_descent(self):
prepare_nodes = [
qnet.PrepareNode(1, [0, 1], self.bell_state_RY, 2),
Expand All @@ -108,7 +107,7 @@ def test_parallel_chsh_gradient_descent(self):

assert np.isclose(opt_dict["opt_score"], 2 * np.sqrt(2), atol=1e-3)

@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_parallel_chsh_natural_gradient_descent(self):
prepare_nodes = [
qnet.PrepareNode(1, [0, 1], qnet.ghz_state, 0),
Expand Down
7 changes: 3 additions & 4 deletions test/cost/nlocal_chain_bell_inequality_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from flaky import flaky
from pennylane import numpy as np
import pennylane as qml

Expand Down Expand Up @@ -63,7 +62,7 @@ def test_nlocal_chain_22_cost_fn(self, parallel_flag):
),
],
)
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_parallel_nlocal_chain_grad_fn(self, natural_grad, prep_nodes, meas_nodes):
chain_ansatz = qnet.NetworkAnsatz(prep_nodes, meas_nodes)

Expand All @@ -81,7 +80,7 @@ def test_parallel_nlocal_chain_grad_fn(self, natural_grad, prep_nodes, meas_node
assert np.allclose(grad, grad_match)

@pytest.mark.parametrize("parallel_flag", [True, False])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_chain_J22_fn(self, parallel_flag):
prep_nodes = [
qnet.PrepareNode(1, [0, 1], qnet.local_RY, 2),
Expand Down Expand Up @@ -132,7 +131,7 @@ def test_chain_J22_fn(self, parallel_flag):
assert np.isclose(4, J22(*settings))

@pytest.mark.parametrize("parallel_flag", [True, False])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_chain_I22_fn(self, parallel_flag):
prep_nodes = [
qnet.PrepareNode(1, [0, 1], qnet.local_RY, 2),
Expand Down
23 changes: 11 additions & 12 deletions test/cost/nlocal_star_bell_inequality_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from flaky import flaky
from pennylane import numpy as np
import pennylane as qml

Expand Down Expand Up @@ -39,7 +38,7 @@ def trilocal_star_ry_ansatz(self):
return qnet.NetworkAnsatz(prep_nodes, meas_nodes)

@pytest.mark.parametrize("parallel_flag, nthreads", [(False, 4), (True, 4), (True, 3)])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_bilocal_star_22_cost(self, parallel_flag, nthreads):
bilocal_star_ansatz = self.bilocal_star_ry_ansatz()
bilocal_22_cost = qnet.nlocal_star_22_cost_fn(
Expand All @@ -55,7 +54,7 @@ def test_bilocal_star_22_cost(self, parallel_flag, nthreads):
assert np.isclose(bilocal_22_cost(*ideal_settings), -(np.sqrt(2)))

@pytest.mark.parametrize("parallel_flag, nthreads", [(False, 4), (True, 4), (True, 5)])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_trilocal_star_cost(self, parallel_flag, nthreads):
trilocal_star_ansatz = self.trilocal_star_ry_ansatz()
trilocal_22_cost = qnet.nlocal_star_22_cost_fn(
Expand Down Expand Up @@ -86,7 +85,7 @@ def test_trilocal_star_cost(self, parallel_flag, nthreads):
assert np.isclose(trilocal_22_cost(*ideal_settings), -np.sqrt(2))

@pytest.mark.parametrize("parallel_flag, nthreads", [(False, 4), (True, 4), (True, 5)])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_bilocal_star_22_cost_gradient_descent(self, parallel_flag, nthreads):
bilocal_star_ansatz = self.bilocal_star_ry_ansatz()

Expand All @@ -99,15 +98,15 @@ def test_bilocal_star_22_cost_gradient_descent(self, parallel_flag, nthreads):
num_steps=10,
step_size=2,
sample_width=10,
grad_fn=qnet.parallel_nlocal_star_grad_fn(bilocal_star_ansatz)
if parallel_flag
else None,
grad_fn=(
qnet.parallel_nlocal_star_grad_fn(bilocal_star_ansatz) if parallel_flag else None
),
)

assert np.isclose(opt_dict["opt_score"], np.sqrt(2), atol=0.0001)

@pytest.mark.parametrize("parallel_flag, nthreads", [(False, 4), (True, 4), (True, 5)])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_trilocal_star_22_cost_gradient_descent(self, parallel_flag, nthreads):
trilocal_star_ansatz = self.trilocal_star_ry_ansatz()

Expand All @@ -118,15 +117,15 @@ def test_trilocal_star_22_cost_gradient_descent(self, parallel_flag, nthreads):
num_steps=8,
step_size=2,
sample_width=10,
grad_fn=qnet.parallel_nlocal_star_grad_fn(trilocal_star_ansatz)
if parallel_flag
else None,
grad_fn=(
qnet.parallel_nlocal_star_grad_fn(trilocal_star_ansatz) if parallel_flag else None
),
)

assert np.isclose(opt_dict["opt_score"], np.sqrt(2), atol=0.0001)

@pytest.mark.parametrize("nthreads", [3, 4])
@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_bilocal_star_22_cost_natural_gradient_descent(self, nthreads):
bilocal_star_ansatz = self.bilocal_star_ry_ansatz()

Expand Down
8 changes: 4 additions & 4 deletions test/network_nodes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def circuit(settings, wires, cc_wires):

assert len(tape) == 1
assert tape.wires.tolist() == [0, 1]
assert tape.num_params == 0
assert tape.get_parameters() == []
assert tape.num_params == 1
assert all(tape.get_parameters()[0] == mock_settings)


def test_network_node_defaults():
Expand Down Expand Up @@ -223,5 +223,5 @@ def circuit(settings, wires, cc_wires):

assert len(tape) == 1
assert tape.wires.tolist() == [0, 1]
assert tape.num_params == 0
assert tape.get_parameters() == []
assert tape.num_params == 1
assert all(tape.get_parameters()[0] == mock_settings)
5 changes: 2 additions & 3 deletions test/nlocal_chain_gradient_descent_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from flaky import flaky
import pennylane as qml
from pennylane import numpy as np

Expand Down Expand Up @@ -42,7 +41,7 @@ def test_bilocal_chain_gradient_descent(self, optimization_args):

assert np.isclose(opt_dict["opt_score"], np.sqrt(2), atol=1e-3)

@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_bilocal_chain_parallel_gradient_descent(self, bilocal_chain_ansatz, optimization_args):
parallel_grad = qnet.parallel_nlocal_chain_grad_fn(bilocal_chain_ansatz)

Expand All @@ -57,7 +56,7 @@ def test_bilocal_chain_parallel_gradient_descent(self, bilocal_chain_ansatz, opt

assert np.isclose(opt_dict["opt_score"], np.sqrt(2), atol=1e-3)

@flaky(max_runs=5, min_passes=1)
@pytest.mark.flaky(5)
def test_bilocal_chain_natural_gradient_descent(self):
prep_nodes = [
qnet.PrepareNode(1, [0, 1], qnet.ghz_state, 0),
Expand Down

0 comments on commit b516495

Please sign in to comment.