-
Notifications
You must be signed in to change notification settings - Fork 1
Add TICK command and edge scheduler for temporal scheduling #126
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
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
f190ce9
add TICK command
masa10-f 538212c
update docs of command
masa10-f 731d596
update pattern
masa10-f 15ecc44
add edge scheduler
masa10-f 0a53f6d
fix ruff
masa10-f 779d342
Merge branch 'master' into edge-scheduler
masa10-f e32f91a
Merge branch 'master' into edge-scheduler
masa10-f f2f5c54
integrate TICK in simulators
masa10-f f03a8ad
update changelog
masa10-f 707dd01
add type hint
masa10-f 9f71bb3
move type hint pos
masa10-f ebe68fc
resolve conflict
masa10-f 0e3c0a6
Merge branch 'master' into edge-scheduler
masa10-f 650917f
count space between TICK commands
masa10-f 9702808
always insert TICK command
masa10-f d60abf5
fix test
masa10-f 4c5b706
remove insert_tick description from CHANGELOG
masa10-f 94fb02f
remove compilation without TICK command
masa10-f 75d6327
fix type of edge from frozenset[int] to tuple[int, int]
masa10-f e3596e8
fix type hint in tests and examples
masa10-f b12c428
use NamedTuple for better type hint
masa10-f 811ba8f
integrate timeline and detailed_timeline properties into the simple t…
masa10-f 998027e
update related stuff
masa10-f 64c17fb
move the position of the auto-entangle-schedule call
masa10-f 9a86068
update example and tests
masa10-f 610ea59
extend the entangle time validator
masa10-f d6a10ff
add unittest
masa10-f a0e6601
add TimeSlice inheriting NamedTuple
masa10-f 7688819
improve validator to raise errors
masa10-f 3701b95
update tests and exmples
masa10-f b1912ad
fix docstring
masa10-f 55e1d81
update the example
masa10-f 497beff
fix ruff error
masa10-f 14c5c7a
update changelog
masa10-f 20c6730
fix behavior if scheduler is not passed.
masa10-f e2a8c97
changed scheduler default strategy
masa10-f a9feebb
update changelog
masa10-f 5e26cc8
add unittest for pattern
masa10-f 7350398
add depth property
masa10-f 8981815
update changelog
masa10-f 6c97cfb
fix ruff
masa10-f 0302898
remove docstring
masa10-f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """Entanglement Scheduling and TICK Command Demo | ||
| ================================================ | ||
|
|
||
| This example demonstrates the new entanglement scheduling functionality | ||
| and TICK commands in graphqomb. | ||
| """ | ||
|
|
||
| from graphqomb.common import Plane, PlannerMeasBasis | ||
| from graphqomb.graphstate import GraphState | ||
| from graphqomb.pattern import print_pattern | ||
| from graphqomb.qompiler import qompile | ||
| from graphqomb.schedule_solver import ScheduleConfig, Strategy | ||
| from graphqomb.scheduler import Scheduler | ||
|
|
||
| # Create a simple graph state | ||
| print("=== Entanglement Scheduling Demo ===\n") | ||
| print("1. Creating graph state...") | ||
| node_labels = ["input", "middle1", "middle2", "output"] | ||
| edges = [("input", "middle1"), ("middle1", "middle2"), ("middle2", "output")] | ||
| inputs = ["input"] | ||
| outputs = ["output"] | ||
| meas_bases = { | ||
| "input": PlannerMeasBasis(Plane.XY, 0.0), | ||
| "middle1": PlannerMeasBasis(Plane.XY, 0.0), | ||
| "middle2": PlannerMeasBasis(Plane.XY, 0.0), | ||
| } | ||
|
|
||
| graph, node_map = GraphState.from_graph( | ||
| nodes=node_labels, | ||
| edges=edges, | ||
| inputs=inputs, | ||
| outputs=outputs, | ||
| meas_bases=meas_bases, | ||
| ) | ||
|
|
||
| node0 = node_map["input"] | ||
| node1 = node_map["middle1"] | ||
| node2 = node_map["middle2"] | ||
| node3 = node_map["output"] | ||
|
|
||
| print(f" Nodes: {list(graph.physical_nodes)}") | ||
| print(f" Input: {list(graph.input_node_indices.keys())}") | ||
| print(f" Output: {list(graph.output_node_indices.keys())}") | ||
| print(f" Edges: {list(graph.physical_edges)}") | ||
|
|
||
| # Define flow | ||
| flow = {node0: {node1}, node1: {node2}, node2: {node3}} | ||
|
|
||
| # Create scheduler | ||
| print("\n2. Creating scheduler and solving schedule...") | ||
| scheduler = Scheduler(graph, flow) | ||
| config = ScheduleConfig(strategy=Strategy.MINIMIZE_SPACE) | ||
| success = scheduler.solve_schedule(config) | ||
|
|
||
| if success: | ||
| print(" Scheduling successful!") | ||
| print(f" Number of time slices: {scheduler.num_slices()}") | ||
|
|
||
| # Show preparation times | ||
| prep_times = {k: v for k, v in scheduler.prepare_time.items() if v is not None} | ||
| print(f" Preparation times: {prep_times}") | ||
|
|
||
| # Show measurement times | ||
| meas_times = {k: v for k, v in scheduler.measure_time.items() if v is not None} | ||
| print(f" Measurement times: {meas_times}") | ||
|
|
||
| # Show entanglement times (auto-scheduled by solve_schedule) | ||
| print("\n3. Entanglement times (auto-scheduled)...") | ||
| ent_times = {edge: time for edge, time in scheduler.entangle_time.items() if time is not None} | ||
| print(f" Entanglement times: {ent_times}") | ||
|
|
||
| # Show detailed timeline | ||
| print("\n4. Detailed timeline (Prep, Entangle, Measure):") | ||
| timeline = scheduler.timeline | ||
| for time_idx, (prep_nodes, ent_edges, meas_nodes) in enumerate(timeline): | ||
| print(f" Time {time_idx}:") | ||
| if prep_nodes: | ||
| print(f" Prepare: {sorted(prep_nodes)}") | ||
| if ent_edges: | ||
| edges_str = [f"({min(e)},{max(e)})" for e in ent_edges] | ||
| print(f" Entangle: {', '.join(edges_str)}") | ||
| if meas_nodes: | ||
| print(f" Measure: {sorted(meas_nodes)}") | ||
|
|
||
| # Compile pattern (TICK commands are inserted automatically per time slice) | ||
| print("\n5. Compiling pattern with scheduler-driven TICK commands...") | ||
| pattern = qompile(graph, flow, scheduler=scheduler) | ||
| print(f" Pattern has {len(pattern.commands)} commands") | ||
| print(f" Maximum space usage: {pattern.max_space} qubits") | ||
|
|
||
| print("\n Pattern commands:") | ||
| print_pattern(pattern, lim=30) | ||
|
|
||
| # Manual entanglement scheduling example | ||
| print("\n6. Manual entanglement scheduling example...") | ||
| scheduler2 = Scheduler(graph, flow) | ||
| scheduler2.manual_schedule( | ||
| prepare_time={node1: 0, node2: 1, node3: 2}, | ||
| measure_time={node0: 1, node1: 2, node2: 3}, | ||
| entangle_time={ | ||
| (node0, node1): 0, | ||
| (node1, node2): 1, | ||
| (node2, node3): 2, | ||
| }, | ||
| ) | ||
|
|
||
| scheduler2.validate_schedule() # Will raise ValueError if invalid | ||
| print(" Manual schedule is valid: True") | ||
| print(f" Number of time slices: {scheduler2.num_slices()}") | ||
|
|
||
| pattern_manual = qompile(graph, flow, scheduler=scheduler2) | ||
| print(f" Pattern has {len(pattern_manual.commands)} commands") | ||
| print(f" Maximum space usage: {pattern_manual.max_space} qubits") | ||
|
|
||
| print("\nDemo completed successfully!") |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.