Skip to content

Commit

Permalink
feat: don't add children costs during compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
mstechly committed Jun 14, 2024
1 parent ee5b6e7 commit 430b598
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 13 additions & 1 deletion src/bartiq/compilation/_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
from typing import Any, Optional, cast, overload

from .. import Port, Routine
Expand Down Expand Up @@ -97,7 +98,10 @@ def _compile_routine(

compiled_routine_with_funcs = _compile_routine_with_functions(routine_with_functions, functions_map, backend)
compiled_routine_with_funcs.name = root_name
return compiled_routine_with_funcs.to_routine()

compiled_routine = compiled_routine_with_funcs.to_routine()
compiled_routine = _remove_children_costs(compiled_routine)
return compiled_routine


def _add_function_to_routine(
Expand Down Expand Up @@ -674,3 +678,11 @@ def _split_local_path(path: str) -> tuple[str, str]:
"""Split path into parent path and local name, much like directory path and a file name."""
*parent_path, name = path.rsplit(".", 1)
return ("" if parent_path == [] else parent_path[0]), name


def _remove_children_costs(routine: Routine) -> Routine:
for subroutine in routine.walk():
for resource in copy.copy(subroutine.resources):
if "." in resource:
del subroutine.resources[resource]
return routine
10 changes: 1 addition & 9 deletions tests/compilation/data/compile_test_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
type: other
value: {type: str, value: x + y}
input_params: [x, y]
# Children with independent resources, unlinked params, no ports
# Children with independent resources, unlinked params, no ports
- - name: root
type: null
children:
Expand Down Expand Up @@ -68,14 +68,6 @@
value: {type: str, value: x + y}
input_params: [x, y]
resources:
a.z:
name: a.z
type: other
value: {type: str, value: a.x + a.y}
b.z:
name: b.z
type: other
value: {type: str, value: b.x + b.y}
z:
name: z
type: other
Expand Down

0 comments on commit 430b598

Please sign in to comment.