diff --git a/qadence/backends/pyqtorch/convert_ops.py b/qadence/backends/pyqtorch/convert_ops.py index ca79e93e4..ebb74dfea 100644 --- a/qadence/backends/pyqtorch/convert_ops.py +++ b/qadence/backends/pyqtorch/convert_ops.py @@ -26,6 +26,7 @@ from torch import dtype as torch_dtype from torch.nn import Module +from qadence import stringify from qadence.backends.utils import ( finitediff, pyqify, @@ -47,7 +48,7 @@ block_to_tensor, ) from qadence.blocks.primitive import ProjectorBlock -from qadence.blocks.utils import parameters +from qadence.blocks.utils import parameters, uuid_to_expression from qadence.operations import ( U, multi_qubit_gateset, @@ -315,6 +316,13 @@ def forward( state: Tensor, values: dict[str, Tensor], ) -> Tensor: + # convert values dict keys from uuids to expression strings if needed + uuid_dict = uuid_to_expression(self.block.generator) # type: ignore [arg-type] + if list(uuid_dict.keys())[0] in values: + orig_param_values = values["orig_param_values"] + values = {stringify(v): values[k] for k, v in uuid_dict.items()} + values["orig_param_values"] = orig_param_values + if getattr(self.block.generator, "is_time_dependent", False): # type: ignore [union-attr] def Ht(t: Tensor | float) -> Tensor: diff --git a/qadence/blocks/embedding.py b/qadence/blocks/embedding.py index 8daea4f08..088e71892 100644 --- a/qadence/blocks/embedding.py +++ b/qadence/blocks/embedding.py @@ -140,6 +140,7 @@ def embedding_fn(params: ParamDictType, inputs: ParamDictType) -> ParamDictType: gate_lvl_params: ParamDictType = {} for uuid, e in uuid_to_expr.items(): gate_lvl_params[uuid] = embedded_params[e] + gate_lvl_params.update({"orig_param_values": inputs}) return gate_lvl_params else: out = {stringify(k): v for k, v in embedded_params.items()}