Skip to content

Commit 7248c12

Browse files
author
Sergei Mironov
authored
Remove CPhase gate alias references (#718)
**Context:** Transition to the quantum device config schema 2 **Description of the Change:** * Remove mentions of CPhase "gate" which happens to be a Python alias for ControlledPhaseShift. * Remove the Python-only Projector patch because we already have a relaxed validation procedure for observables * Relax operation validation by allowing kokkos device to declare C(GlobalPhase) which is a Python-only operation. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** * PennyLaneAI/pennylane-lightning#642 - (related discussion) PennyLaneAI/pennylane-lightning#642 (comment)
1 parent 34db688 commit 7248c12

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

frontend/catalyst/device/qjit_device.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,16 @@ def validate_device_capabilities(
492492
if hasattr(device, "operations") and hasattr(device, "observables"):
493493
# For gates, we require strict match
494494
device_gates = filter_out_adjoint(set(device.operations))
495+
# Lightning-kokkis might support C(GlobalPhase) in Python, but not in C++. We remove this
496+
# gate before calling the validation.
497+
# See https://github.com/PennyLaneAI/pennylane-lightning/pull/642#discussion_r1535478642
498+
if device_name == "lightning.kokkos":
499+
device_gates = device_gates - {"C(GlobalPhase)"}
495500
spec_gates = filter_out_adjoint(set.union(native, matrix, decomposable))
496501
if device_gates != spec_gates:
497502
raise CompileError(
498-
"Gates in qml.device.operations and specification file do not match.\n"
503+
"Gates in qml.device.operations and specification file do not match for "
504+
f'"{device_name}".\n'
499505
f"Gates that present only in the device: {device_gates - spec_gates}\n"
500506
f"Gates that present only in spec: {spec_gates - device_gates}\n"
501507
)

frontend/catalyst/utils/toml.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,10 @@ def get_operation_properties(config_props: dict) -> OperationProperties:
260260

261261

262262
def patch_schema1_collections(
263-
config, device_name, native_gate_props, matrix_decomp_props, decomp_props, observable_props
263+
config, _device_name, native_gate_props, matrix_decomp_props, decomp_props
264264
): # pylint: disable=too-many-arguments, too-many-branches
265265
"""For old schema1 config files we deduce some information which was not explicitly encoded."""
266266

267-
# TODO: remove after PR #642 is merged in lightning
268-
# NOTE: we mark GlobalPhase as controllables even if `quantum_control` flag is False. This
269-
# is what actual device reports.
270-
if device_name == "lightning.kokkos": # pragma: nocover
271-
native_gate_props["GlobalPhase"] = OperationProperties(
272-
invertible=False, controllable=True, differentiable=True
273-
)
274-
275-
# TODO: remove after PR #642 is merged in lightning
276-
if device_name == "lightning.kokkos": # pragma: nocover
277-
observable_props["Projector"] = OperationProperties(
278-
invertible=False, controllable=False, differentiable=False
279-
)
280-
281267
# The deduction logic is the following:
282268
# * Most of the gates have their `C(Gate)` controlled counterparts.
283269
# * Some gates have to be decomposed if controlled version is used. Typically these are
@@ -414,7 +400,6 @@ def load_device_capabilities(
414400
native_gate_props,
415401
matrix_decomp_props,
416402
decomp_props,
417-
observable_props,
418403
)
419404

420405
return DeviceCapabilities(

frontend/test/pytest/test_custom_devices.py

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"PSWAP",
6161
"SISWAP",
6262
"SQISW",
63-
"CPhase",
6463
"BasisState",
6564
"QubitStateVector",
6665
"StatePrep",

runtime/lib/backend/dummy/dummy_device.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ CY = { properties = [ "invertible", "differentiable" ] }
1919
CZ = { properties = [ "invertible", "differentiable" ] }
2020
PhaseShift = { properties = [ "controllable", "invertible", "differentiable" ] }
2121
ControlledPhaseShift = { properties = [ "invertible", "differentiable" ] }
22-
CPhase = { properties = [ "invertible", "differentiable" ] }
2322
RX = { properties = [ "controllable", "invertible", "differentiable" ] }
2423
RY = { properties = [ "controllable", "invertible", "differentiable" ] }
2524
RZ = { properties = [ "controllable", "invertible", "differentiable" ] }

0 commit comments

Comments
 (0)