Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't add children costs during compilation #68

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
mstechly marked this conversation as resolved.
Show resolved Hide resolved
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
Loading