-
Notifications
You must be signed in to change notification settings - Fork 22
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
Replace pygraphviz
with graphviz
#80
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c43b520
delete used lines
chensgit169 03904c4
Merge branch 'master' of https://github.com/chensgit169/pyquafu
chensgit169 40d2420
Merge branch 'master' of https://github.com/chensgit169/pyquafu
chensgit169 35874ae
specify typing of oracle gate_structure
chensgit169 74c4bb2
add draw_dag.py
chensgit169 902bd08
delete ``pprint`` in task by mistake
chensgit169 1a30464
move function of draw_dag() from ``dagcircuit`` into ``visualization``
chensgit169 efd9ca8
remove dependence of pygraphviz, use graphviz instead
chensgit169 91319d6
add TODO in draw_dag()
chensgit169 e067d56
update explanation for ``graphviz`` in README
chensgit169 8207b7c
correct graphviz version requirement
chensgit169 a5162f0
update format and filename setting supports
chensgit169 9da64fc
update docstring
chensgit169 f2f85f6
delete ``verbose`` in send()
chensgit169 fc71e32
Merge remote-tracking branch 'origin/master'
chensgit169 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 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 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 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 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 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 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 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,55 @@ | ||
import graphviz | ||
|
||
from quafu import QuantumCircuit | ||
from quafu.dagcircuits.circuit_dag import circuit_to_dag | ||
from quafu.dagcircuits.instruction_node import InstructionNode | ||
|
||
from typing import Union, Any | ||
|
||
|
||
def _extract_node_info(node): | ||
if isinstance(node, InstructionNode): | ||
name, label = str(id(node)), str(node) | ||
else: | ||
assert node == -1 or node == float("inf") | ||
name, label = str(node), str(node) | ||
return name, label | ||
|
||
|
||
def draw_dag(qc: Union[QuantumCircuit, None], | ||
dag: Any = None, | ||
output_format: str = 'pdf', | ||
output_filename: str = 'DAG'): | ||
""" | ||
TODO: complete docstring, test supports for notebook | ||
|
||
Helper function to visualize the DAG | ||
|
||
Args: | ||
qc (QuantumCircuit): pyquafu quantum circuit if provided | ||
dag (DAG): DAG object with nodes and edges, built from qc if not provided | ||
output_format (str): output format, including "png", "svg", "pdf"... | ||
output_filename (str): file name of generated image | ||
|
||
Returns: | ||
dot: graphviz.Digraph object | ||
|
||
""" | ||
Zhaoyilunnn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if dag is None: | ||
assert qc is not None | ||
dag = circuit_to_dag(qc) | ||
|
||
dot = graphviz.Digraph(filename=output_filename) | ||
|
||
for node in dag.nodes: | ||
name, label = _extract_node_info(node) | ||
dot.node(name, label=label) | ||
|
||
for edge in dag.edges(data=True): | ||
node1, node2, link = edge | ||
name1, label1 = _extract_node_info(node1) | ||
name2, label2 = _extract_node_info(node2) | ||
dot.edge(name1, name2, label=link['label']) | ||
|
||
dot.render(format=output_format, cleanup=True) | ||
return dot |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that you want to use the verbose flag to control whether we print response, so you finally decide to remove this now? If so, maybe the verbose flag should be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I intended to help debug by setting
verbose=True
, yet it was not completed. Let's delete it for now. By the way I just noticed status_code in two level in master branch were not seperated yet?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is a mistake I made when I merge stable/0.3 branch into master. When resolving conflicts, I mistakenly removed the change in stable/0.3 branch and kept the master branch change. I will fix this later.