Skip to content

Commit

Permalink
🍱 Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
EarlMilktea committed Oct 29, 2024
1 parent 68dfbb5 commit 1fbbfe0
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Example code for finding causal flow."""

# %%

from __future__ import annotations

import networkx as nx
from fastflow import flow

g: nx.Graph[int]

# %%

# 1 - 3 - 5
# |
# 2 - 4 - 6
g = nx.Graph([(1, 3), (2, 4), (3, 5), (4, 6)])
iset = {1, 2}
oset = {5, 6}

result = flow.find(g, iset, oset)

# Found
assert result is not None

# %%

# 1 - 3
# \ /
# X
# / \
# 2 - 4
g = nx.Graph([(1, 3), (1, 4), (2, 3), (2, 4)])
iset = {1, 2}
oset = {3, 4}

# Not found
result = flow.find(g, iset, oset)

assert result is None
45 changes: 45 additions & 0 deletions examples/gflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Example code for finding generalized flow."""

# %%

from __future__ import annotations

import networkx as nx
from fastflow import gflow
from fastflow.common import Plane

g: nx.Graph[int]

# %%

# 0 - 1
# /| |
# 4 | |
# \| |
# 2 - 5 - 3
g = nx.Graph([(0, 1), (0, 2), (0, 4), (1, 5), (2, 4), (2, 5), (3, 5)])
iset = {0, 1}
oset = {4, 5}
planes = {0: Plane.XY, 1: Plane.XY, 2: Plane.XZ, 3: Plane.YZ}

result = gflow.find(g, iset, oset, planes)

# Found
assert result is not None

# %%

# 1 - 3
# \ /
# X
# / \
# 2 - 4
g = nx.Graph([(1, 3), (1, 4), (2, 3), (2, 4)])
iset = {1, 2}
oset = {3, 4}
# Omitting planes (all Plane.XY)

result = gflow.find(g, iset, oset)

# Not found
assert result is None
44 changes: 44 additions & 0 deletions examples/pflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Example code for finding Pauli flow."""

# %%

from __future__ import annotations

import networkx as nx
from fastflow import pflow
from fastflow.common import PPlane

g: nx.Graph[int]

# %%

# 1 2 3
# | / |
# 0 - - - 4
g = nx.Graph([(0, 1), (0, 2), (0, 4), (3, 4)])
iset = {0}
oset = {4}
pplanes = {0: PPlane.Z, 1: PPlane.Z, 2: PPlane.Y, 3: PPlane.Y}

result = pflow.find(g, iset, oset, pplanes)

# Found
assert result is not None

# %%

# 1 - 3
# \ /
# X
# / \
# 2 - 4
g = nx.Graph([(1, 3), (1, 4), (2, 3), (2, 4)])
iset = {1, 2}
oset = {3, 4}
# Omitting pplanes (all PPlane.XY)

# NOTE: This results in warning (use gflow.find if pplanes has no Pauli measurements)
result = pflow.find(g, iset, oset)

# Not found
assert result is None
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ convention = "numpy"
"D1", # undocumented-XXX
"INP",
]
"examples/**/*.py" = [
"INP",
"S101", # assert
]
"tests/*.py" = [
"D1", # undocumented-XXX
"INP",
Expand Down

0 comments on commit 1fbbfe0

Please sign in to comment.