Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `.to_<object>_or_none` for transformations that can return `object` or `None`. Equivalently, we use `.from_<object>_or_none` for constructors.
- accessor methods use nouns instead of verb + noun. Example: `Pattern.max_degree` instead of `Pattern.compute_max_degree`.

- #571: Removed method `Pattern.graph`


## [0.3.5] - 2026-03-26

### Added
Expand Down
2 changes: 2 additions & 0 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Graphix does not guarantee backwards compatibility between 0.x version releases.

## Unreleased

- #571: Method `Pattern.graph` (formely `Pattern.extract_graph`) is removed. Use instead `Pattern.to_opengraph().graph` which standardizes the pattern and fails gracefully if there are non-commutative CLiffords.

- #557: Namespace homogenisation.

The following methods and classes have been renamed to provide a homogeneous, consistent and pythonic naming convention:
Expand Down
2 changes: 0 additions & 2 deletions docs/source/modifier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ Pattern Manipulation

.. automethod:: is_standard

.. automethod:: graph

.. automethod:: nodes

.. automethod:: to_causalflow
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ This reveals the graph structure of the resource state which we can inspect:
.. code-block:: python

import networkx as nx
graph = pattern.graph()
graph = pattern.to_opengraph().graph
pos = {0: (0, 0), 1: (0, -0.5), 2: (1, 0), 3: (4, 0), 4: (1, -0.5), 5: (2, -0.5), 6: (3, -0.5), 7: (4, -0.5)}
graph_params = {'node_size': 240, 'node_color': 'w', 'edgecolors': 'k', 'with_labels': True}
nx.draw(graph, pos=pos, **graph_params)
Expand Down
2 changes: 1 addition & 1 deletion examples/fusion_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# %%
# Here we say we want a graph state with 9 nodes and 12 edges.
# We can obtain resource graph for a measurement pattern by using :code:`pattern.graph()`.
# We can obtain resource graph for a measurement pattern by using :code:`pattern.to_opengraph().graph`.
gs = Graph()
nodes = [0, 1, 2, 3, 4, 5, 6, 7, 8]
edges = [(0, 1), (1, 2), (2, 3), (3, 0), (3, 4), (0, 5), (4, 5), (5, 6), (6, 7), (7, 0), (7, 8), (8, 1)]
Expand Down
2 changes: 1 addition & 1 deletion examples/ghz_with_tn.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
pattern = circuit.transpile().pattern
pattern.standardize()

graph = pattern.graph()
graph = pattern.to_opengraph().graph
print(f"Number of nodes: {len(graph.nodes)}")
print(f"Number of edges: {len(graph.edges)}")
pos = nx.spring_layout(graph)
Expand Down
2 changes: 1 addition & 1 deletion examples/qft_with_tn.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def qft(circuit: Circuit, n: int) -> None:
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()
graph = pattern.graph()
graph = pattern.to_opengraph().graph
print(f"Number of nodes: {len(graph.nodes)}")
print(f"Number of edges: {len(graph.edges)}")

Expand Down
2 changes: 1 addition & 1 deletion examples/tn_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def ansatz(
# %%
# Print some properties of the graph.

graph = pattern.graph()
graph = pattern.to_opengraph().graph
print(f"Number of nodes: {len(graph.nodes)}")
print(f"Number of edges: {len(graph.edges)}")

Expand Down
34 changes: 10 additions & 24 deletions graphix/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,35 +1192,14 @@ def max_degree(self) -> int:
max_degree : int
max degree of a pattern
"""
graph = self.graph()
graph = self.to_opengraph().graph
degree = graph.degree()
assert isinstance(degree, nx.classes.reportviews.DiDegreeView)
degrees = dict(degree).values()
if len(degrees) == 0:
return 0
return int(max(degrees))

def graph(self) -> nx.Graph[int]:
"""Return the graph state from the command sequence, extracted from ``N`` and ``E`` commands.

Returns
-------
graph_state: nx.Graph[int]
"""
graph: nx.Graph[int] = nx.Graph()
graph.add_nodes_from(self.input_nodes)
for cmd in self.__seq:
match cmd.kind:
case CommandKind.N:
graph.add_node(cmd.node)
case CommandKind.E:
u, v = cmd.nodes
if graph.has_edge(u, v):
graph.remove_edge(u, v)
else:
graph.add_edge(u, v)
return graph

def nodes(self) -> set[int]:
"""Return the set of nodes of the pattern."""
nodes = set(self.input_nodes)
Expand All @@ -1237,8 +1216,15 @@ def isolated_nodes(self) -> set[int]:
isolated_nodes : set[int]
set of the isolated nodes
"""
graph = self.graph()
return {node for node, d in graph.degree if d == 0}
nodes = set(self.input_nodes)
for cmd in self.__seq:
match cmd.kind:
case CommandKind.N:
nodes.add(cmd.node)
case CommandKind.E:
u, v = cmd.nodes
nodes -= {u, v}
return nodes

def to_opengraph(self) -> OpenGraph[Measurement]:
r"""Extract the underlying resource-state open graph from the pattern.
Expand Down
2 changes: 1 addition & 1 deletion graphix/sim/tensornet.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def __init__(
if graph_prep == "parallel":
if not pattern.is_standard():
raise ValueError("parallel preparation strategy does not support not-standardized pattern")
graph = pattern.graph()
graph = pattern.to_opengraph().graph
state = MBQCTensorNet(
graph_nodes=graph.nodes,
graph_edges=graph.edges,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def test_graph(self) -> None:
circuit.rx(v, ANGLE_PI / 9)

pattern = circuit.transpile().pattern
graph = pattern.graph()
graph = pattern.to_opengraph().graph

graph_ref: nx.Graph[int] = nx.Graph()
graph_ref.add_nodes_from(range(27))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_space_minimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_minimization_by_degree_edge_ordering() -> None:
]
)
# Verify Networkx node ordering behaves as expected
graph = p.graph()
graph = p.to_opengraph().graph
assert set(graph.edges()) == {(0, 2), (1, 2)}
assert set(graph.edges(2)) == {(2, 0), (2, 1)}

Expand Down
Loading