Skip to content

Commit d4e7357

Browse files
Use JSON
1 parent 4f80f34 commit d4e7357

5 files changed

Lines changed: 34 additions & 64 deletions

File tree

dependencies/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This directory houses the files that specify and constrain the dependencies requ
77
* [Overview](#overview)
88
* [Dependency Files](#dependency-files)
99
* [`constraints-dev.txt`](#constraints-devtxt)
10-
* [`constraints-plc-dev.txt`](#constraints-plc-devtxt)
10+
* [`constraints-plc-dev.json`](#constraints-plc-devjson)
1111
* [`constraints-stable.txt`](#constraints-stabletxt)
1212
* [`requirements-build.txt`](#requirements-buildtxt)
1313
* [`requirements-core.in`](#requirements-corein)
@@ -31,12 +31,13 @@ This file specifies the allowed versions of dependencies for building and runnin
3131
* **Location:** `./constraints-dev.txt`
3232
* **Purpose:** Defines dependencies for the `qml build --dev` command.
3333

34-
### `constraints-plc-dev.txt`
34+
### `constraints-plc-dev.json`
3535

36-
This file specifies the allowed versions of PennyLane, Lightning, and Catalyst for **development builds**. These files are currently installed **onyl if the demo is set to be executed** (`qml build --execute --dev`). These versions are pulled from test-pypi so that the release candidate versions are used during feature freeze. Unless you're a release manager, you likely don't need to modify this file.
36+
This file specifies the allowed release versions of PennyLane, Lightning, and Catalyst for **development builds**. These packages are currently installed **only if the demo is set to be executed** (`qml build --execute --dev`). The latest version available on test-pypi, whose release version matches the constraint, is what gets installed (e.g. 0.45.0.dev15 == 0.45.0, 0.45.0rc7 == 0.45.0, 0.46.0.dev3 != 0.45.0, etc.). Only update this constraint after a new release, so that the release candidate versions continue to be used during feature freeze. Unless you're a release manager, you likely don't need to modify this file.
3737

38-
* **Location:** `./constraints-plc-dev.txt`
38+
* **Location:** `./constraints-plc-dev.json`
3939
* **Purpose:** Defines PennyLane, Lightning, and Catalyst versions for the `qml build --execute --dev` command.
40+
* **Format:** JSON array of objects with the package names as keys. Order of entries must be preserved (Catalyst, then Lightning, then PennyLane).
4041

4142
### `constraints-stable.txt`
4243

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{"name": "pennylane-catalyst", "version": "0.15.0"},
3+
{"name": "pennylane-lightning", "version": "0.45.0"},
4+
{"name": "pennylane", "version": "0.45.0"}
5+
]

dependencies/constraints-plc-dev.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/qml/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def dev_constraints_file(self) -> Path:
5151

5252
@property
5353
def plc_dev_constraints_file(self) -> Path:
54-
return self.repo_root / "dependencies" / "constraints-plc-dev.txt"
54+
return self.repo_root / "dependencies" / "constraints-plc-dev.json"
5555

5656
@property
5757
def build_requirements_file(self) -> Path:

lib/qml/lib/demo.py

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass
22
from pathlib import Path, PurePosixPath
33
from collections.abc import Sequence, Iterator
4+
from packaging.version import Version
45
import shutil
56
from qml.lib import fs, cmds
67
from qml.lib.virtual_env import Virtualenv
@@ -297,57 +298,28 @@ def _build_demo(
297298
# If dev, we need to re-install the latest Catalyst, then Lightning, then PennyLane
298299
# in that order, regardless of conflicts/warnings.
299300
if dev:
300-
with open(ctx.plc_dev_constraints_file, "r") as f:
301-
packages = f.readlines()
302-
for package in packages:
303-
package = package.strip()
304-
if package and not package.startswith("#"):
305-
logger.info("Getting versions for %s", package)
306-
try:
307-
package_name, constraint = package.split("<", maxsplit=1)
308-
except:
309-
logger.error("Malformed constraints file for PLC dev.")
310-
raise
311-
package_versions = cmds.pip_get_versions(build_venv.python, package_name, index_url="https://test.pypi.org/simple/")
312-
for version in package_versions:
313-
if version < constraint:
314-
logger.info("Installing %s==%s", package_name, version)
315-
#Testing. Refactor this later if successful
316-
if package_name == "pennylane-catalyst":
317-
cmds.pip_install(
318-
build_venv.python,
319-
"--no-cache-dir",
320-
"--extra-index-url",
321-
"https://test.pypi.org/simple/",
322-
f"{package_name}=={version}",
323-
use_uv=False,
324-
quiet=False,
325-
)
326-
elif package_name == "pennylane-lightning":
327-
cmds.pip_install(
328-
build_venv.python,
329-
"--no-cache-dir",
330-
"--force-reinstall",
331-
"--no-deps",
332-
"--extra-index-url",
333-
"https://test.pypi.org/simple/",
334-
f"{package_name}=={version}",
335-
use_uv=False,
336-
quiet=False,
337-
)
338-
elif package_name == "pennylane":
339-
cmds.pip_install(
340-
build_venv.python,
341-
"--no-cache-dir",
342-
"--force-reinstall",
343-
"--no-deps",
344-
"--extra-index-url",
345-
"https://test.pypi.org/simple/",
346-
f"{package_name}=={version}",
347-
use_uv=False,
348-
quiet=False,
349-
)
350-
break
301+
base_install_args = [
302+
build_venv.python,
303+
"--no-cache-dir",
304+
"--extra-index-url",
305+
"https://test.pypi.org/simple/",
306+
]
307+
with open(ctx.plc_dev_constraints_file) as f:
308+
constraints = json.load(f)
309+
for package in constraints:
310+
logger.info("Getting versions for %s", package["name"])
311+
package_versions = cmds.pip_get_versions(build_venv.python, package["name"], index_url="https://test.pypi.org/simple/")
312+
# These are ruturned newest to oldest, so we can break when we find the first match
313+
for version in package_versions:
314+
if Version(version).release == Version(package["version"]).release:
315+
logger.info("Installing %s==%s", package["name"], version)
316+
install_args = base_install_args.copy()
317+
if package["name"] != "pennylane-catalyst":
318+
install_args.append("--force-reinstall")
319+
install_args.append("--no-deps")
320+
install_args.append(f"{package['name']}=={version}")
321+
cmds.pip_install(*install_args, use_uv=False, quiet=False)
322+
break
351323
# Need to reinstall the demo's requirements file to ensure the correct versions are installed
352324
if demo.requirements_file:
353325
cmds.pip_install(

0 commit comments

Comments
 (0)