Determine the interaction graph of the circuit.
Parameters:
| Name |
Type |
Description |
Default |
ir
|
IR
|
Intermediate representation of the quantum circuit.
|
required
|
Returns:
| Type |
Description |
Graph
|
The interaction graph of the circuit.
|
Source code in opensquirrel/passes/mapper/utils.py
| def make_interaction_graph(ir: IR) -> nx.Graph:
"""Determine the interaction graph of the circuit.
Args:
ir (IR): Intermediate representation of the quantum circuit.
Returns:
The interaction graph of the circuit.
"""
interaction_graph = nx.Graph()
gates = (statement for statement in ir.statements if isinstance(statement, Gate))
for gate in gates:
target_qubits = gate.qubit_operands
match len(target_qubits):
case 1:
continue
case 2:
interaction_graph.add_edge(*target_qubits)
case _:
msg = (
f"the gate {gate!r} acts on more than 2 qubits: the gate must be decomposed before an"
f" interaction graph can be made"
)
raise ValueError(msg)
return interaction_graph
|