Skip to content

[CQT-430]: Make the interaction graph a property of the circuit expressed in terms of simple types#670

Open
rares1609 wants to merge 6 commits intodevelopfrom
CQT-430-Make-the-interaction-graph-a-property-of-the-Circuit-expressed-in-terms-of-simple-types
Open

[CQT-430]: Make the interaction graph a property of the circuit expressed in terms of simple types#670
rares1609 wants to merge 6 commits intodevelopfrom
CQT-430-Make-the-interaction-graph-a-property-of-the-Circuit-expressed-in-terms-of-simple-types

Conversation

@rares1609
Copy link
Contributor

No description provided.

Rares Oancea added 6 commits February 11, 2026 10:55
…nteraction-graph-a-property-of-the-Circuit-expressed-in-terms-of-simple-types
…nteraction-graph-a-property-of-the-Circuit-expressed-in-terms-of-simple-types
@rares1609 rares1609 requested a review from elenbaasc February 16, 2026 14:06
Copy link
Collaborator

@elenbaasc elenbaasc left a comment

Choose a reason for hiding this comment

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

Thanks for the effort!

I think we should pass the circuit/self to the Circuit.map method, such that the passes themselves can pick up the interaction graph where needed.

Comment on lines +125 to 126
def _ir_to_networkx(ir: IR) -> nx.Graph:
"""Build an undirected interaction graph representation of the IR.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't use package specific name in the functionality.

Also is it 'undirected'? Or should it be unidirected or bi-directional?

Suggested change
def _ir_to_networkx(ir: IR) -> nx.Graph:
"""Build an undirected interaction graph representation of the IR.
def _ir_to_graph(ir: IR) -> nx.Graph:
"""Build an undirected interaction graph representation of the IR.

raise ValueError(msg)

circuit_graph = self._ir_to_interaction_graph(ir)
if interaction_graph is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if interaction_graph is None:
if not interaction_graph:

return interaction_graph

@staticmethod
def _interaction_graph_to_networkx(edges: dict[tuple[int, int], int]) -> nx.Graph:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _interaction_graph_to_networkx(edges: dict[tuple[int, int], int]) -> nx.Graph:
def _convert_interaction_graph(edges: dict[tuple[int, int], int]) -> nx.Graph:

self,
ir: IR,
qubit_register_size: int,
interaction_graph: dict[tuple[int, int], int] | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is the interaction graph an input argument to the map method? If it is a property of the circuit, then just provide the circuit as input (instead of just the IR) and take the interaction graph from there...

And the passes that don't required it (e.g. MIP mapper), don't take it from the circuit... am I missing something?


InstructionCount = dict[str, int]
MeasurementToBitMap = defaultdict[str, list[int]]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
InteractionGraph = dict[tuple[int, int], int]

):
waiting_time = schedulable_data.data["timing_constraints"][0].rel_time
assert waiting_time == -1.0 * expected_waiting_cycle * CYCLE_TIME
assert waiting_time == -1.0 * expected_waiting_cycle * CYCLE_TIME # noqa: RUF069
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here as previous comment.

used_interaction_graph = {"called": False}
used_ir = {"called": False}

def fake_interaction_graph_to_networkx(_: Any) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

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

fake -> mock

Suggested change
def fake_interaction_graph_to_networkx(_: Any) -> Any:
def mock_interaction_graph_to_networkx(_: Any) -> Any:

CNOT q[0], q[1]
CNOT q[0], q[2]
CNOT q[1], q[2]
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a CNOT q[1], q[0], and adjust the interaction_graph

Comment on lines +98 to +102
if interaction_graph is not None:
msg = (
"The MIPMapper does not effectively use the interaction graph, thus this argument should be set to None"
)
warnings.warn(msg, stacklevel=2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be needed... the interaction graph should simply not be picked up by this mapper pass.

Comment on lines +190 to +193
def test_interaction_graph_warning(mapper1: MIPMapper, circuit1: Circuit) -> None:
msg = "The MIPMapper does not effectively use the interaction graph, thus this argument should be set to None"
with pytest.warns(Warning, match=msg):
mapper1.map(circuit1.ir, circuit1.qubit_register_size, interaction_graph=circuit1.interaction_graph)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the above changes are made, then these tests don't need to be done.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments