Skip to content

Commit

Permalink
Merge branch 'master' into sc-62116-support-large-runners
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmr authored Apr 29, 2024
2 parents 03e89e2 + 05a98ae commit 2bdf4b2
Show file tree
Hide file tree
Showing 11 changed files with 646 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### New features since last release

* Add Python class for the `lightning.tensor` device which uses the new device API and the interface for `quimb` based on the MPS method.
[(#671)](https://github.com/PennyLaneAI/pennylane-lightning/pull/671)

* Add compile-time support for AVX2/512 streaming operations in `lightning.qubit`.
[(#664)](https://github.com/PennyLaneAI/pennylane-lightning/pull/664)

Expand Down Expand Up @@ -129,11 +132,14 @@
* Update the version of `codecov-action` to v4 and fix the CodeCov issue with the PL-Lightning check-compatibility actions.
[(#682)](https://github.com/PennyLaneAI/pennylane-lightning/pull/682)

* Increase tolerance for a flaky test.
[(#703)](https://github.com/PennyLaneAI/pennylane-lightning/pull/703)

### Contributors

This release contains contributions from (in alphabetical order):

Ali Asadi, Amintor Dusko, Christina Lee, Vincent Michaud-Rioux, Lee James O'Riordan, Mudit Pandey, Shuli Shu
Ali Asadi, Amintor Dusko, Pietropaolo Frisoni, Christina Lee, Vincent Michaud-Rioux, Lee James O'Riordan, Mudit Pandey, Shuli Shu

---

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests_linux_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
strategy:
matrix:
pl_backend: ["lightning_qubit"]
timeout-minutes: 60
timeout-minutes: 75
name: Python tests
runs-on: ${{ needs.determine_runner.outputs.runner_group }}

Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
strategy:
matrix:
pl_backend: ["lightning_qubit"]
timeout-minutes: 60
timeout-minutes: 75
name: Python tests with OpenBLAS
runs-on: ${{ needs.determine_runner.outputs.runner_group }}

Expand Down Expand Up @@ -265,7 +265,7 @@ jobs:
exclude:
- pl_backend: ["all"]
exec_model: OPENMP
timeout-minutes: 60
timeout-minutes: 75
name: Python tests with Kokkos
runs-on: ${{ needs.determine_runner.outputs.runner_group }}

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.36.0-dev44"
__version__ = "0.36.0-dev45"
18 changes: 18 additions & 0 deletions pennylane_lightning/lightning_tensor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""PennyLane lightning_tensor package."""

from pennylane_lightning.core import __version__

from .lightning_tensor import LightningTensor
100 changes: 100 additions & 0 deletions pennylane_lightning/lightning_tensor/backends/quimb/_mps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Class implementation for the Quimb MPS interface for simulating quantum circuits while keeping the state always in MPS form.
"""

import numpy as np
import pennylane as qml
import quimb.tensor as qtn
from pennylane.wires import Wires

_operations = frozenset({}) # pragma: no cover
# The set of supported operations.

_observables = frozenset({}) # pragma: no cover
# The set of supported observables.


def stopping_condition(op: qml.operation.Operator) -> bool:
"""A function that determines if an operation is supported by ``lightning.tensor`` for this interface."""
return op.name in _operations # pragma: no cover


def accepted_observables(obs: qml.operation.Operator) -> bool:
"""A function that determines if an observable is supported by ``lightning.tensor`` for this interface."""
return obs.name in _observables # pragma: no cover


class QuimbMPS:
"""Quimb MPS class.
Used internally by the `LightningTensor` device.
Interfaces with `quimb` for MPS manipulation, and provides methods to execute quantum circuits.
Args:
num_wires (int): the number of wires in the circuit.
interf_opts (dict): dictionary containing the interface options.
dtype (np.dtype): the complex type used for the MPS.
"""

def __init__(self, num_wires, interf_opts, dtype=np.complex128):

if dtype not in [np.complex64, np.complex128]: # pragma: no cover
raise TypeError(f"Unsupported complex type: {dtype}")

self._wires = Wires(range(num_wires))
self._dtype = dtype

self._init_state_ops = {
"binary": "0" * max(1, len(self._wires)),
"dtype": self._dtype.__name__,
"tags": [str(l) for l in self._wires.labels],
}

self._gate_opts = {
"contract": "swap+split",
"parametrize": None,
"cutoff": interf_opts["cutoff"],
"max_bond": interf_opts["max_bond_dim"],
}

self._expval_opts = {
"dtype": self._dtype.__name__,
"simplify_sequence": "ADCRS",
"simplify_atol": 0.0,
}

self._circuitMPS = qtn.CircuitMPS(psi0=self._initial_mps())

@property
def state(self):
"""Current MPS handled by the interface."""
return self._circuitMPS.psi

def state_to_array(self) -> np.ndarray:
"""Contract the MPS into a dense array."""
return self._circuitMPS.to_dense()

def _initial_mps(self) -> qtn.MatrixProductState:
r"""
Returns an initial state to :math:`\ket{0}`.
Internally, it uses `quimb`'s `MPS_computational_state` method.
Returns:
MatrixProductState: The initial MPS of a circuit.
"""

return qtn.MPS_computational_state(**self._init_state_ops)
Loading

0 comments on commit 2bdf4b2

Please sign in to comment.