Skip to content

Add greedy scheduler solver backend#158

Open
masa10-f wants to merge 8 commits intomasterfrom
split/greedy-scheduling
Open

Add greedy scheduler solver backend#158
masa10-f wants to merge 8 commits intomasterfrom
split/greedy-scheduling

Conversation

@masa10-f
Copy link
Collaborator

@masa10-f masa10-f commented Jan 21, 2026

Before submitting, please check the following:

  • Make sure you have tests for the new code and that test passes (run pytest)
  • If applicable, add a line to the [unreleased] part of CHANGELOG.md, following keep-a-changelog.
  • Format added code by ruff
  • Type checking by mypy and pyright
  • Make sure the checks (github actions) pass.
  • Check that the docs compile without errors (run make html in ./docs/ - you may need to install dependency for sphinx docs, see docs/requirements.txt.)

Then, please fill in below:

Context (if applicable):

This PR adds greedy scheduling algorithms as a fast alternative to CP-SAT optimization for MBQC pattern scheduling.

Description of the change:

  • Add greedy_minimize_time() for minimal execution time scheduling
    • Separate strategies for unlimited and qubit-limited cases
    • ALAP (As-Late-As-Possible) preparation optimization to minimize active volume
    • Criticality-based prioritization for preparation candidates
    • Slack-filling mechanism for efficient qubit utilization
  • Add greedy_minimize_space() for minimal qubit usage scheduling
  • Add comprehensive tests for the greedy scheduling algorithms

Related issue:

None

masa10-f and others added 3 commits December 25, 2025 14:33
- Add alap_prepare_times() for As-Late-As-Possible preparation scheduling
- Refactor greedy_minimize_time() with separate strategies for unlimited
  and qubit-limited cases
- Add criticality-based prioritization and slack-filling for qubit-limited
  scheduling
- Add tests for ALAP optimization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@masa10-f masa10-f changed the title Add greedy scheduler with ALAP optimization Add greedy scheduler solver backend Jan 21, 2026
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 81.65138% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.39%. Comparing base (ad07ddf) to head (05a9543).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #158      +/-   ##
==========================================
- Coverage   83.65%   83.39%   -0.26%     
==========================================
  Files          21       22       +1     
  Lines        2313     2530     +217     
  Branches      416      469      +53     
==========================================
+ Hits         1935     2110     +175     
- Misses        287      319      +32     
- Partials       91      101      +10     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce4fcb1465

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

masa10-f and others added 2 commits January 21, 2026 17:55
Previously, greedy_minimize_space only prepared neighbors of the measured
node, not the node itself. This caused a KeyError when a non-input node
with no DAG dependencies had all input neighbors (already prepared).

The fix ensures non-input nodes are prepared before measurement by:
- Adding the node itself to the preparation set when needed
- Updating _calc_activate_cost to account for self-preparation cost

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@masa10-f masa10-f requested a review from d1ssk January 21, 2026 09:19
@masa10-f
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05a95430bc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +448 to +450
current_time = meas_time + 1

return prepare_time, measure_time

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Assign prep times for output-only nodes

greedy_minimize_space only records preparation times when a node is needed to measure a non-output node. If the graph contains output nodes that are never neighbors of any measured node (e.g., an isolated output or outputs connected only to other outputs), the loop exits and returns without ever adding those outputs to prepare_time. Downstream, Scheduler.solve_schedule will fill those nodes with None and Scheduler._validate_all_nodes_scheduled will reject the schedule; more importantly, the returned schedule leaves those output qubits unprepared. Consider a final pass (similar to ALAP in greedy_minimize_time) to assign preparation times for any remaining non-input nodes.

Useful? React with 👍 / 👎.

# Since dag is {parent: children}, nodes with empty children come first (leaves).
# This is the correct order for computing criticality (leaves before roots).
try:
topo_order = list(TopologicalSorter(dag).static_order())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In _greedy_minimize_time_unlimited, TopologicalSorter takes inv_dag. If the usage is the same here as well, it would be better to rename the parameter accordingly.

unmeasured = graph.physical_nodes - graph.output_node_indices.keys()

try:
topo_order = list(TopologicalSorter(dag).static_order())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants