- 
                Notifications
    
You must be signed in to change notification settings  - Fork 707
 
[Decomposition] Register work-wire usage of decomposition rules #7861
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
      
      
    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
    
  
  
    
    
              
                    astralcai
  
              
              commented
              
                  
                    Jul 11, 2025 
                  
              
              
            
            
              
                    astralcai
  
              
              commented
              
                  
                    Jul 17, 2025 
                  
              
              
            
            
          Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@            Coverage Diff             @@
##           master    #7861      +/-   ##
==========================================
- Coverage   99.68%   99.68%   -0.01%     
==========================================
  Files         542      542              
  Lines       55628    55648      +20     
==========================================
+ Hits        55455    55474      +19     
- Misses        173      174       +1     ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
  | 
    
              
                    isaacdevlugt
  
              
              requested changes
              
                  
                    Jul 21, 2025 
                  
              
              
            
            
              
                    mudit2812
  
              
              reviewed
              
                  
                    Jul 21, 2025 
                  
              
              
            
            
Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]> Co-authored-by: Isaac De Vlugt <[email protected]>
              
                    mudit2812
  
              
              approved these changes
              
                  
                    Jul 21, 2025 
                  
              
              
            
            
…o register-work-wire
…o register-work-wire
Co-authored-by: Isaac De Vlugt <[email protected]>
              
                    albi3ro
  
              
              approved these changes
              
                  
                    Jul 25, 2025 
                  
              
              
            
            
              
                    isaacdevlugt
  
              
              approved these changes
              
                  
                    Jul 25, 2025 
                  
              
              
            
            
    
  github-merge-queue bot
      pushed a commit
      that referenced
      this pull request
    
      Aug 15, 2025 
    
    
      
  
    
      
    
  
**Context:** This is a follow-up to #7861, updating the decomposition graph so that it can be solved under a maximum number of work wires constraint. **Assumptions** - The same number of work wires is available to every operator at the top level of the circuit. - All work wires will be allocated from this initial pool of wires, no borrowing algorithmic wires (whatever that means) or reallocation of wires not yet deallocated. - If a decomposition rule requests work wires, these wires are kept until the end of the decomposition. Even if the decomposition rule deallocates these wires early in its internal implementation, since there is currently no way to specify this, we must assume that these wires cannot be used in further decompositions of operators within. **Algorithm** Before dynamic wire allocation, work wires are specified as an operator property, and included in an operator's resource params. Two operators with different work wire budgets (I use the term work wire budget to mean how many work wires is available for the decomposition of an operator) are stored as two separate nodes in the graph. With dynamic wire allocation, the number of available work wires is no longer an operator property, so two operators with different work wire budgets will have identical resource representations. Therefore, we cannot use `CompressedResourceOp` as graph nodes anymore, because it's now missing a crucial piece of information. The first step is to define a `_OperatorNode` class, which contains both the `CompressedResourceOp` and the number of available work wires (previously a part of the `CompressedResourceOp`), and use this as nodes in the graph. The number of work wires available to each operator is tracked during the graph construction process. Imagine passing a `work_wires` argument to every operator at the top level of the circuit, and each decomposition takes the wires that it needs, and pass the rest of the work wires to every op within. **Optimizations** There are a few inefficiencies with this approach: 1. The graph must be constructed with a maximum work wire budget. If it changes, the entire graph must be reconstructed with a new work wire budget. **Solution**: throughout the graph, we track not the number of work wires available to an operator, but the number of work wires NOT available to an operator. The top level operators all have `num_work_wires_not_available=0`, indicating that they have access to all the available work wires. If a decomposition of a top level operator uses 2 work wires, then all operators produced from this decomposition has `num_work_wires_not_available=2`. This allows the graph to be constructed once and solved multiple times with different work wire budgets. 2. The number of nodes in the graph grows significantly. Imagine every operator now comes with a `work_wires` property. Sometimes, two operators with different work wire budgets do not necessarily need to be two separate nodes in the graph. For example, an `RX` with 1 work wire available and an `RX` with 2 work wires available should not be two separate nodes. **Solution**: during graph construction, we track not only the number of work wires available, but also whether any decomposition rules of an operator, or any operator produced from any of the decompositions, depend on work wires. Since the graph construction is recursive and depth-first, when we first encounter an operator, and build the sub-graph with all of its decompositions, we label this operator node as either work-wire dependent or not. The next time we encounter the same operator with a different work wire budget, we create a new node for this operator only if this operator was previously marked as work-wire dependent. This significantly reduces the number of nodes. **Related GitHub Issues:** [sc-94400] --------- Co-authored-by: Isaac De Vlugt <[email protected]> Co-authored-by: Mudit Pandey <[email protected]>
  
    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.
  
    
  
    
Context:
With dynamic qubit allocation, whether a decomposition rule can be performed may depend on whether there is enough work wires available. The number of work wires that a decomposition rule uses should be registered as a resource requirement.
Description of the Change:
Implements arequire_work_wiresdecorator to be applied on decomposition rules to declare the number of work wires that this decomposition rule intends to use.Adds a
work_wiresargument toregister_resources.Benefits:
Possible Drawbacks:
Related GitHub Issues:
[sc-94399]