Skip to content

Commit 833ace5

Browse files
authored
Merge 322d80b into c7de986
2 parents c7de986 + 322d80b commit 833ace5

28 files changed

+45
-2800
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v2
1818

1919
- name: Install dependencies
20-
run: sudo apt-get -y -q install cmake gcc libeigen3-dev
20+
run: sudo apt-get -y -q install cmake gcc
2121

2222
- name: Install Google Test
2323
run: |
@@ -50,7 +50,7 @@ jobs:
5050
python-version: '3.7'
5151

5252
- name: Install dependencies
53-
run: sudo apt-get -y -q install cmake gcc libeigen3-dev
53+
run: sudo apt-get -y -q install cmake gcc
5454

5555
- name: Get required Python packages
5656
run: |

.github/workflows/deploy.yml

+1-27
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,11 @@ on:
66
env:
77
CIBW_SKIP: "cp27-* cp34-* cp35-* *i686 pp* *win32"
88

9-
# Linux specific build settings
10-
11-
CIBW_BEFORE_ALL_LINUX: |
12-
curl -OsL https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz
13-
tar xzf eigen-3.3.7.tar.gz eigen-3.3.7/Eigen --strip-components 1
14-
tar xzf eigen-3.3.7.tar.gz eigen-3.3.7/unsupported --strip-components 1
15-
mkdir -p {project}/include
16-
cp -rf Eigen {project}/include
17-
cp -rf unsupported {project}/include
18-
199
# MacOS specific build settings
2010

2111
CIBW_BEFORE_ALL_MACOS: |
2212
brew cask uninstall --force oclint
23-
brew install gcc eigen libomp
24-
25-
CIBW_ENVIRONMENT_MACOS: EIGEN_INCLUDE_DIR=/usr/local/Cellar/eigen/3.3.7/include/eigen3
26-
27-
# Windows specific build settings
28-
29-
CIBW_ENVIRONMENT_WINDOWS: EIGEN_INCLUDE_DIR="C:\\eigen-3.3.7\\"
13+
brew install gcc libomp
3014
3115
# Python build settings
3216

@@ -68,16 +52,6 @@ jobs:
6852
python -m pip install --upgrade pip
6953
python -m pip install cibuildwheel==1.5.5
7054
71-
- name: Install Eigen on Windows
72-
if: runner.os == 'Windows'
73-
shell: powershell
74-
env:
75-
GIT_REDIRECT_STDERR: "2>&1"
76-
run: |
77-
choco install vcpython27 -f -y
78-
Invoke-WebRequest -Uri "https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip" -UseBasicParsing -OutFile C:\eigen3.zip
79-
& "C:\\Program Files\\7-Zip\\7z.exe" x C:\eigen3.zip -o"C:\" -y
80-
8155
- name: Build wheels
8256
run: |
8357
python -m cibuildwheel --output-dir wheelhouse

.github/workflows/wheels.yml

+1-27
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,11 @@ on:
88
env:
99
CIBW_SKIP: "cp27-* cp34-* cp35-* *i686 pp* *win32"
1010

11-
# Linux specific build settings
12-
13-
CIBW_BEFORE_ALL_LINUX: |
14-
curl -OsL https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz
15-
tar xzf eigen-3.3.7.tar.gz eigen-3.3.7/Eigen --strip-components 1
16-
tar xzf eigen-3.3.7.tar.gz eigen-3.3.7/unsupported --strip-components 1
17-
mkdir -p {project}/include
18-
cp -rf Eigen {project}/include
19-
cp -rf unsupported {project}/include
20-
2111
# MacOS specific build settings
2212

2313
CIBW_BEFORE_ALL_MACOS: |
2414
brew cask uninstall --force oclint
25-
brew install gcc eigen libomp
26-
27-
CIBW_ENVIRONMENT_MACOS: EIGEN_INCLUDE_DIR=/usr/local/Cellar/eigen/3.3.7/include/eigen3
28-
29-
# Windows specific build settings
30-
31-
CIBW_ENVIRONMENT_WINDOWS: EIGEN_INCLUDE_DIR="C:\\eigen-3.3.7\\"
15+
brew install gcc libomp
3216
3317
# Python build settings
3418

@@ -72,16 +56,6 @@ jobs:
7256
python -m pip install --upgrade pip
7357
python -m pip install cibuildwheel==1.5.5
7458
75-
- name: Install Eigen on Windows
76-
if: runner.os == 'Windows'
77-
shell: powershell
78-
env:
79-
GIT_REDIRECT_STDERR: "2>&1"
80-
run: |
81-
choco install vcpython27 -f -y
82-
Invoke-WebRequest -Uri "https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip" -UseBasicParsing -OutFile C:\eigen3.zip
83-
& "C:\\Program Files\\7-Zip\\7z.exe" x C:\eigen3.zip -o"C:\" -y
84-
8559
- name: Build wheels
8660
run: |
8761
python -m cibuildwheel --output-dir wheelhouse

CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@
66

77
### Improvements
88

9-
* Add new lightweight backend with performance improvements
9+
* Add new lightweight backend with performance improvements.
1010
[(#57)](https://github.com/PennyLaneAI/pennylane-lightning/pull/57)
1111

12+
* Remove the previous Eigen-based backend.
13+
[(#67)](https://github.com/PennyLaneAI/pennylane-lightning/pull/67)
14+
1215
### Documentation
1316

1417
### Bug fixes
1518

16-
* Re-add dispatch table after fixing static initialisation order issue
19+
* Re-add dispatch table after fixing static initialisation order issue.
1720
[(#68)](https://github.com/PennyLaneAI/pennylane-lightning/pull/68)
1821

1922
### Contributors
2023

2124
This release contains contributions from (in alphabetical order):
2225

23-
Thomas Loke
26+
Thomas Bromley, Christina Lee, Thomas Loke, Antal Száva.
2427

2528
---
2629

README.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PennyLane-Lightning Plugin
2727

2828
.. header-start-inclusion-marker-do-not-remove
2929
30-
The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++ using `Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_.
30+
The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++.
3131

3232
`PennyLane <https://pennylane.readthedocs.io>`_ is a cross-platform Python library for quantum machine
3333
learning, automatic differentiation, and optimization of hybrid quantum-classical computations.
@@ -65,15 +65,14 @@ Note that subsequent calls to ``pip install -e .`` will use cached binaries stor
6565
The following dependencies are required to install PennyLane-Lightning:
6666

6767
* A C++ compiler, such as ``g++``, ``clang``, or ``MSVC``.
68-
* `Eigen3 <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ - a C++ header library for linear algebra.
6968
* `pybind11 <https://pybind11.readthedocs.io/en/stable/>`_ a library for binding C++
7069
functionality to Python.
7170

7271
On Debian-based systems, these can be installed via ``apt`` and ``pip``:
7372

7473
.. code-block:: console
7574
76-
$ sudo apt install g++ libeigen3-dev
75+
$ sudo apt install g++
7776
$ pip install pybind11
7877
7978
Testing

doc/devices.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Lightning Qubit device
22
======================
33

44
The ``lightning.qubit`` device is an extension of PennyLane's built-in ``default.qubit`` device.
5-
It uses the C++ `Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`__ library to
5+
It uses a custom-built backend to
66
perform fast linear algebra calculations for simulating quantum state-vector evolution.
77

88
A ``lightning.qubit`` device can be loaded using:

lightning_benchmark.ipynb

-362
This file was deleted.

pennylane_lightning/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515

1616
from ._version import __version__
1717
from .lightning_qubit import LightningQubit
18-
from .lightning_qubit_new import LightningQubitNew

pennylane_lightning/lightning_benchmark.py

-46
This file was deleted.

pennylane_lightning/lightning_qubit.py

+12-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 Xanadu Quantum Technologies Inc.
1+
# Copyright 2021 Xanadu Quantum Technologies Inc.
22

33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -15,12 +15,10 @@
1515
This module contains the :class:`~.LightningQubit` class, a PennyLane simulator device that
1616
interfaces with C++ for fast linear algebra calculations.
1717
"""
18-
import warnings
19-
2018
from pennylane.devices import DefaultQubit
2119
from .lightning_qubit_ops import apply
2220
import numpy as np
23-
from pennylane import QubitStateVector, BasisState, DeviceError
21+
from pennylane import QubitStateVector, BasisState, DeviceError, QubitUnitary
2422

2523
from ._version import __version__
2624

@@ -29,17 +27,11 @@ class LightningQubit(DefaultQubit):
2927
"""PennyLane Lightning device.
3028
3129
An extension of PennyLane's built-in ``default.qubit`` device that interfaces with C++ to
32-
perform fast linear algebra calculations using the
33-
`Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`__ library.
30+
perform fast linear algebra calculations.
3431
3532
Use of this device requires pre-built binaries or compilation from source. Check out the
3633
:doc:`/installation` guide for more details.
3734
38-
.. warning::
39-
40-
The C++ interface currently supports up to 50 wires. If Lightning Qubit is loaded with
41-
more than 50 wires, it will revert to a NumPy-based simulation.
42-
4335
Args:
4436
wires (int): the number of wires to initialize the device with
4537
shots (int): How many times the circuit should be evaluated (or sampled) to estimate
@@ -82,21 +74,11 @@ class LightningQubit(DefaultQubit):
8274
"CRot",
8375
}
8476

85-
observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Identity"}
86-
87-
_MAX_WIRES = 50
88-
"""Maximum number of supported wires. Beyond this number, lightning.qubit behaves like
89-
default.qubit."""
77+
observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Hermitian", "Identity"}
9078

9179
def __init__(self, wires, *, shots=1000, analytic=True):
9280
super().__init__(wires, shots=shots, analytic=analytic)
9381

94-
if self.num_wires > self._MAX_WIRES:
95-
warnings.warn(
96-
f"The number of wires exceeds {self._MAX_WIRES}, reverting to NumPy-based evaluation.",
97-
UserWarning,
98-
)
99-
10082
@classmethod
10183
def capabilities(cls):
10284
capabilities = super().capabilities().copy()
@@ -112,14 +94,10 @@ def capabilities(cls):
11294

11395
def apply(self, operations, rotations=None, **kwargs):
11496

115-
if self.num_wires > self._MAX_WIRES:
116-
super().apply(operations, rotations=rotations, **kwargs)
117-
return
118-
11997
# State preparation is currently done in Python
12098
if operations: # make sure operations[0] exists
12199
if isinstance(operations[0], QubitStateVector):
122-
self._apply_state_vector(operations[0].parameters[0], operations[0].wires)
100+
self._apply_state_vector(operations[0].parameters[0].copy(), operations[0].wires)
123101
del operations[0]
124102
elif isinstance(operations[0], BasisState):
125103
self._apply_basis_state(operations[0].parameters[0], operations[0].wires)
@@ -138,7 +116,10 @@ def apply(self, operations, rotations=None, **kwargs):
138116
self._pre_rotated_state = self._state
139117

140118
if rotations:
141-
self._state = self.apply_lightning(self._pre_rotated_state, rotations)
119+
if any(isinstance(r, QubitUnitary) for r in rotations):
120+
super().apply(operations=[], rotations=rotations)
121+
else:
122+
self._state = self.apply_lightning(np.copy(self._pre_rotated_state), rotations)
142123
else:
143124
self._state = self._pre_rotated_state
144125

@@ -156,6 +137,6 @@ def apply_lightning(self, state, operations):
156137
op_wires = [self.wires.indices(o.wires) for o in operations]
157138
op_param = [o.parameters for o in operations]
158139

159-
state_vector = np.ravel(state, order="F")
160-
state_vector_updated = apply(state_vector, op_names, op_wires, op_param, self.num_wires)
161-
return np.reshape(state_vector_updated, state.shape, order="F")
140+
state_vector = np.ravel(state)
141+
apply(state_vector, op_names, op_wires, op_param, self.num_wires)
142+
return np.reshape(state_vector, state.shape)

0 commit comments

Comments
 (0)