Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for C(BlockEncode) #743

Merged
merged 8 commits into from
Jun 3, 2024
Merged
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
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Add `cutensornet` backed `MPS` C++ layer to `lightning.tensor`.
[(#704)](https://github.com/PennyLaneAI/pennylane-lightning/pull/704)

* Add support for `C(BlockEncode)` to Lightning devices.
[(#743)](https://github.com/PennyLaneAI/pennylane-lightning/pull/743)

### Breaking changes

* Removed the `QuimbMPS` class and the corresponding interface/backend from `lightning.tensor`.
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.37.0-dev23"
__version__ = "0.37.0-dev24"
1 change: 1 addition & 0 deletions pennylane_lightning/lightning_gpu/lightning_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def _mebibytesToBytes(mebibytes):
"QFT",
"ECR",
"BlockEncode",
"C(BlockEncode)",
}

allowed_observables = {
Expand Down
4 changes: 2 additions & 2 deletions pennylane_lightning/lightning_gpu/lightning_gpu.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ MultiControlledX = {}
# Gates which should be translated to QubitUnitary
[operators.gates.matrix]


BlockEncode = {properties = [ "controllable" ]}
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
GlobalPhase = {properties = [ "controllable" ]}
ControlledQubitUnitary = {}
ECR = {}
SX = {}
Expand All @@ -70,7 +71,6 @@ OrbitalRotation = {}
QubitCarry = {}
QubitSum = {}
DiagonalQubitUnitary = {}
BlockEncode = {}

# Observables supported by the device
[operators.observables]
Expand Down
1 change: 1 addition & 0 deletions pennylane_lightning/lightning_kokkos/lightning_kokkos.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def _kokkos_configuration():
"QFT",
"ECR",
"BlockEncode",
"C(BlockEncode)",
}

allowed_observables = {
Expand Down
3 changes: 2 additions & 1 deletion pennylane_lightning/lightning_kokkos/lightning_kokkos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ StatePrep = {}
# Gates which should be translated to QubitUnitary
[operators.gates.matrix]

BlockEncode = {}
BlockEncode = {properties = [ "controllable" ]}
GlobalPhase = {properties = [ "controllable" ]}
DiagonalQubitUnitary = {}
ECR = {}
ISWAP = {}
Expand Down
1 change: 1 addition & 0 deletions pennylane_lightning/lightning_qubit/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def simulate_and_vjp(
"QFT",
"ECR",
"BlockEncode",
"C(BlockEncode)",
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
}
)
# The set of supported operations.
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/lightning_qubit/lightning_qubit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ QFT = {}
# Gates which should be translated to QubitUnitary
[operators.gates.matrix]

BlockEncode = {}
BlockEncode = {properties = [ "controllable" ]}
DiagonalQubitUnitary = {}
ECR = {}
ISWAP = {}
Expand Down
36 changes: 36 additions & 0 deletions tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,42 @@ def circuit():
assert np.allclose(res_sv, expected_sv, atol=tol, rtol=0)
assert np.allclose(res_probs, expected_prob, atol=tol, rtol=0)

# Check the BlockEncode PennyLane page for details:
# https://docs.pennylane.ai/en/stable/code/api/pennylane.BlockEncode.html
@pytest.mark.parametrize(
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
"op, op_wires",
[
[qml.BlockEncode, [0, 2]],
[qml.ctrl(qml.BlockEncode, control=(1)), [0, 2]],
[qml.ctrl(qml.BlockEncode, control=(2)), [0, 1]],
],
)
@pytest.mark.parametrize(
"A",
[
np.array([[1, 1], [1, -1]]) / np.sqrt(2),
np.array([[1, 1], [1, -1]]),
],
)
def test_apply_BlockEncode(self, op, op_wires, A, qubit_device, tol):
"""Test apply BlockEncode and C(BlockEncode)"""

num_wires = 3
dev = qubit_device(wires=num_wires)

def circuit1(A):
qml.Hadamard(0)
qml.Hadamard(1)
op(A, wires=op_wires)
return qml.state()

results = qml.qnode(dev)(circuit1)(A)

dev_default = qml.device("default.qubit", wires=num_wires)
expected = qml.qnode(dev_default)(circuit1)(A)

assert np.allclose(results, expected, atol=tol, rtol=0)


class TestApplyLightningMethod:
"""Unit tests for the apply_lightning method."""
Expand Down
Loading