Skip to content

Commit

Permalink
Fixed bug when using time-dependent block with convenience function run
Browse files Browse the repository at this point in the history
  • Loading branch information
vytautas-a committed Jun 28, 2024
1 parent 774e4d9 commit 4863f37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion qadence/backends/pyqtorch/convert_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions qadence/blocks/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down

0 comments on commit 4863f37

Please sign in to comment.