Conversation
|
@nabe98 |
masa10-f
left a comment
There was a problem hiding this comment.
Great job! I added a few comments, so please refer to them.
Also, could you move ZXGraphState class into a new file, like zxgraphstate.py?
|
@nabe98 Could you also turn on the format/type check ci? |
|
When I run the following code, after Cliffords are removed from the original graph, there seems no gflow. Do you have any idea about this? # %%
import numpy as np
import networkx as nx
import fastflow as ff
from fastflow import gflow
from graphix_zx.common import Plane
from graphix_zx.euler import is_clifford_angle
from graphix_zx.flow import FlowLike
from graphix_zx.graphstate import BaseGraphState
from graphix_zx.zxgraphstate import ZXGraphState
from graphix_zx.circuit import MBQCCircuit, circuit2graph
from graphix_zx.visualizer import visualize
def random_gflow_circ(
width: int,
depth: int,
rng: np.random.Generator = np.random.default_rng(),
edge_p: float = 0.5,
) -> MBQCCircuit:
angle_list = [0, np.pi / 3, 2 * np.pi / 3, np.pi]
circ = MBQCCircuit(width)
for d in range(depth):
for j in range(width):
circ.j(j, rng.choice(angle_list))
if d < depth - 1:
for j in range(width):
if rng.random() < edge_p:
circ.cz(j, (j + 1) % width)
num = rng.integers(0, width)
if num > 0:
target = set(rng.choice([i for i in range(width)], num))
circ.phase_gadget(target, rng.choice(angle_list))
return circ
def check_clifford_removal(graphstate: BaseGraphState) -> bool:
no_clifford = True
for node in (
graphstate.physical_nodes - graphstate.output_nodes - graphstate.input_nodes
):
angle = graphstate.meas_angles[node]
no_clifford &= not is_clifford_angle(angle)
return no_clifford
def gflow_wrapper(graphstate: BaseGraphState) -> FlowLike:
graph = nx.Graph()
graph.add_nodes_from(graphstate.physical_nodes)
graph.add_edges_from(graphstate.physical_edges)
planes = graphstate.meas_planes
fastflow_planes = {}
for node, plane in planes.items():
if plane == Plane.XY:
fastflow_planes[node] = ff.common.Plane.XY
elif plane == Plane.YZ:
fastflow_planes[node] = ff.common.Plane.YZ
elif plane == Plane.XZ:
fastflow_planes[node] = ff.common.Plane.XZ
else:
msg = f"No match {plane}"
raise ValueError(msg)
gflow_object = gflow.find(
graph, graphstate.input_nodes, graphstate.output_nodes, fastflow_planes
).f
return gflow_object
# %%
# generate circuit
# graph, flow = get_random_flow_graph(5, 5)
circ = random_gflow_circ(5, 5)
graph, flow = circuit2graph(circ)
# visualize(graph, save=True, filename="test.png")
gflow_result = gflow_wrapper(graph)
print(gflow_result)
# %%
# ZX process
zxgraph = ZXGraphState()
zxgraph.append(graph)
# %%
zxgraph.remove_cliffords()
print("No Clifford?", check_clifford_removal(zxgraph))
# visualize(zxgraph, save=True, filename="zxtest.png")
gflow_result = gflow_wrapper(zxgraph)
print(gflow_result) |
|
@masa10-f Since it relies on the fastflow module, I didn't include the test to confirm that it preserves gflow. Do you think it should be included? |
|
@nabe98 Could you move tests for ZXGraphState into a new file because the original file becomes too big to maintain? |
|
@nabe98 Could you check ruff? Afterwards, you can merge this branch! Well done! |
|
@masa10-f Thanks for reviewing! |
Enables Clifford vertex removal.
For [1], cases corresponding to the following lemmas are implemented
Tests
[1] https://arxiv.org/abs/2003.01664
closes: #6