Skip to content

Commit

Permalink
Bump required versions of Lightning and Catalyst (#5963)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas R. Bromley <[email protected]>
  • Loading branch information
astralcai and trbromley authored Jul 8, 2024
1 parent 9a60574 commit af5bd6d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/stable/external.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ packaging==24.1
pandocfilters==1.5.1
parso==0.8.4
pathspec==0.12.1
PennyLane-Catalyst==0.6.0
PennyLane_Lightning==0.36.0
PennyLane-Catalyst==0.7.0
PennyLane_Lightning==0.37.0
pexpect==4.9.0
pillow==10.3.0
platformdirs==4.2.2
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/install_deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ runs:
python setup.py bdist_wheel
pip install dist/PennyLane*.whl
- name: Install Catalyst
shell: bash
if: inputs.install_catalyst_after_pennylane == 'true'
run: pip install --upgrade pennylane-catalyst

- name: Install PennyLane-Lightning master
shell: bash
if: inputs.install_pennylane_lightning_master == 'true'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/interface-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ jobs:
install_jax: true
install_tensorflow: true
install_pytorch: false
# This is required during the release process when the latest released version of
# catalyst requires the latest version of pennylane that is about to be released.
# Installing catalyst after pennylane to make sure that the latest catalyst is used.
install_catalyst_after_pennylane: true
# using lightning master does not work for the tests with external libraries
install_pennylane_lightning_master: false
pytest_coverage_flags: ${{ inputs.pytest_coverage_flags }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ on:
required: false
type: string
default: ''
install_catalyst_after_pennylane:
description: Indicate if the latest Catalyst should be installed after PennyLane
required: false
type: boolean
default: false
install_pennylane_lightning_master:
description: Indicate if PennyLane-Lightning should be installed from the master branch
required: false
Expand Down Expand Up @@ -147,6 +152,7 @@ jobs:
install_tensorflow: ${{ inputs.install_tensorflow }}
install_jax: ${{ inputs.install_jax }}
additional_pip_packages: ${{ inputs.additional_pip_packages }}
install_catalyst_after_pennylane: ${{ inputs.install_catalyst_after_pennylane }}
install_pennylane_lightning_master: ${{ inputs.install_pennylane_lightning_master }}
requirements_file: ${{ inputs.requirements_file }}

Expand Down
50 changes: 32 additions & 18 deletions doc/releases/changelog-0.37.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,41 @@
[(#5795)](https://github.com/PennyLaneAI/pennylane/pull/5795)

Either method can be selected when instantiating the `default.tensor` device by setting the
`method` keyword argument to `"tn"` (tensor network) or `"mps"` (matrix product state). This
device can simulate a large number of qubits. Take this example that
simulates 1000 qubits with a shallow circuit in a few seconds!
`method` keyword argument to `"tn"` (tensor network) or `"mps"` (matrix product state).

There are
[several templates in PennyLane](https://docs.pennylane.ai/en/stable/introduction/templates.html#tensor-networks)
that are tensor-network focused, which are excellent candidates for the `"tn"` method for
`default.tensor`. The following example shows how a circuit comprising gates in a tree tensor
network architecture can be efficiently simulated using `method="tn"`.

```python
import pennylane as qml

num_qubits = 1000
dev = qml.device("default.tensor", method="mps")
n_wires = 16
dev = qml.device("default.tensor", method="tn")

def block(weights, wires):
qml.CNOT(wires=[wires[0], wires[1]])
qml.RY(weights[0], wires=wires[0])
qml.RY(weights[1], wires=wires[1])

n_block_wires = 2
n_params_block = 2
n_blocks = qml.TTN.get_n_blocks(range(n_wires), n_block_wires)
template_weights = [[0.1, -0.3]] * n_blocks

@qml.qnode(dev)
def circuit():
qml.Hadamard(0)
for i in range(num_qubits - 1):
qml.CNOT([i, i + 1])
return qml.expval(qml.Z(num_qubits - 1))
def circuit(template_weights):
for i in range(n_wires):
qml.Hadamard(i)
qml.TTN(range(n_wires), n_block_wires, block, n_params_block, template_weights)
return qml.expval(qml.Z(n_wires - 1))
```

```pycon
>>> circuit()
tensor(0., requires_grad=True)
>>> circuit(template_weights)
0.3839174759751649
```

For matrix product state simulations (`method="mps"`), we can make the execution be approximate by setting `max_bond_dim` (see the
Expand Down Expand Up @@ -213,18 +227,18 @@ via the `NoiseModel` class and an `add_noise` transform.
For example, `qml.debug_tape()` returns the tape of the circuit, giving access to its operations and drawing:

```pycon
(pldb): tape = qml.debug_tape()
(pldb): print(tape.draw(wire_order=[0,1,2]))
[pldb] tape = qml.debug_tape()
[pldb] print(tape.draw(wire_order=[0,1,2]))
0: ──H─╭●─┤
2: ────╰X─┤
(pldb): tape.operations
[pldb] tape.operations
[Hadamard(wires=[0]), CNOT(wires=[0, 2])]
```

While `qml.debug_state()` is equivalent to `qml.state()` and gives the current state:

```pycon
(pldb): print(qml.debug_state())
[pldb] print(qml.debug_state())
[0.70710678+0.j 0. +0.j 0. +0.j 0. +0.j
1. +0.j 0.70710678+0.j 0. +0.j 0. +0.j]
```
Expand All @@ -236,9 +250,9 @@ via the `NoiseModel` class and an `add_noise` transform.
Finally, to modify a circuit mid-run, simply call the desired PennyLane operations:

```pycon
(pldb) qml.CNOT(wires=(0,2))
[pldb] qml.CNOT(wires=(0,2))
CNOT(wires=[0, 2])
(pldb): print(qml.debug_tape().draw(wire_order=[0,1,2]))
[pldb] print(qml.debug_tape().draw(wire_order=[0,1,2]))
0: ──H─╭●─╭●─┤
2: ────╰X─╰X─┤
```
Expand Down
2 changes: 1 addition & 1 deletion pennylane/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from packaging.version import Version

PL_CATALYST_MIN_VERSION = Version("0.6.0")
PL_CATALYST_MIN_VERSION = Version("0.7.0")


class CompileError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"semantic-version>=2.7",
"autoray>=0.6.11",
"cachetools",
"pennylane-lightning>=0.36",
"pennylane-lightning>=0.37",
"requests",
"typing_extensions",
"packaging",
Expand Down
3 changes: 0 additions & 3 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ def circuit(x: float):
result_header = "func.func private @circuit(%arg0: tensor<f64>) -> tensor<f64>"
assert result_header in mlir_str

@pytest.mark.xfail(reason="supported once catalyst #768 is merged")
def test_qjit_adjoint(self):
"""Test JIT compilation with adjoint support"""
dev = qml.device("lightning.qubit", wires=2)
Expand All @@ -273,7 +272,6 @@ def func():

assert jnp.allclose(workflow_cl(0.1, [1]), workflow_pl(0.1, [1]))

@pytest.mark.xfail(reason="supported once catalyst #768 is merged")
def test_qjit_adjoint_lazy(self):
"""Test that the lazy kwarg is supported."""
dev = qml.device("lightning.qubit", wires=2)
Expand Down Expand Up @@ -732,7 +730,6 @@ def f(x):
class TestCatalystSample:
"""Test qml.sample with Catalyst."""

@pytest.mark.xfail(reason="requires simultaneous catalyst pr")
def test_sample_measure(self):
"""Test that qml.sample can be used with catalyst.measure."""

Expand Down

0 comments on commit af5bd6d

Please sign in to comment.