Skip to content

Commit

Permalink
Merge pull request #239 from gadhvirushiraj/dev-rushi
Browse files Browse the repository at this point in the history
Matplotlib based Circuit Rendering Module
  • Loading branch information
BoxiLi authored Aug 7, 2024
2 parents e393b43 + e6be0ed commit 1506d1c
Show file tree
Hide file tree
Showing 6 changed files with 1,247 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ instance/
# Scrapy stuff:
.scrapy

# vscode
.vscode

# Sphinx documentation
doc/_build/

Expand Down Expand Up @@ -128,4 +131,4 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
1 change: 1 addition & 0 deletions src/qutip_qip/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .circuit import *
from .circuitsimulator import *
from .mat_renderer import *
from ..operations import Gate, Measurement
from .texrenderer import *

Expand Down
12 changes: 10 additions & 2 deletions src/qutip_qip/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def add_gate(
classical_controls=None,
control_value=None,
classical_control_value=None,
style=None,
):
"""
Adds a gate with specified parameters to the circuit.
Expand Down Expand Up @@ -245,6 +246,7 @@ def add_gate(
classical_controls=classical_controls,
control_value=control_value,
classical_control_value=classical_control_value,
style=style,
)

if index is None:
Expand Down Expand Up @@ -968,19 +970,20 @@ def svg(self):

def draw(
self,
renderer="latex",
renderer="matplotlib",
file_type="png",
dpi=None,
file_name="exported_pic",
file_path="",
**kwargs,
):
"""
Export circuit object as an image file in a supported format.
Parameters
----------
renderer : choose the renderer for the circuit.
Default: 'latex'
Default: 'matplotlib'
file_type : Provide a supported image file_type eg: "svg"/"png".
Default : "png".
Expand Down Expand Up @@ -1010,6 +1013,11 @@ def draw(
os.path.join(file_path, file_name + "." + file_type), mode
) as f:
f.write(image_data)
elif renderer == "matplotlib":
from .mat_renderer import MatRenderer

mat = MatRenderer(self, **kwargs)
mat.canvas_plot()
else:
raise ValueError(
f"Unknown renderer '{renderer}' not supported. Please choose from 'latex', 'matplotlib', 'text'."
Expand Down
128 changes: 128 additions & 0 deletions src/qutip_qip/circuit/color_theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""
Color theme for different gates in the circuit diagram.
"""

qutip = {
"bgcolor": "#FFFFFF", # White
"color": "#FFFFFF", # White
"wire_color": "#000000", # Black
"default_gate": "#000000", # Black
"H": "#6270CE", # Medium Slate Blue
"SNOT": "#6270CE", # Medium Slate Blue
"X": "#CB4BF9", # Medium Orchid
"Y": "#CB4BF9", # Medium Orchid
"Z": "#CB4BF9", # Medium Orchid
"S": "#254065", # Dark Slate Blue
"T": "#254065", # Dark Slate Blue
"RX": "#5EBDF8", # Light Sky Blue
"RY": "#5EBDF8", # Light Sky Blue
"RZ": "#5EBDF8", # Light Sky Blue
"CNOT": "#3B3470", # Indigo
"CPHASE": "#456DB2", # Steel Blue
"TOFFOLI": "#3B3470", # Indigo
"SWAP": "#3B3470", # Indigo
"CX": "#9598F5", # Light Slate Blue
"CY": "#9598F5", # Light Slate Blue
"CZ": "#9598F5", # Light Slate Blue
"CS": "#9598F5", # Light Slate Blue
"CT": "#9598F5", # Light Slate Blue
"CRX": "#A66DDF", # Medium Purple
"CRY": "#A66DDF", # Medium Purple
"CRZ": "#A66DDF", # Medium Purple
"BERKELEY": "#7648CB", # Dark Orchid
"FREDKIN": "#7648CB", # Dark Orchid
}

light = {
"bgcolor": "#EEEEEE", # Light Gray
"color": "#000000", # Black
"wire_color": "#000000", # Black
"default_gate": "#D8CDAF", # Bit Dark Beige
"H": "#A3C1DA", # Light Blue
"SNOT": "#A3C1DA", # Light Blue
"X": "#F4A7B9", # Light Pink
"Y": "#F4A7B9", # Light Pink
"Z": "#F4A7B9", # Light Pink
"S": "#D3E2EE", # Very Light Blue
"T": "#D3E2EE", # Very Light Blue
"RX": "#B3E6E4", # Light Teal
"RY": "#B3E6E4", # Light Teal
"RZ": "#B3E6E4", # Light Teal
"CNOT": "#B7C9F2", # Light Indigo
"CPHASE": "#D5E0F2", # Light Slate Blue
"TOFFOLI": "#E6CCE6", # Soft Lavender
"SWAP": "#FFB6B6", # Lighter Coral Pink
"CX": "#E0E2F7", # Very Light Indigo
"CY": "#E0E2F7", # Very Light Indigo
"CZ": "#E0E2F7", # Very Light Indigo
"CS": "#E0E2F7", # Very Light Indigo
"CT": "#E0E2F7", # Very Light Indigo
"CRX": "#D6C9E8", # Light Muted Purple
"CRY": "#D6C9E8", # Light Muted Purple
"CRZ": "#D6C9E8", # Light Muted Purple
"BERKELEY": "#CDC1E8", # Light Purple
"FREDKIN": "#CDC1E8", # Light Purple
}

dark = {
"bgcolor": "#000000", # Black
"color": "#000000", # Black
"wire_color": "#989898", # Dark Gray
"default_gate": "#D8BFD8", # (Thistle)
"H": "#AFEEEE", # Pale Turquoise
"SNOT": "#AFEEEE", # Pale Turquoise
"X": "#9370DB", # Medium Purple
"Y": "#9370DB", # Medium Purple
"Z": "#9370DB", # Medium Purple
"S": "#B0E0E6", # Powder Blue
"T": "#B0E0E6", # Powder Blue
"RX": "#87CEEB", # Sky Blue
"RY": "#87CEEB", # Sky Blue
"RZ": "#87CEEB", # Sky Blue
"CNOT": "#6495ED", # Cornflower Blue
"CPHASE": "#8A2BE2", # Blue Violet
"TOFFOLI": "#DA70D6", # Orchid
"SWAP": "#BA55D3", # Medium Orchid
"CX": "#4682B4", # Steel Blue
"CY": "#4682B4", # Steel Blue
"CZ": "#4682B4", # Steel Blue
"CS": "#4682B4", # Steel Blue
"CT": "#4682B4", # Steel Blue
"CRX": "#7B68EE", # Medium Slate Blue
"CRY": "#7B68EE", # Medium Slate Blue
"CRZ": "#7B68EE", # Medium Slate Blue
"BERKELEY": "#6A5ACD", # Slate Blue
"FREDKIN": "#6A5ACD", # Slate Blue
}


modern = {
"bgcolor": "#FFFFFF", # White
"color": "#FFFFFF", # White
"wire_color": "#000000", # Black
"default_gate": "#ED9455", # Slate Orange
"H": "#C25454", # Soft Red
"SNOT": "#C25454", # Soft Red
"X": "#4A5D6D", # Dark Slate Blue
"Y": "#4A5D6D", # Dark Slate Blue
"Z": "#4A5D6D", # Dark Slate Blue
"S": "#2C3E50", # Very Dark Slate Blue
"T": "#2C3E50", # Very Dark Slate Blue
"RX": "#2F4F4F", # Dark Slate Teal
"RY": "#2F4F4F", # Dark Slate Teal
"RZ": "#2F4F4F", # Dark Slate Teal
"CNOT": "#4A6D7C", # Dark Slate Blue Gray
"CPHASE": "#5E7D8B", # Dark Slate Blue
"TOFFOLI": "#4A4A4A", # Dark Gray
"SWAP": "#6A9ACD", # Slate Blue
"CX": "#5D8AA8", # Medium Slate Blue
"CY": "#5D8AA8", # Medium Slate Blue
"CZ": "#5D8AA8", # Medium Slate Blue
"CS": "#5D8AA8", # Medium Slate Blue
"CT": "#5D8AA8", # Medium Slate Blue
"CRX": "#6C5B7B", # Dark Lavender
"CRY": "#6C5B7B", # Dark Lavender
"CRZ": "#6C5B7B", # Dark Lavender
"BERKELEY": "#4A5D6D", # Dark Slate Blue
"FREDKIN": "#4A5D6D", # Dark Slate Blue
}
Loading

0 comments on commit 1506d1c

Please sign in to comment.