Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
abb9fa4
:white_check_mark: Add tests for convert_to_phase_gadget
Feb 3, 2025
5ef6d90
:sparkles: Add convert_to_phase_gadget to ZXGraphState
Feb 3, 2025
ecd81a0
:art: Add diagramatic representation for each tests in convert_to_pha…
Feb 5, 2025
d15f954
:white_check_mark: Add tests for merge_yz_to_xy
Feb 5, 2025
912cc8a
:art: Add merge_yz_to_xy
Feb 5, 2025
eb6f70e
:art: Improve tests' readability
Feb 6, 2025
260577a
:white_check_mark: Add tests for merge_yz_nodes
Feb 6, 2025
0777029
:art: Add merge_yz_nodes
Feb 6, 2025
735b32d
:recycle: Refactor test codes
Feb 15, 2025
85a79bb
:white_check_mark: Add tests for prune_non_clifford
Feb 15, 2025
d8d07e6
:sparkles: Add prune_non_clifford to ZXGraphState
Feb 15, 2025
31fc41d
:art: Apply ruff check
Feb 15, 2025
6d196b5
:pencil2: Fix typo
Feb 15, 2025
7e7a73d
:bug: Fix merge_yz_to_xy & merge_yz_nodes
Feb 15, 2025
fdf0aa4
:sparkles: Add get_random_gflow_circ
Feb 15, 2025
9a7c3a7
:sparkles: Add an example for Clifford/non-Clifford removal
Feb 15, 2025
60593b5
Merge branch 'mf' into non-Clifford-removal
Feb 19, 2025
d8520fe
:bug: Fix _angle_check
Feb 24, 2025
eab5787
:bug: Fix test_local_complement in test_euler.py
Feb 24, 2025
0c25e60
:bug: Fix update rule
Feb 24, 2025
39cb744
:bug: Add property method
Feb 28, 2025
6cb9263
:art: Apply ruff
Feb 28, 2025
0e7357a
:white_check_mark: Add pivot tests for euler.py
Feb 28, 2025
c638d4f
Merge branch 'mf' into non-Clifford-removal
Apr 21, 2025
6e29aa4
:sparkles: Add measurement_actions in test_zxgraphstate
Apr 22, 2025
4dc91c6
:sparkles: Add plane_combinations in test_zxgraphstate
Apr 22, 2025
d806447
:sparkles: Add rng in test_zxgraphstate
Apr 22, 2025
16e2c10
:sparkles: Add doc in plane_combinations
Apr 22, 2025
3e41c7e
:art: Change typehints
Apr 22, 2025
790fc5a
:bug: Fix bug in _test
Apr 22, 2025
abf22bd
:art: Fix test_local_complement_with_no_edge
Apr 22, 2025
03b514c
:art: Fix test_local_complement_on_output_node
Apr 22, 2025
0ab74be
:art: Fix test_local_complement_with_two_nodes_graph
Apr 22, 2025
215adbd
:art: Fix test_local_complement_with_minimal_graph
Apr 22, 2025
f9e41c3
:art: Fix test_local_complement_4_times
Apr 22, 2025
8161140
:construction: Migrate local_complement & pivot into new version
Apr 23, 2025
fe1bd6d
:art: Fix lc & import
Apr 23, 2025
f826a84
:fire: Remove old local_complement, pivot, remove_clifford
Apr 23, 2025
7d5a8d9
:art: Fix typehints in test
Apr 23, 2025
45dfbc8
:recycle: Refactor test_zxgraphstate
Apr 23, 2025
44131ec
:fire: Delete unneccesary tests
Apr 23, 2025
9abe2cd
:art: Fix measurement action readability
Apr 28, 2025
81001bc
:art: Rename get_random_gflow_circ into random_circ
Apr 28, 2025
1e8870d
:art: Fix typehints for random_circ
Apr 28, 2025
b7b0a8c
:fire: Remove unnecessary del sentences
Apr 28, 2025
27e56f9
:art: Rename prune_non_cliffords method into full_reduce
Apr 28, 2025
cf8892b
:art: Format docstring
Apr 28, 2025
d0cfd88
:recycle: Merge if block into while block
Apr 28, 2025
e67f8a0
:recycle: Refactor check conditions
Apr 28, 2025
50af11d
:art: Migrate from get_random_gflow_circ to random_circ
Apr 28, 2025
e4c0e0e
:memo: Fix docstrings
Apr 28, 2025
8802575
:bug: Fix typehint in random_objects
Apr 28, 2025
7df1c8f
:art: Fix typehints
Apr 28, 2025
30bcf55
:art: Rewrite angle condition with _is_close_angle
May 3, 2025
3b29d82
:art: Improve readability
May 3, 2025
3d277ef
:white_check_mark: Add corner case for test_remove_clifford
May 3, 2025
aafe3fb
:art: Apply ruff
May 3, 2025
22861f0
:recycle: Refactor test_zxgraphstate
May 3, 2025
faaba1a
:zap: Improve performance for merge_yz_nodes
May 3, 2025
af2aba8
:memo: Fix docstrings
May 3, 2025
611f142
:art: Integrate the term 'vertex' into 'node'
May 3, 2025
a0baef7
:fire: Remove _update_new_measurement method
May 3, 2025
4fb8a61
:art: Simplify
May 3, 2025
69e12f4
:art: Apply ruff
May 3, 2025
63a6526
:art: Improve docstrings and variable name
May 3, 2025
1655757
:bug: Fix bug in _remove_clifford
May 3, 2025
ddd4c6f
:recycle: Refactor merge_yz_nodes
May 3, 2025
3576a63
:recycle: Refactor _extract_yz_adjacent_pair
May 3, 2025
6bf9946
:fire: Delete an uneccesary line
May 5, 2025
dc7375b
:recycle: Refactor ZXGraphState
May 5, 2025
0927f1c
:recycle: Refactor ZXGraphState
May 5, 2025
7421cbd
:bug: Fix bug in merge_yz_to_xy
May 6, 2025
b3cb2c7
:bug: Fix bug when referencing _clifford_rules
May 6, 2025
b02df26
:truck: Rename
May 6, 2025
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
43 changes: 43 additions & 0 deletions examples/zxgraph_simplification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Basic example of simplifying a ZX-diagram.

By using the `full_reduce` method,
we can remove all the internal Clifford nodes and some non-Clifford nodes from the graph state,
which generates a simpler ZX-diagram.
This example is a simple demonstration of the simplification process.
"""

# %%
from copy import deepcopy

import numpy as np

from graphix_zx.circuit import circuit2graph
from graphix_zx.random_objects import random_circ
from graphix_zx.visualizer import visualize
from graphix_zx.zxgraphstate import ZXGraphState

# %%
circ = random_circ(4, 4)
graph, flow = circuit2graph(circ)
zx_graph = ZXGraphState()
zx_graph.append(graph)

visualize(zx_graph)
print("node | plane | angle (/pi)")
for node in zx_graph.input_nodes:
print(f"{node} (input)", zx_graph.meas_bases[node].plane, zx_graph.meas_bases[node].angle / np.pi)
for node in zx_graph.physical_nodes - zx_graph.input_nodes - zx_graph.output_nodes:
print(node, zx_graph.meas_bases[node].plane, zx_graph.meas_bases[node].angle / np.pi)

# %%
zx_graph_smp = deepcopy(zx_graph)
zx_graph_smp.full_reduce()

visualize(zx_graph_smp)
print("node | plane | angle (/pi)")
for node in zx_graph.input_nodes:
print(f"{node} (input)", zx_graph.meas_bases[node].plane, zx_graph.meas_bases[node].angle / np.pi)
for node in zx_graph_smp.physical_nodes - zx_graph.input_nodes - zx_graph_smp.output_nodes:
print(node, zx_graph_smp.meas_bases[node].plane, zx_graph_smp.meas_bases[node].angle / np.pi)

# %%
22 changes: 22 additions & 0 deletions graphix_zx/graphstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,28 @@ def local_cliffords(self) -> dict[int, LocalClifford]:
"""
return self.__local_cliffords

@property
def inner2nodes(self) -> dict[int, int]:
"""Return inner index to node index mapping.

Returns
-------
dict[int, int]
inner index to node index mapping.
"""
return self.__inner2nodes

@property
def nodes2inner(self) -> dict[int, int]:
"""Return node index to inner index mapping.

Returns
-------
dict[int, int]
node index to inner index mapping.
"""
return self.__nodes2inner

def check_meas_basis(self) -> None:
"""Check if the measurement basis is set for all physical nodes except output nodes.

Expand Down
49 changes: 49 additions & 0 deletions graphix_zx/random_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This module provides:
- get_random_flow_graph: Generate a random flow graph.
- random_circ: Generate a random MBQC circuit.
"""

from __future__ import annotations
Expand All @@ -10,10 +11,13 @@

import numpy as np

from graphix_zx.circuit import MBQCCircuit
from graphix_zx.common import default_meas_basis
from graphix_zx.graphstate import GraphState

if TYPE_CHECKING:
from collections.abc import Sequence

from numpy.random import Generator


Expand Down Expand Up @@ -82,3 +86,48 @@ def get_random_flow_graph(
num_nodes += 1

return graph, flow


def random_circ(
width: int,
depth: int,
rng: np.random.Generator | None = None,
edge_p: float = 0.5,
angle_candidates: Sequence[float] = (0.0, np.pi / 3, 2 * np.pi / 3, np.pi),
) -> MBQCCircuit:
"""Generate a random MBQC circuit.

Parameters
----------
width : int
circuit width
depth : int
circuit depth
rng : numpy.random.Generator, optional
random number generator, by default numpy.random.default_rng()
edge_p : float, optional
probability of adding CZ gate, by default 0.5
angle_candidates : collections.abc.Sequence[float], optional
list of angles, by default (0, np.pi / 3, 2 * np.pi / 3, np.pi)

Returns
-------
MBQCCircuit
generated MBQC circuit
"""
if rng is None:
rng = np.random.default_rng()
circ = MBQCCircuit(width)
for d in range(depth):
for j in range(width):
circ.j(j, rng.choice(angle_candidates))
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(range(width), num))
circ.phase_gadget(target, rng.choice(angle_candidates))

return circ
Loading