Skip to content

Commit

Permalink
fix: don't add children costs during compilation (#68)
Browse files Browse the repository at this point in the history
* fix: don't add children costs during compilation

* Update src/bartiq/compilation/_compile.py

Co-authored-by: Konrad Jałowiecki <[email protected]>

* style: remove unnecessary import

---------

Co-authored-by: Konrad Jałowiecki <[email protected]>
  • Loading branch information
mstechly and dexter2206 authored Jun 14, 2024
1 parent ee5b6e7 commit 1ad361f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/bartiq/compilation/_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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 +677,9 @@ 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():
subroutine.resources = {name: res for name, res in subroutine.resources.items() if "." not in name}
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 1ad361f

Please sign in to comment.