-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Text circuit drawer #15357
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
base: main
Are you sure you want to change the base?
Text circuit drawer #15357
Conversation
…nger needed to import qiskit._accelerate, can simply call qc.draw(text2)
* Change the VisualizationElement::VerticalLine to hold a PackedInstruction reference * Fix capitalization of labels * Fix clippy * Correct drawing vertical line of a measure
This commit fixes several issues discovered via manual testing. Specifically: * Single bit wires - avoid printing `_1` for bits of length 1. For example `my_qr` instead of `my_qr_1` if `my_qr` is of length 1 * Changed some standard gate names to match those in the Python drawer * Count number of chars in label to account for Unicode chars properly when computing label length.
* Changed default names for qubit and clbit wires * Added support for anonymous bits * Fixed a bug with mapping clbit indices to `VisualizationMatrix` wires when `cregbunde=true`
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
|
|
Pull Request Test Coverage Report for Build 19755751808Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Summary
This PR addresses the feature request in #14713 and adds a draw function to rust which takes in
&CircuitDatatype to give an ASCII art string representation for its visualisation. It currently focuses only on drawingStandardInstruction,StandardGateandUnitaryvariants of thePackedOperationand is being added as a standalone feature rather than replacing the entire TextDrawer from the python space.VisualizationMatrix,VisualizationLayerstruct andVisualizationElementenum are introduced to create a logical 2D matrix representation of the circuit instructions for visualization.fn build_layers(dag: &DAGCircuit) -> Vec<Vec<NodeIndex>>: This function is used to divide theNodeIndexof aDAGCircuitinto layers so that when they are visualised, there are no instructions with overlapping wires.fn get_instruction_range(...) -> (usize, usize): This function provides with range of indices of wires that will be affected by an instruction when it is visualised. It is used inbuild_layerto avoid overlapping of visualised instructions.Please note that these layers are purely for visualization.
NodeIndexelementsbuild_layersout , that might be topologically the same, will most likely be in different layers, as their respective instructions act on intersecting ranges.The
VisualizationMatrixis an intermediate representation that handles all the logic mappings of instructions for visualization. This is then used to build another data struct,TextDrawerthat handles all the string operations to create the final ASCII string art.The
TextDrawerhas adraw_elementmethod which gives the correspondingTextWireElementfor aVisualizationElement. TheTextDrawerstruct holds the 2D String representation which can then be printed using the.draw()method.Code flow
CircuitDatawhich is used to create theVisualizationMatrix. Specifically for thebuild_layersfunction,CircuitDatais converted toDAGCircuitbuild_layersis used inVisualizationMatrix::from_circuit()to construct theVisualizationMatrixfor the input circuitVisualizationMatrixis a logicalVisualizationLayer. This is a column based representation.VisualizationElement. These enums ultimately hold a reference toPackedInstruction.VisualizationMatrixis created, it is then used to createTextDrawer, which holds a row based representation for the circuit. These rows represent the wires for each qubit and clbit/register based on ifcregbundleis true or not.TextDrawer, after which it returns the string. At this point it is ready for printing.