Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement improved demo build pipeline #1286

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
b57ba0f
create new demos directory structure
brownj85 Dec 20, 2024
4dc5233
pick lib.qml tool
brownj85 Dec 20, 2024
b2e3edb
fix pytorch constraint
brownj85 Dec 20, 2024
bb76dae
restructure lib
brownj85 Dec 20, 2024
22acefc
Apply suggestions from code review
brownj85 Jan 16, 2025
326e586
docstrings
brownj85 Jan 16, 2025
5fcda7f
specify poetry<2
brownj85 Jan 16, 2025
fb46d78
sync
brownj85 Jan 16, 2025
6b19a63
requirements
brownj85 Jan 16, 2025
bea7530
fix tutorial quantum chemistry paths
brownj85 Jan 16, 2025
c51c68e
docs
brownj85 Jan 16, 2025
e768e21
docstrings
brownj85 Jan 16, 2025
ceea64f
update lockfile
brownj85 Jan 16, 2025
39d96d3
fmt
brownj85 Jan 27, 2025
8441b41
add core dependencies
brownj85 Jan 27, 2025
c54066c
fmt
brownj85 Jan 27, 2025
7aecbae
Merge branch 'master' into sc-79849-implement-improved-demo-build-pip…
brownj85 Jan 27, 2025
1fc423e
sync
brownj85 Jan 27, 2025
60e982e
fix v2
brownj85 Jan 27, 2025
424b4b0
clean conf.py
brownj85 Jan 27, 2025
70797e2
add requirements-parser
brownj85 Jan 27, 2025
00f517c
qiskit-aer spec
brownj85 Jan 27, 2025
36d8ec1
Merge branch 'sc-79849-implement-improved-demo-build-pipeline' into s…
brownj85 Jan 30, 2025
8b828ce
single demo builds
brownj85 Jan 31, 2025
8d1e3ec
don't generate full requirements
brownj85 Feb 7, 2025
0aded43
Merge branch 'master' into sc-79849-implement-improved-demo-build-pip…
brownj85 Feb 7, 2025
a505b55
sync
brownj85 Feb 7, 2025
dd0347a
Merge branch 'sc-79849-implement-improved-demo-build-pipeline' into s…
brownj85 Feb 7, 2025
f4c2367
add lxml
brownj85 Feb 7, 2025
1e86b65
pack demos
brownj85 Feb 7, 2025
03363b4
copy hardware images
brownj85 Feb 7, 2025
bbd53cd
skip non-executable demos
brownj85 Feb 7, 2025
20e7135
Merge branch 'sc-79849-implement-improved-demo-build-pipeline' into s…
brownj85 Feb 7, 2025
b4c1e66
jax
brownj85 Feb 7, 2025
2212966
jax
brownj85 Feb 7, 2025
cf7a5ce
Merge branch 'sc-79849-implement-improved-demo-build-pipeline' into s…
brownj85 Feb 7, 2025
00c4454
add actions for build and deploy to content service
brownj85 Feb 11, 2025
5fa842e
add inherit secrets
brownj85 Feb 11, 2025
9d137e1
add pypandoc_binary
brownj85 Feb 11, 2025
e79f85b
Merge branch 'sc-79849-implement-improved-demo-build-pipeline' into s…
brownj85 Feb 11, 2025
53f52d1
fix organization
brownj85 Feb 11, 2025
7880301
add openfermion dep to tutorial_diffable_shadows
brownj85 Feb 11, 2025
55a29b0
Merge branch 'sc-79849-implement-improved-demo-build-pipeline' into s…
brownj85 Feb 11, 2025
53be132
update
brownj85 Feb 11, 2025
8f0b2d9
remove pypandoc-binary
brownj85 Feb 11, 2025
111fb92
Merge branch 'sc-81925-qml-repository-ci-pushes-newly-built-demos' in…
brownj85 Feb 11, 2025
8c24d01
demo
brownj85 Feb 11, 2025
98c63f8
push trigger
brownj85 Feb 11, 2025
d1ac538
fx environment
brownj85 Feb 11, 2025
a8b5ec3
use GITHUB_OUTPUT
brownj85 Feb 11, 2025
8ba91a3
formatting
brownj85 Feb 11, 2025
b4d200d
deploy
brownj85 Feb 11, 2025
17a8899
gbs
brownj85 Feb 11, 2025
3ecf175
rename deploy step
brownj85 Feb 11, 2025
d86d97a
error handling
brownj85 Feb 11, 2025
9b19a4d
hmm
brownj85 Feb 11, 2025
6dfd10a
fix deploy
brownj85 Feb 11, 2025
5a7aab3
test build
brownj85 Feb 11, 2025
b8a6dcc
reqs
brownj85 Feb 11, 2025
2586336
test
brownj85 Feb 11, 2025
756309c
fix build issues
brownj85 Feb 12, 2025
2c42e58
fix gallery path
brownj85 Feb 12, 2025
76df2c8
requirements
brownj85 Feb 12, 2025
3ff2753
qrack
brownj85 Feb 12, 2025
8f95123
concurrency
brownj85 Feb 12, 2025
420a1ca
install system dependencies
brownj85 Feb 13, 2025
86f7789
fix error summary
brownj85 Feb 13, 2025
35a4477
remove kak_theorem
brownj85 Feb 13, 2025
51f52d2
fetch hymenoptera_data
brownj85 Feb 13, 2025
032be6e
error logging
brownj85 Feb 13, 2025
3e86fe1
test all
brownj85 Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ backreferences
.DS_Store
demos_community.rst
.venv/
.venv-build/
**/*.egg-info/

# Generated after installation
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.analysis.ignore": [
".venv/**",
".venv-build/**",
"_build/**"
]
}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ environment:
$$PYTHON_VENV_PATH/bin/python -m pip install --upgrade git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane;\
fi;\
fi

fmt:
poetry run ruff check --fix lib/
poetry run ruff format lib/
9 changes: 6 additions & 3 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from jinja2 import FileSystemLoader, Environment
import yaml
from pennylane import PennyLaneDeprecationWarning
from pathlib import Path

sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
Expand Down Expand Up @@ -56,12 +57,12 @@
"extension",
]


html_baseurl = "https://pennylane.ai/qml/"
demo_staging_dir = os.getenv("DEMO_STAGING_DIR", "demonstrations")

sphinx_gallery_conf = {
# path to your example scripts
"examples_dirs": ["demonstrations"],
"examples_dirs": [demo_staging_dir],
# path where to save gallery generated examples
"gallery_dirs": ["demos"],
# execute files that match the following filename pattern,
Expand All @@ -85,6 +86,8 @@
"doc_module" : ("pennylane"),
"junit": "../test-results/sphinx-gallery/junit.xml",
"reset_modules": ("module_resets.reset_jax", "matplotlib", "seaborn"),
"show_signature": False,
'download_all_examples': False,
}


Expand Down Expand Up @@ -136,7 +139,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "*venv", "sphinxext"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "*venv", "*venv-build", "sphinxext"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand Down
144 changes: 144 additions & 0 deletions demonstrations_v2/adjoint_diff_benchmarking/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
r"""

.. _adjoint_differentiation_benchmarking:

Adjoint Differentiation
=======================

.. meta::
:property="og:description": Benchmarking file for adjoint diff demonstration.
:property="og:image": https://pennylane.ai/qml/_static/demo_thumbnails/opengraph_demo_thumbnails/code.png


*Author: Christina Lee — Posted: 23 November 2021. Last updated: 04 July 2024.*

"""

##############################################################################
# This page is supplementary material to the
# `Adjoint Differentiation <https://pennylane.ai/qml/demos/tutorial_adjoint_diff.html>`__
# demonstration. The below script produces the benchmarking images used.

import timeit
import matplotlib.pyplot as plt
import pennylane as qml
import jax

jax.config.update("jax_platform_name", "cpu")
jax.config.update('jax_enable_x64', True)

plt.style.use("bmh")

n_samples = 5


def get_time(qnode, params):
globals_dict = {'grad': jax.grad, 'circuit': qnode, 'params': params}
return timeit.timeit("grad(circuit)(params)", globals=globals_dict, number=n_samples)


def wires_scaling(n_wires, n_layers):
key = jax.random.PRNGKey(42)

t_adjoint = []
t_ps = []
t_backprop = []

def circuit(params, wires):
qml.StronglyEntanglingLayers(params, wires=range(wires))
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1) @ qml.PauliZ(2))

for i_wires in n_wires:
dev = qml.device("lightning.qubit", wires=i_wires)
dev_python = qml.device("default.qubit", wires=i_wires)

circuit_adjoint = qml.QNode(lambda x: circuit(x, wires=i_wires), dev, diff_method="adjoint")
circuit_ps = qml.QNode(lambda x: circuit(x, wires=i_wires), dev, diff_method="parameter-shift")
circuit_backprop = qml.QNode(lambda x: circuit(x, wires=i_wires), dev_python, diff_method="backprop")

# set up the parameters
param_shape = qml.StronglyEntanglingLayers.shape(n_wires=i_wires, n_layers=n_layers)
params = jax.random.normal(key, param_shape)

t_adjoint.append(get_time(circuit_adjoint, params))
t_backprop.append(get_time(circuit_backprop, params))
t_ps.append(get_time(circuit_ps, params))

return t_adjoint, t_backprop, t_ps


def layers_scaling(n_wires, n_layers):
key = jax.random.PRNGKey(42)

dev = qml.device("lightning.qubit", wires=n_wires)
dev_python = qml.device('default.qubit', wires=n_wires)

t_adjoint = []
t_ps = []
t_backprop = []

def circuit(params):
qml.StronglyEntanglingLayers(params, wires=range(n_wires))
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1) @ qml.PauliZ(2))

circuit_adjoint = qml.QNode(circuit, dev, diff_method="adjoint")
circuit_ps = qml.QNode(circuit, dev, diff_method="parameter-shift")
circuit_backprop = qml.QNode(circuit, dev_python, diff_method="backprop")

for i_layers in n_layers:
# set up the parameters
param_shape = qml.StronglyEntanglingLayers.shape(n_wires=n_wires, n_layers=i_layers)
params = jax.random.normal(key, param_shape)

t_adjoint.append(get_time(circuit_adjoint, params))
t_backprop.append(get_time(circuit_backprop, params))
t_ps.append(get_time(circuit_ps, params))

return t_adjoint, t_backprop, t_ps


if __name__ == "__main__":

wires_list = [3, 6, 9, 12, 15]
n_layers = 6
adjoint_wires, backprop_wires, ps_wires = wires_scaling(wires_list, n_layers)

layers_list = [3, 9, 15, 21, 27]
n_wires = 12
adjoint_layers, backprop_layers, ps_layers = layers_scaling(n_wires, layers_list)

# Generating the graphic
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))

ax1.plot(wires_list, adjoint_wires, '.-', label="adjoint")
ax1.plot(wires_list, ps_wires, '.-', label="parameter-shift")
ax1.plot(wires_list, backprop_wires, '.-', label="backprop")

ax1.legend()

ax1.set_xlabel("Number of wires")
ax1.set_xticks(wires_list)
ax1.set_ylabel("Log Time")
ax1.set_yscale("log")
ax1.set_title("Scaling with wires")

ax2.plot(layers_list, adjoint_layers, '.-', label="adjoint")
ax2.plot(layers_list, ps_layers, '.-', label="parameter-shift")
ax2.plot(layers_list, backprop_layers, '.-', label="backprop")

ax2.legend()

ax2.set_xlabel("Number of layers")
ax2.set_xticks(layers_list)
ax2.set_ylabel("Time")
ax2.set_title("Scaling with Layers")

plt.savefig("scaling.png")

##############################################################################
#
# .. figure:: ../_static/demonstration_assets/adjoint_diff/scaling.png
# :width: 80%
# :align: center
#
#
24 changes: 24 additions & 0 deletions demonstrations_v2/adjoint_diff_benchmarking/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": "Adjoint Differentiation \u2013 Supplementary Material",
"authors": [
{
"username": "christina"
}
],
"dateOfPublication": "2021-11-23T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"categories": [],
"tags": [],
"previewImages": [
{
"type": "thumbnail",
"uri": "/_static/demo_thumbnails/regular_demo_thumbnails/thumbnail_adjoint_differentiation.png"
}
],
"seoDescription": "Benchmarking file for adjoint diff demonstration.",
"doi": "",
"references": [],
"basedOnPapers": [],
"referencedByPapers": [],
"relatedContent": []
}
4 changes: 4 additions & 0 deletions demonstrations_v2/adjoint_diff_benchmarking/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jax
jaxlib
matplotlib
pennylane
Loading
Loading