Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions .github/workflows/v2-build-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@ on:
description: Number of demos to build per job.
type: number
default: 10
lightning-version:
description: Specify the version of PennyLane-Lightning to install (default PennyLane-Lightning).
required: false
type: string
default: "PennyLane-Lightning"
catalyst-version:
description: Specify the version of PennyLane-Catalyst to install (default PennyLane-Catalyst).
required: false
type: string
default: "PennyLane-Catalyst"
pennylane-version:
description: Specify the version of PennyLane to install (default git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane).
required: false
type: string
default: "git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane"
extra-index-url:
description: Specify an additional index URL for pip to use (default None).
required: false
type: string
default: null
testpypi:
description: Use TestPyPI as an additional package index (default None).
required: false
type: string
default: null
prerelease-packages:
description: Allow installation of pre-release packages (default False).
required: false
type: boolean
default: false
outputs:
artifact-name:
description: "Name of the artifact containing the built demos"
Expand Down Expand Up @@ -169,6 +199,7 @@ jobs:

- name: Install pandoc, opencl, and graphviz
run: |
sudo apt-get update
sudo apt-get install -y \
ocl-icd-opencl-dev \
pandoc \
Expand All @@ -194,8 +225,11 @@ jobs:
${{ inputs.keep-going && '--keep-going' || '--no-keep-going' }} \
${{ inputs.quiet && '--quiet' || '--no-quiet' }} \
${{ steps.demo-name-list.outputs.demo-names }} \
${{ inputs.dev && '--dev' || '--no-dev' }}

${{ inputs.dev && '--dev' || '--no-dev' }} \
--lightning-version "${{ inputs.lightning-version }}" \
--catalyst-version "${{ inputs.catalyst-version }}" \
--pennylane-version "${{ inputs.pennylane-version }}"

- name: Upload artifacts
id: upload-artifacts
if: ${{ inputs.save-artifact }}
Expand Down
122 changes: 122 additions & 0 deletions .github/workflows/v2-build-rc-demos-daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build Daily RC Demos
on:
schedule:
- cron: '0 11 * * 1-5' # Runs weekdays 6 am ET
workflow_dispatch:
push:

jobs:
check-for-rc-branches:
runs-on: ubuntu-latest
outputs:
branch_exists: ${{ steps.check-rc-branches.outputs.branch_exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: PennyLaneAI/pennylane

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install latest setuptools
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools packaging

- name: Check for RC branches
id: check-rc-branches
run: |
VERSION=$(python setup.py --version)
echo "Current version: $VERSION"
IFS=. read MAJ MIN PAT <<< "${VERSION%-dev[0-9]*}"
RC_BRANCH="v${MAJ}.$((MIN-2)).${PAT}-rc0"
if git ls-remote --exit-code origin "refs/heads/$RC_BRANCH"; then
echo "branch_exists=true" >> $GITHUB_OUTPUT
echo "rc_branch=$RC_BRANCH" >> $GITHUB_OUTPUT
else
echo "branch_exists=true" >> $GITHUB_OUTPUT # TODO change to false
echo "No RC branch found."
fi

build-demos-with-rc-branches:
runs-on: ubuntu-latest
needs: check-for-rc-branches
# if: needs.check-for-rc-branches.outputs.branch_exists == 'true'
outputs:
pennylane-version: ${{ steps.setup-rc-versions.outputs.pennylane-version }}
lightning-version: ${{ steps.setup-rc-versions.outputs.lightning-version }}
catalyst-version: ${{ steps.setup-rc-versions.outputs.catalyst-version }}
rc-build-branch: ${{ steps.setup-rc-versions.outputs.rc-build-branch }}
steps:
- name: Checkout QML repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Set up rc versions
id: setup-rc-versions
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
rc_build_branch=rc-daily-build-$(date +'%Y-%m-%d-%H%M%S')
git checkout -b $rc_build_branch
python -m pip index versions pennylane 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true
pennylane_version=$(python -m pip index versions pennylane 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)
lightning_version=$(python -m pip index versions pennylane-lightning 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 ||true )
catalyst_version=$(python -m pip index versions pennylane-catalyst 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)
echo "lightning-version=$lightning_version" >> $GITHUB_OUTPUT
echo "catalyst-version=$catalyst_version" >> $GITHUB_OUTPUT
echo "pennylane-version=$pennylane_version" >> $GITHUB_OUTPUT
echo "rc-build-branch=$rc_build_branch" >> $GITHUB_OUTPUT
echo "PennyLane version: $pennylane_version, PennyLane-Lightning version: $lightning_version, PennyLane-Catalyst version: $catalyst_version"

# - name: Update demo versions
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# sed -i -E "s#git\+https://github.com/PennyLaneAI/pennylane.git\#egg=pennylane\",#pennylane<=${{ steps.setup-rc-versions.outputs.pennylane-version }}\",\\n\\t\\t\\t\"—extra-index-url\",\\n\\t\\t\\t\"https://test.pypi.org/simple/\",\\n\\t\\t\\tpre=True,#" lib/qml/lib/demo.py
# sed -i "s/PennyLane-Lightning/pennylane-lightning<=${{ steps.setup-rc-versions.outputs.lightning-version }}/" lib/qml/lib/demo.py
# sed -i "s/PennyLane-Catalyst/pennylane-catalyst<=${{ steps.setup-rc-versions.outputs.catalyst-version }}/" lib/qml/lib/demo.py
# git commit -am "Set up RC versions for demo builds"
# git push --set-upstream origin ${{ steps.setup-rc-versions.outputs.rc-build-branch }}

build-demos:
needs: build-demos-with-rc-branches
uses: ./.github/workflows/v2-build-demos.yml
with:
ref: sc-101692-dailyrcbuild #'${{ needs.build-demos-with-rc-branches.outputs.rc-build-branch }}'
demo-names: ''
execute: true
dev: true
save-artifact: true
artifact-name: 'demo-build-use-rc'
artifact-retention: 10
keep-going: false
quiet: false
batch_size: 10
pennylane-version: 'pennylane<=${{ needs.build-demos-with-rc-branches.outputs.pennylane-version }}'
lightning-version: 'pennylane-lightning<=${{ needs.build-demos-with-rc-branches.outputs.lightning-version }}'
catalyst-version: 'pennylane-catalyst<=${{ needs.build-demos-with-rc-branches.outputs.catalyst-version }}'
extra-index-url: 'https://test.pypi.org/simple/'
testpypi: true
prerelease-packages: true

cleanup:
runs-on: ubuntu-latest
needs:
- build-demos
- build-demos-with-rc-branches
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cleanup branch
run: |
echo "Cleaning up branch '${{ needs.build-demos-with-rc-branches.outputs.rc-build-branch }}'"
git push origin --delete '${{ needs.build-demos-with-rc-branches.outputs.rc-build-branch }}'|| true
2 changes: 1 addition & 1 deletion dependencies/constraints-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ openfermionpyscf==0.5
openqaoa-core==0.2.5
qiskit>=2.0
qiskit-aer>=0.17
qiskit_ibm_runtime==0.41.1
qiskit_ibm_runtime>=0.41.1
torch==2.1.2+cpu ; sys_platform != 'darwin'
torch==2.1.2 ; sys_platform == 'darwin'
torchvision==0.16.2+cpu ; sys_platform != 'darwin'
Expand Down
16 changes: 16 additions & 0 deletions lib/qml/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def build(
bool, typer.Option(help="Continue if sphinx-build fails for a demo")
] = False,
dev: Annotated[bool, typer.Option(help="Whether to use dev dependencies")] = False,
lightning_version: Annotated[
Optional[str], typer.Option(help="Version of Lightning to use")
] = "PennyLane-Lightning",
catalyst_version: Annotated[
Optional[str], typer.Option(help="Version of Catalyst to use")
] = "PennyLane-Catalyst",
pennylane_version: Annotated[
Optional[str], typer.Option(help="Version of PennyLane to use")
] = "git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane",
) -> None:
"""
Build the named demos.
Expand Down Expand Up @@ -96,6 +105,10 @@ def build(
logger.error(f"Failed to copy static files: {e}")
raise typer.Exit(1)

final_pennylane_version = pennylane_version or "pennylane"
final_catalyst_version = catalyst_version or "pennylane-catalyst"
final_lightning_version = lightning_version or "pennylane-lightning"

demo.build(
ctx,
demos=demos,
Expand All @@ -104,6 +117,9 @@ def build(
quiet=quiet,
keep_going=keep_going,
dev=dev,
catalyst_version=final_catalyst_version,
pennylane_version=final_pennylane_version,
lightning_version=final_lightning_version,
)

except Exception as e:
Expand Down
33 changes: 25 additions & 8 deletions lib/qml/lib/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import lxml.html
from qml.context import Context
import sphobjinv as soi
import argparse


logger = getLogger("qml")


class BuildTarget(Enum):
"""Sphinx-build targets."""

Expand Down Expand Up @@ -152,6 +152,9 @@ def build(
quiet: bool = False,
keep_going: bool = False,
dev: bool = False,
lightning_version: str = "PennyLane-Lightning",
catalyst_version: str = "PennyLane-Catalyst",
pennylane_version: str = "git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane",
) -> None:
"""Build the provided demos using 'sphinx-build', optionally
executing them to generate plots and cell outputs.
Expand Down Expand Up @@ -189,6 +192,7 @@ def build(
)

try:
logger.info("lightning_version:- ", lightning_version)
_build_demo(
ctx,
build_venv=build_venv,
Expand All @@ -198,6 +202,9 @@ def build(
package=target is BuildTarget.JSON,
quiet=quiet,
dev=dev,
lightning_version=lightning_version,
catalyst_version=catalyst_version,
pennylane_version=pennylane_version,
)
except subprocess.CalledProcessError as exc:
if not keep_going:
Expand Down Expand Up @@ -242,9 +249,10 @@ def build(


def generate_requirements(
ctx: Context, demo: Demo, dev: bool, output_file: Path
ctx: Context, demo: Demo, dev: bool, output_file: Path, pennylane_version: str, catalyst_version: str, lightning_version: str,
) -> None:
constraints = [ctx.build_requirements_file]

if dev:
constraints.append(ctx.dev_constraints_file)
else:
Expand All @@ -260,7 +268,7 @@ def generate_requirements(
*requirements_in,
constraints_files=constraints,
quiet=False,
prerelease=dev,
prerelease=dev,
)


Expand All @@ -273,11 +281,14 @@ def _build_demo(
package: bool,
quiet: bool,
dev: bool,
lightning_version: str,
catalyst_version: str,
pennylane_version: str,
):
out_dir = ctx.repo_root / "demos"
fs.clean_dir(out_dir)

generate_requirements(ctx, demo, dev, out_dir / "requirements.txt")
generate_requirements(ctx, demo, dev, out_dir / "requirements.txt", pennylane_version, catalyst_version, lightning_version)
if execute:
cmds.pip_install(
build_venv.python,
Expand All @@ -286,17 +297,19 @@ def _build_demo(
quiet=False,
pre=dev,
)

logger.info("lightning_version inside _build_demo:- ", lightning_version)
# If dev, we need to re-install the latest Catalyst, then Lightning, then PennyLane
# in that order, regardless of conflicts/warnings.
if dev:
# Catalyst
logger.info("lightning_version inside dev:-", lightning_version)
cmds.pip_install(
build_venv.python,
"--upgrade",
"--extra-index-url",
"https://test.pypi.org/simple/",
"PennyLane-Catalyst",
"sphinx==8.1",
catalyst_version,
use_uv=False,
quiet=False,
pre=True,
Expand All @@ -307,7 +320,7 @@ def _build_demo(
"--upgrade",
"--extra-index-url",
"https://test.pypi.org/simple/",
"PennyLane-Lightning",
lightning_version,
use_uv=False,
quiet=False,
pre=True,
Expand All @@ -317,9 +330,13 @@ def _build_demo(
cmds.pip_install(
build_venv.python,
"--upgrade",
"git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane",
"sphinx==8.1",
"--extra-index-url",
"https://test.pypi.org/simple/",
pennylane_version,
use_uv=False,
quiet=False,
pre=True,
)

stage_dir = ctx.build_dir / "demonstrations"
Expand Down
Loading