Skip to content

Commit e95337d

Browse files
kipawaaJerryChen97
andauthored
qml -> qp in tests + matches (#2751)
**Context:** In order to reposition PennyLane and Catalyst for general quantum computing (rather than quantum machine learning) PennyLane will be imported as `qp` (rather than `qml`). These changes will be made per-module in Catalyst. **Description of the Change:** Update references to PennyLane in `tests`. **Benefits:** Improve user perception of the uses of PennyLane + Catalyst. **Possible Drawbacks:** **Related GitHub Issues:** [sc-117236] [sc-117694] --------- Co-authored-by: Yushao Chen (Jerry) <chenys13@outlook.com>
1 parent ac88573 commit e95337d

42 files changed

Lines changed: 1855 additions & 1855 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/catalyst/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@
9797
loop), and will raise a warning informing of the failure.
9898
9999
>>> @qjit(autograph=True)
100-
... @qml.qnode(dev)
100+
... @qp.qnode(dev)
101101
... def f():
102102
... x = ["0.1", "0.2", "0.3"]
103103
... for i in range(3):
104-
... qml.RX(float(x[i]), wires=i)
105-
... return qml.expval(qml.PauliZ(0))
104+
... qp.RX(float(x[i]), wires=i)
105+
... return qp.expval(qp.PauliZ(0))
106106
Warning: Tracing of an AutoGraph converted for loop failed with an exception:
107107
...
108108
If you intended for the conversion to happen, make sure that the (now dynamic)
@@ -114,12 +114,12 @@
114114
>>> catalyst.autograph_strict_conversion = False
115115
>>> catalyst.autograph_ignore_fallbacks = True
116116
>>> @qjit(autograph=True)
117-
... @qml.qnode(dev)
117+
... @qp.qnode(dev)
118118
... def f():
119119
... x = ["0.1", "0.2", "0.3"]
120120
... for i in range(3):
121-
... qml.RX(float(x[i]), wires=i)
122-
... return qml.expval(qml.PauliZ(0))
121+
... qp.RX(float(x[i]), wires=i)
122+
... return qp.expval(qp.PauliZ(0))
123123
>>> f()
124124
array(0.99500417)
125125
"""
@@ -136,14 +136,14 @@
136136
loop), and will automatically fallback to interpreting the control flow
137137
logic at compile-time via Python:
138138
139-
>>> dev = qml.device("lightning.qubit", wires=1)
139+
>>> dev = qp.device("lightning.qubit", wires=1)
140140
>>> @qjit(autograph=True)
141-
... @qml.qnode(dev)
141+
... @qp.qnode(dev)
142142
... def f():
143143
... params = ["0", "1", "2"]
144144
... for x in params:
145-
... qml.RY(int(x) * jnp.pi / 4, wires=0)
146-
... return qml.expval(qml.PauliZ(0))
145+
... qp.RY(int(x) * jnp.pi / 4, wires=0)
146+
... return qp.expval(qp.PauliZ(0))
147147
>>> f()
148148
array(-0.70710678)
149149
@@ -152,12 +152,12 @@
152152
153153
>>> catalyst.autograph_strict_conversion = True
154154
>>> @qjit(autograph=True)
155-
... @qml.qnode(dev)
155+
... @qp.qnode(dev)
156156
... def f():
157157
... params = ["0", "1", "2"]
158158
... for x in params:
159-
... qml.RY(int(x) * jnp.pi / 4, wires=0)
160-
... return qml.expval(qml.PauliZ(0))
159+
... qp.RY(int(x) * jnp.pi / 4, wires=0)
160+
... return qp.expval(qp.PauliZ(0))
161161
AutoGraphError: Could not convert the iteration target ['0', '1', '2'] to array
162162
while processing the following with AutoGraph:
163163
File "<ipython-input-44-dbae11e6d745>", line 7, in f

frontend/catalyst/api_extensions/differentiation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,10 @@ def _check_qnode_against_grad_method(f: QNode, method: str, jaxpr: Jaxpr):
908908
):
909909
raise DifferentiableCompileError(
910910
"The parameter-shift method can only be used for QNodes "
911-
"which return either qml.expval or qml.probs."
911+
"which return either qp.expval or qp.probs."
912912
)
913913

914914
if f.diff_method == "adjoint" and any(prim not in [expval_p] for prim in return_ops):
915915
raise DifferentiableCompileError(
916-
"The adjoint method can only be used for QNodes which return qml.expval."
916+
"The adjoint method can only be used for QNodes which return qp.expval."
917917
)

frontend/catalyst/api_extensions/quantum_operators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def circuit():
151151
"""
152152
EvaluationContext.check_is_tracing("catalyst.measure can only be used from within @qjit.")
153153
EvaluationContext.check_is_quantum_tracing(
154-
"catalyst.measure can only be used from within a qml.qnode."
154+
"catalyst.measure can only be used from within a qp.qnode."
155155
)
156156
cur_trace = EvaluationContext.get_current_trace()
157157
wires = list(wires) if isinstance(wires, (list, tuple)) else [wires]
@@ -408,7 +408,7 @@ def __init__(self, target, lazy):
408408
self.single_op = False
409409
self.instantiated = False
410410
else:
411-
raise ValueError(f"Expected a callable or a qml.Operator, not {target}")
411+
raise ValueError(f"Expected a callable or a qp.Operator, not {target}")
412412

413413
def __call__(self, *args, **kwargs):
414414
if self.single_op:
@@ -563,7 +563,7 @@ def __init__(self, target, control, control_values, work_wires, work_wire_type="
563563
self.single_op = False
564564
self.instantiated = False
565565
else:
566-
raise ValueError(f"Expected a callable or a qml.Operator, not {target}")
566+
raise ValueError(f"Expected a callable or a qp.Operator, not {target}")
567567

568568
def __call__(self, *args, **kwargs):
569569
if self.single_op:

frontend/catalyst/jax_primitives.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import jax
2626
import numpy as np
27-
import pennylane as qml
27+
import pennylane as qp
2828
from jax._src import core, source_info_util, util
2929
from jax._src.core import pytype_aval_mappings
3030
from jax._src.interpreters import partial_eval as pe
@@ -426,7 +426,7 @@ def my_circuit(angle: float):
426426
), "Decomposition rules with `qreg` do not require `num_params`."
427427

428428
if op_type is not None and not isinstance(op_type, str):
429-
if issubclass(op_type, qml.operation.Operation):
429+
if issubclass(op_type, qp.operation.Operation):
430430
op_type = op_type.__name__
431431
else:
432432
raise ValueError("op_type must be a string or a pennylane operator.")
@@ -586,12 +586,12 @@ def _quantum_kernel_lowering(ctx, *args, call_jaxpr, qnode, pipelines=None):
586586
Args:
587587
ctx: LoweringRuleContext
588588
*args: List[mlir.Value] corresponding to argument values
589-
qnode: qml.Qnode
589+
qnode: qp.Qnode
590590
call_jaxpr: jaxpr representing fn
591591
Returns:
592592
List[mlir.Value] corresponding
593593
"""
594-
assert isinstance(qnode, qml.QNode), "This function expects qnodes"
594+
assert isinstance(qnode, qp.QNode), "This function expects qnodes"
595595
pipelines = pipelines or ()
596596

597597
func_op = lower_callable(ctx, qnode, call_jaxpr, pipelines)
@@ -1988,7 +1988,7 @@ def custom_measurement_staging_rule(
19881988

19891989
shape = _merge_dyn_shape(static_shape, dynamic_shape)
19901990
if not dynamic_shape:
1991-
# Some PL transforms, like @qml.batch_params, do not support dynamic shapes yet
1991+
# Some PL transforms, like @qp.batch_params, do not support dynamic shapes yet
19921992
# Therefore we still keep static shapes when possible
19931993
# This can be removed, and all avals turned into DShapedArrays, when
19941994
# dynamic program capture in PL is complete

frontend/catalyst/jax_primitives_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import copy
1717
import functools
1818

19-
import pennylane as qml
19+
import pennylane as qp
2020
from jax._src import core, util
2121
from jax._src.lib.mlir import ir
2222
from jax.interpreters import mlir
@@ -37,7 +37,7 @@ def _all_expval(call_jaxpr: core.ClosedJaxpr) -> bool:
3737
return True
3838

3939

40-
def _calculate_diff_method(qn: qml.QNode, call_jaxpr: core.ClosedJaxpr):
40+
def _calculate_diff_method(qn: qp.QNode, call_jaxpr: core.ClosedJaxpr):
4141
diff_method = str(qn.diff_method)
4242
if diff_method != "best":
4343
return diff_method
@@ -78,7 +78,7 @@ def lower_jaxpr(ctx, jaxpr, metadata=None, fn=None):
7878
FuncOp
7979
"""
8080

81-
if fn is None or isinstance(fn, qml.QNode):
81+
if fn is None or isinstance(fn, qp.QNode):
8282
equation = get_call_equation(jaxpr)
8383
call_jaxpr = equation.params["call_jaxpr"]
8484
pipelines = equation.params.get("pipelines")
@@ -112,7 +112,7 @@ def lower_callable(ctx, callable_, call_jaxpr, pipelines=(), metadata=None):
112112
"""
113113
if pipelines is None:
114114
pipelines = tuple()
115-
if isinstance(callable_, qml.QNode):
115+
if isinstance(callable_, qp.QNode):
116116
return get_or_create_qnode_funcop(ctx, callable_, call_jaxpr, pipelines, metadata=metadata)
117117
return get_or_create_funcop(ctx, callable_, call_jaxpr, pipelines, metadata=metadata)
118118

@@ -182,7 +182,7 @@ def lower_callable_to_funcop(ctx, callable_, call_jaxpr):
182182

183183
func_op = mlir.lower_jaxpr_to_fun(**kwargs)
184184

185-
if isinstance(callable_, qml.QNode):
185+
if isinstance(callable_, qp.QNode):
186186
func_op.attributes["quantum.node"] = ir.UnitAttr.get()
187187

188188
diff_method = _calculate_diff_method(callable_, call_jaxpr)
@@ -210,7 +210,7 @@ def get_or_create_qnode_funcop(ctx, callable_, call_jaxpr, pipelines, metadata):
210210
211211
Args:
212212
ctx: LoweringRuleContext
213-
callable_: qml.Qnode
213+
callable_: qp.Qnode
214214
call_jaxpr: jaxpr representing callable_
215215
Returns:
216216
FuncOp
@@ -236,12 +236,12 @@ def lower_qnode_to_funcop(ctx, callable_, call_jaxpr, pipelines):
236236
237237
Args:
238238
ctx: LoweringRuleContext
239-
callable_: qml.Qnode
239+
callable_: qp.Qnode
240240
call_jaxpr: jaxpr representing callable_
241241
Returns:
242242
FuncOp
243243
"""
244-
assert isinstance(callable_, qml.QNode), "This function expects qnodes"
244+
assert isinstance(callable_, qp.QNode), "This function expects qnodes"
245245

246246
name = "module_" + callable_.__name__
247247
# pylint: disable-next=no-member

0 commit comments

Comments
 (0)