Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- **Non-Unitary Parity Projection Example**: Added `examples/nonunitary_parity_projection.py` demonstrating measurement-induced entanglement via a 3-node star graph parity projector

### Fixed

- **Qompiler**: `qompile()` now validates a provided scheduler before pattern generation, so invalid manual schedules fail early with `ValueError`.

## [0.3.0] - 2026-04-08

### Added
Expand Down
6 changes: 5 additions & 1 deletion graphqomb/qompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def qompile( # noqa: PLR0913
scheduler to schedule the graph state preparation and measurements,
if `None`, a `Scheduler` is constructed internally and solved with the
default ``MINIMIZE_TIME`` strategy before compiling the pattern,
otherwise the provided scheduler is validated before compiling the pattern,
by default `None`

Returns
Expand Down Expand Up @@ -97,6 +98,7 @@ def _qompile(
scheduler to schedule the graph state preparation and measurements,
if `None`, a `Scheduler` is constructed internally and solved with the
default ``MINIMIZE_TIME`` strategy before compiling the pattern,
otherwise the provided scheduler is validated before compiling the pattern,
by default `None`

Returns
Expand All @@ -112,9 +114,11 @@ def _qompile(
topo_order.reverse() # children first

commands: list[Command] = []
if not scheduler:
if scheduler is None:
scheduler = Scheduler(graph, pauli_frame.xflow, pauli_frame.zflow)
scheduler.solve_schedule()
else:
scheduler.validate_schedule()

timeline = scheduler.timeline

Expand Down
26 changes: 26 additions & 0 deletions tests/test_scheduler_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,32 @@ def test_validate_schedule_dag_violations() -> None:
scheduler2.validate_schedule()


def test_qompile_validates_provided_scheduler() -> None:
"""Qompile should reject invalid schedules before pattern generation."""
graph = GraphState()
node0 = graph.add_physical_node()
node1 = graph.add_physical_node()
node2 = graph.add_physical_node()
graph.add_physical_edge(node0, node1)
graph.add_physical_edge(node1, node2)

qindex = 0
graph.register_input(node0, qindex)
graph.register_output(node2, qindex)
graph.assign_meas_basis(node0, PlannerMeasBasis(Plane.XY, 0.0))
graph.assign_meas_basis(node1, PlannerMeasBasis(Plane.XY, 0.0))

flow = {node0: {node1}, node1: {node2}}
scheduler = Scheduler(graph, flow)
scheduler.manual_schedule(
prepare_time={node1: 0, node2: 0},
measure_time={node0: 2, node1: 1},
)

with pytest.raises(ValueError, match="DAG violation"):
qompile(graph, flow, scheduler=scheduler)


def test_validate_schedule_same_time_prep_meas() -> None:
"""Test that validate_schedule rejects schedules with nodes prepared and measured at same time."""
# Create a graph
Expand Down
Loading