From 295ce3247b65d36cb19fadf532d99d78d61ea52a Mon Sep 17 00:00:00 2001 From: Sitong Liu <57391558+sitong1011@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:56:31 -0700 Subject: [PATCH] fix: correctly passing local variables when converting qref_v1 object to bartiq routine This PR modifies the _routine_v1_to_bartiq_routine function to ensure that local variables are correctly passed and included when converting qref to bartiq routine. --- src/bartiq/integrations/qref.py | 1 + tests/integrations/test_qref_integration.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/bartiq/integrations/qref.py b/src/bartiq/integrations/qref.py index a975990..9d50aa0 100644 --- a/src/bartiq/integrations/qref.py +++ b/src/bartiq/integrations/qref.py @@ -91,6 +91,7 @@ def _routine_v1_to_bartiq_routine(routine_v1) -> Routine: type=routine_v1.type, ports={port.name: port.model_dump() for port in routine_v1.ports}, resources={resource.name: resource.model_dump() for resource in routine_v1.resources}, + local_variables=routine_v1.local_variables, connections=[connection.model_dump() for connection in routine_v1.connections], input_params=routine_v1.input_params, linked_params={ diff --git a/tests/integrations/test_qref_integration.py b/tests/integrations/test_qref_integration.py index e8cdcbc..a45b022 100644 --- a/tests/integrations/test_qref_integration.py +++ b/tests/integrations/test_qref_integration.py @@ -45,6 +45,10 @@ def example_routine(): "name": "foo", "type": None, "input_params": ["M"], + "local_variables": [ + "R=ceiling(log_2(M))", + ], + "resources": {"T_gates": {"name": "T_gates", "type": "additive", "value": "R ** 2"}}, "ports": { "in_0": {"name": "in_0", "size": "M", "direction": "input"}, "out_0": {"name": "out_0", "size": 3, "direction": "output"}, @@ -93,6 +97,10 @@ def example_serialized_qref_v1_object(): {"name": "out_0", "direction": "output", "size": 3}, ], "input_params": ["M"], + "local_variables": [ + "R=ceiling(log_2(M))", + ], + "resources": [{"name": "T_gates", "type": "additive", "value": "R ** 2"}], }, ], "type": None,