Conversation
Collaborator
|
@nabe98 Did you check this change fixes the side effect on your program? |
Collaborator
Author
|
@masa10-f # %%
import numpy as np
from graphix_zx.circuit import MBQCCircuit, circuit2graph
from graphix_zx.zxgraphstate import ZXGraphState
from graphix_zx.focus_flow import focus_gflow, is_focused
def random_gflow_circ(
width: int,
depth: int,
rng: np.random.Generator = np.random.default_rng(),
edge_p: float = 0.5,
) -> MBQCCircuit:
"""Generate a random MBQC circuit which has gflow
Parameters
----------
width : int
circuit width
depth : int
circuit depth
rng : np.random.Generator, optional
random number generator, by default np.random.default_rng()
edge_p : float, optional
probability of adding CZ gate, by default 0.5
Returns
-------
MBQCCircuit
generated MBQC circuit
"""
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
circ = random_gflow_circ(4, 4)
graph, flow = circuit2graph(circ)
print(flow)
zxgraph = ZXGraphState()
zxgraph.append(graph)
flow_opt = focus_gflow(flow, zxgraph)
print(flow)
print(is_focused(flow, graph))
print(is_focused(flow_opt, graph))
print("flow == flow_opt: ", flow == flow_opt)
# %%In the previous implementation, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.