-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add support for first-pass resources #277
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e6c57ef to
ff79479
Compare
mstechly
approved these changes
Nov 27, 2025
src/bartiq/_routine.py
Outdated
| children = {child.name: cls.from_qref(child, backend) for child in program.children} | ||
| other_data = _common_routine_dict_from_qref(qref_obj, backend) | ||
|
|
||
| usual_resources = {} |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] I'd call it regular_resources or standard_resources.
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your wish has been granted in f4ca54b
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Programs created using our internal tools sometimes include routines whose resources should only be counted once, a.k.a. as first-pass only routines. However, those are not easily representable in QREF, and, therefore, cannot be correctly processed in Bartiq, leading to vast overcounts of resources. This PR deals with this issues. To this end I introduced the following changes:
RoutineandCompiledRoutineto capture necessary information for processing first-pass resources.The details of how everything works are below.
High-level overview
To tackle the problem, we allow marking some uncompiled routines as being first-pass only. When a routine is marked in this way, it tells the compilation engine that if this particular routine is repeated, then it should only contribute to the resources once. For instance, consider routine A, with children B and C, with an additive resource
x. Suppose that B is marked as first-pass only, C is not marked as first-pass only, and A is repeated 10 times (using constant repetition). Then A.x would be equal to 10 * C.x + A.x (as oppose to 10 * C.x + !0 * A.x).However, this is not enough, as one has to take into account the whole hierarchy of the program. For instance, if A has child B with child C that has a first-pass child D, and A is repeated 10 times, we have to somehow know that part of resources in
Care actually coming from a first-pass child. Note that this is only necessary for compiled routines. To this end, we also store "first-pass resources" in any given routine that requires it. Those resources propagate during compilation, and are also correctly combined in case there are sourced from multiple subroutines.Changes to
RoutineandCompiledRoutinefirst_pass_onlyflag to both routine types.first_pass_resourcesfield toCompiledroutineChanges to compilation engine
The largest part of the compilation engine remain unchanged, except the following:
xresource be 5, and corresponding first pass value be 2. Then, instead of computing the total value of x as 10 * 5, we compute it as 10 * (5 - 2) + 2.Boy-scout changes
Please verify that you have completed the following steps