-
Notifications
You must be signed in to change notification settings - Fork 1
Implement Simple Visualizer #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
93cb042
draw graph example
masa10-f ada1ba0
implement visualizer
masa10-f 1c72c51
config for sphinx doc
masa10-f 207eddd
set up for sphinx doc
masa10-f 94d3318
add matplotlib and networkx as requiremenets
masa10-f 90e7da2
ignore types in matplotlib
masa10-f 7052e02
add demo of different meas plane
masa10-f d62d7ba
enrich visualizer
masa10-f 510878a
add multiple demo
masa10-f 4abc52e
tune font size
masa10-f 5f44dc4
ignore png
masa10-f a8ede6b
update color map
masa10-f 5f5aa02
add legend
masa10-f b879130
change display style of Pauli node and modify size calculation logic
masa10-f a724cb0
adjust node size
masa10-f 98d8817
update demo
masa10-f d39545a
fix ruff and pyright error
masa10-f c5fa8b5
remove scale
masa10-f e370f97
locate the legend at the buttom
masa10-f 24fb754
use AxisMeasBasis
masa10-f 12492f2
move is_clifford_angle and is_close_angle
masa10-f cf2f11b
update unittest
masa10-f f16aeb4
complete the implementation of visualizer
masa10-f b8d1d7c
update docs
masa10-f 5f42a29
ruff
masa10-f 7dac4c5
remove float cast
masa10-f 4dbd58e
use tuple
masa10-f a23af3a
graphix_zx/visualizer.py
masa10-f 1239d31
Revert "graphix_zx/visualizer.py"
masa10-f 889bbab
implement compatibility layer for ColorMap
masa10-f e1ad8f0
delete unnecessary line
masa10-f 1bb84fb
remove .show() call
masa10-f a5fd246
add ax as an input variable and return fig and ax
masa10-f aaf8620
use fig/ax style and remove plt.xxx
masa10-f 1c27993
remove figure
masa10-f 881ec8b
rename get_xxx
masa10-f 2f1a01e
use NamedTuple for complex setup func
masa10-f bb6ea80
use unpack
masa10-f b8fa9d9
delete pyright pragmas
masa10-f 89eaf52
remove unnecessary float cast
masa10-f c9dc687
ruff
masa10-f a224191
completely use fig/ax style
masa10-f 1aae3d9
update example
masa10-f d56472e
add ref to matplotlib
masa10-f 1573686
add docstring
masa10-f e113ca2
tune figure aspect ratio
masa10-f 6a79869
rename get_pauli_axis -> determine_pauli_axis
masa10-f 17a13a9
fix doc
masa10-f 068e153
unify into math.pi
masa10-f f56b44e
type cast
masa10-f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,3 +164,4 @@ cython_debug/ | |
| # Custom stuff | ||
| docs/source/gallery | ||
| docs/source/sg_execution_times.rst | ||
| *.png | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,4 @@ Module reference | |
| pauli_frame | ||
| qompiler | ||
| scheduler | ||
| visualizer | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Visualizer Module | ||
| ================= | ||
|
|
||
| .. automodule:: graphix_zx.visualizer | ||
| :members: |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| """ | ||
| Graph Visualizer | ||
| ================ | ||
|
|
||
| Simple example to draw a GraphState in graphix-zx. | ||
| """ | ||
|
|
||
| # %% | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| from graphix_zx.common import Axis, AxisMeasBasis, Plane, PlannerMeasBasis, Sign | ||
| from graphix_zx.graphstate import GraphState | ||
| from graphix_zx.random_objects import generate_random_flow_graph | ||
| from graphix_zx.visualizer import visualize | ||
|
|
||
| # Create a random flow graph | ||
| random_graph, flow = generate_random_flow_graph(5, 5) | ||
|
|
||
|
|
||
| # Visualize the flow graph | ||
| ax = visualize(random_graph) | ||
| plt.show() | ||
| print("Displayed flow graph") | ||
|
|
||
| # %% | ||
| # Create a demo graph with different measurement planes and input/output nodes | ||
|
|
||
| demo_graph = GraphState() | ||
|
|
||
| # Add input nodes | ||
| input_node1 = demo_graph.add_physical_node() | ||
| input_node2 = demo_graph.add_physical_node() | ||
| q_index1 = demo_graph.register_input(input_node1) | ||
| q_index2 = demo_graph.register_input(input_node2) | ||
|
|
||
| # Set measurement bases for input nodes (XY plane with different angles) | ||
| demo_graph.assign_meas_basis(input_node1, AxisMeasBasis(Axis.X, Sign.PLUS)) | ||
| demo_graph.assign_meas_basis(input_node2, PlannerMeasBasis(Plane.XY, np.pi / 6)) | ||
|
|
||
| # Add internal nodes with different measurement planes | ||
| internal_node1 = demo_graph.add_physical_node() | ||
| internal_node2 = demo_graph.add_physical_node() | ||
| internal_node3 = demo_graph.add_physical_node() | ||
|
|
||
| # Set measurement bases for internal nodes | ||
| # XZ plane (blue) with angle π/4 | ||
| demo_graph.assign_meas_basis(internal_node1, PlannerMeasBasis(Plane.XZ, np.pi / 4)) | ||
| # YZ plane (red) with angle π/3 | ||
| demo_graph.assign_meas_basis(internal_node2, PlannerMeasBasis(Plane.YZ, np.pi / 3)) | ||
| # XZ plane (blue) with angle π/2 | ||
| demo_graph.assign_meas_basis(internal_node3, PlannerMeasBasis(Plane.XZ, np.pi / 2)) | ||
|
|
||
| # Add output nodes | ||
| output_node1 = demo_graph.add_physical_node() | ||
| output_node2 = demo_graph.add_physical_node() | ||
| demo_graph.register_output(output_node1, 0) | ||
| demo_graph.register_output(output_node2, 1) | ||
|
|
||
| # Create edges to connect the graph | ||
| demo_graph.add_physical_edge(input_node1, internal_node1) | ||
| demo_graph.add_physical_edge(input_node2, internal_node2) | ||
| demo_graph.add_physical_edge(internal_node1, internal_node3) | ||
| demo_graph.add_physical_edge(internal_node2, internal_node3) | ||
| demo_graph.add_physical_edge(internal_node3, output_node1) | ||
| demo_graph.add_physical_edge(internal_node1, output_node2) | ||
|
|
||
| print("Demo graph with XZ and YZ measurement planes:") | ||
| print(f"Input nodes: {list(demo_graph.input_node_indices.keys())}") | ||
| print(f"Output nodes: {list(demo_graph.output_node_indices.keys())}") | ||
| print(f"All physical nodes: {demo_graph.physical_nodes}") | ||
| print("Internal nodes with measurement bases:") | ||
| for node, basis in demo_graph.meas_bases.items(): | ||
| print(f" Node {node}: {basis.plane.name} plane, angle={basis.angle:.3f}") | ||
|
|
||
| # Visualize the demo graph with labels | ||
| ax = visualize(demo_graph, show_node_labels=True) | ||
| plt.show() | ||
| print("Displayed demo graph with labels") | ||
|
|
||
| # Visualize without labels to see just the colored patterns | ||
| print("\n--- Same graph without node labels ---") | ||
| ax = visualize(demo_graph, show_node_labels=False) | ||
| plt.show() | ||
| print("Displayed demo graph without labels") | ||
|
|
||
| # %% | ||
| # Create another demo graph with Pauli measurements (θ=0, π) | ||
| pauli_demo_graph = GraphState() | ||
|
|
||
| # Add nodes for Pauli measurements | ||
| pauli_input = pauli_demo_graph.add_physical_node() | ||
| pauli_demo_graph.register_input(pauli_input) | ||
|
|
||
| # Create internal nodes with Pauli measurements | ||
| x_measurement_node = pauli_demo_graph.add_physical_node() # X measurement: XY plane, θ=0 | ||
| y_measurement_node = pauli_demo_graph.add_physical_node() # Y measurement: YZ plane, θ=π/2 | ||
| z_measurement_node = pauli_demo_graph.add_physical_node() # Z measurement: XZ plane, θ=π | ||
|
|
||
| # Set Pauli measurement bases | ||
| pauli_demo_graph.assign_meas_basis(pauli_input, AxisMeasBasis(Axis.X, Sign.PLUS)) # X+ | ||
| pauli_demo_graph.assign_meas_basis(x_measurement_node, AxisMeasBasis(Axis.X, Sign.PLUS)) # X+ | ||
| pauli_demo_graph.assign_meas_basis(y_measurement_node, AxisMeasBasis(Axis.Y, Sign.PLUS)) # Y+ | ||
| pauli_demo_graph.assign_meas_basis(z_measurement_node, AxisMeasBasis(Axis.Z, Sign.MINUS)) # Z- | ||
|
|
||
| # Add output node | ||
| pauli_output = pauli_demo_graph.add_physical_node() | ||
| pauli_demo_graph.register_output(pauli_output, 0) | ||
|
|
||
| # Connect nodes | ||
| pauli_demo_graph.add_physical_edge(pauli_input, x_measurement_node) | ||
| pauli_demo_graph.add_physical_edge(x_measurement_node, y_measurement_node) | ||
| pauli_demo_graph.add_physical_edge(y_measurement_node, z_measurement_node) | ||
| pauli_demo_graph.add_physical_edge(z_measurement_node, pauli_output) | ||
|
|
||
| print("\\nPauli measurement demo graph:") | ||
| print(f"Input nodes: {list(pauli_demo_graph.input_node_indices.keys())}") | ||
| print(f"Output nodes: {list(pauli_demo_graph.output_node_indices.keys())}") | ||
| print("Pauli measurement nodes (will show bordered patterns):") | ||
| print(" - X measurement (θ=0°): Green center + Blue border (XY+XZ planes)") | ||
| print(" - Y measurement (θ=90°): Red center + Green border (YZ+XY planes)") | ||
| print(" - Z measurement (θ=180°): Blue center + Red border (XZ+YZ planes)") | ||
| print("Individual nodes:") | ||
| for node, basis in pauli_demo_graph.meas_bases.items(): | ||
| plane_name = basis.plane.name | ||
| angle_deg = basis.angle * 180 / np.pi | ||
| print(f" Node {node}: {plane_name} plane, angle={basis.angle:.3f} ({angle_deg:.1f}°)") | ||
|
|
||
| # Visualize the Pauli demo graph (using bordered-node visualization) | ||
| ax = visualize(pauli_demo_graph, show_node_labels=True) | ||
| plt.show() | ||
| print("Displayed Pauli demo graph") | ||
|
|
||
| # Demo with larger nodes and no labels | ||
| print("\n--- Larger nodes without labels ---") | ||
| ax = visualize(pauli_demo_graph, show_node_labels=False) | ||
| plt.show() | ||
| print("Displayed Pauli demo graph without labels") | ||
|
|
||
| # Demo without legend to avoid overlap | ||
| print("\n--- Without legend to avoid overlap ---") | ||
| ax = visualize(pauli_demo_graph, show_node_labels=True, show_legend=False) | ||
| plt.show() | ||
| print("Displayed Pauli demo graph without legend") | ||
|
|
||
| # %% |
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
Oops, something went wrong.
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.