From 14b8f85ee5bb59ad2ea09760ad749ca59695bc37 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 7 Nov 2024 13:02:38 +0000 Subject: [PATCH 01/41] Color wires changes. wires are coloured used by default when the diagram has frames but can be turned off using flag `color_wires=False` --- lambeq/backend/drawing/drawable.py | 92 ++++++++++++++++++++--- lambeq/backend/drawing/drawing.py | 64 ++++++++++++++-- lambeq/backend/drawing/drawing_backend.py | 28 ++++++- lambeq/backend/drawing/mat_backend.py | 21 +++++- 4 files changed, 184 insertions(+), 21 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 3abe57c7..4c3d0bc4 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -95,7 +95,7 @@ class WireEndpoint: x: float y: float - + color: int = 0 # New attribute for wire noun parent: Optional['BoxNode'] = None @property @@ -345,7 +345,8 @@ def _add_box(self, box: grammar.Box, off: int, x_pos: float, - y_pos: float) -> tuple[list[int], int]: + y_pos: float, + input_nouns: list[str]=None) -> tuple[list[int], int, list[str]]: """Add a box to the graph, creating necessary wire endpoints. Returns @@ -354,25 +355,63 @@ def _add_box(self, The new scan of wire endpoints after adding the box box_ind : int The index of the newly added `BoxNode` + list[int] + The new order of input_nouns after adding the box """ node = BoxNode(box, x_pos, y_pos) box_ind = self._add_boxnode(node) + num_input = len(box.dom) + for i in range(num_input): + if i < len(input_nouns): + pass + else: + # If we run out of input nouns, generate new ones + new_color = self.get_noun_id() + input_nouns.append(new_color) # Create a node representing each element in the box's domain for i, obj in enumerate(box.dom): + idx = off + i nbr_idx = scan[off + i] + noun_id = input_nouns[idx] if input_nouns and idx < len( + input_nouns) else DrawableDiagramWithFrames.get_noun_id() # Default to black if no input color available + wire_end = WireEndpoint(WireEndpointType.DOM, obj=obj, x=self.wire_endpoints[nbr_idx].x, - y=y_pos + HALF_BOX_HEIGHT) + y=y_pos + HALF_BOX_HEIGHT, + color=noun_id) wire_idx = self._add_wire_end(wire_end) node.add_dom_wire(wire_idx) self._add_wire(nbr_idx, wire_idx) scan_insert = [] - + # if Swap, exchange the noun_ids + if isinstance(box, grammar.Swap): + if input_nouns and len(box.dom) > 1: + dom_idx_1 = off + dom_idx_2 = off + 1 + input_nouns[dom_idx_1], input_nouns[dom_idx_2] = input_nouns[dom_idx_2], input_nouns[dom_idx_1] + # if Spider, expand or shrink the noun_ids based on type + elif isinstance(node.obj, grammar.Spider): + if len(box.dom) == 1 and len(box.cod) > 1: + dom_noun = input_nouns[off] if input_nouns and off < len(input_nouns) else DrawableDiagramWithFrames.get_noun_id() + expanded_colors = [dom_noun] * len(box.cod) + input_nouns = input_nouns[:off] + expanded_colors + input_nouns[off + len(box.dom):] + elif len(box.dom) > 1 and len(box.cod) == 1: + cod_noun = input_nouns[off] if input_nouns and off < len(input_nouns) else DrawableDiagramWithFrames.get_noun_id() + input_nouns = input_nouns[:off] + [cod_noun] + input_nouns[off + len(box.dom):] + + num_output = off+len(box.cod) + for i in range(num_output): + if i < len(input_nouns): + pass + else: + # If we run out of input nouns, generate new ones + new_color = self.get_noun_id() + input_nouns.append(new_color) # Create a node representing each element in the box's codomain for i, obj in enumerate(box.cod): @@ -383,18 +422,20 @@ def _add_box(self, else: x = x_pos + X_SPACING * (i - len(box.cod[1:]) / 2) y = y_pos - HALF_BOX_HEIGHT - + idx = off + i + noun_id = input_nouns[idx] if input_nouns and idx < len(input_nouns) else DrawableDiagramWithFrames.get_noun_id() wire_end = WireEndpoint(WireEndpointType.COD, obj=obj, x=x, - y=y) + y=y, + color=noun_id) wire_idx = self._add_wire_end(wire_end) scan_insert.append(wire_idx) node.add_cod_wire(wire_idx) # Replace node's dom with its cod in scan - return scan[:off] + scan_insert + scan[off + len(box.dom):], box_ind + return scan[:off] + scan_insert + scan[off + len(box.dom):], box_ind, input_nouns def _find_box_edges(self, box: grammar.Box, @@ -778,7 +819,8 @@ class DrawableDiagramWithFrames(DrawableDiagram): frame, carrying all information necessary to render it. """ - + #add counter for Nouns + noun_id_counter = 0 def _make_space(self, scan: list[int], box: grammar.Box, @@ -949,6 +991,15 @@ def calculate_bounds(self) -> tuple[float, float, float, float]: return min(all_xs), min(all_ys), max(all_xs), max(all_ys) + + @staticmethod + def get_noun_id() -> int: + """Generate a new numerical ID for the noun box/wire.""" + # Increment and return the next available ID + noun_id = DrawableDiagramWithFrames.noun_id_counter + DrawableDiagramWithFrames.noun_id_counter += 1 + return noun_id + @classmethod def from_diagram(cls, diagram: grammar.Diagram, @@ -976,12 +1027,19 @@ def from_diagram(cls, drawable = cls() scan = [] + # Generate unique noun_ids for input wires + num_input = len(diagram.dom) + input_nouns = [] + for i in range(num_input): + new_color = drawable.get_noun_id() + input_nouns.append(new_color) for i, obj in enumerate(diagram.dom): wire_end = WireEndpoint(WireEndpointType.INPUT, obj=obj, x=X_SPACING * i, - y=1) + y=1, + color=input_nouns[i]) wire_end_idx = drawable._add_wire_end(wire_end) scan.append(wire_end_idx) @@ -993,7 +1051,7 @@ def from_diagram(cls, # TODO: Debug issues with y coord x, y = drawable._make_space(scan, box, off, foliated=foliated) - scan, box_ind = drawable._add_box(scan, box, off, x, y) + scan, box_ind, input_nouns = drawable._add_box(scan, box, off, x, y, input_nouns) box_height = BOX_HEIGHT # Add drawables for the inside of the frame if isinstance(box, grammar.Frame): @@ -1004,12 +1062,24 @@ def from_diagram(cls, max_box_half_height = max(max_box_half_height, (box_height / 2)) min_y = min(min_y, y) + num_output = len(diagram.cod) + output_nouns = [] + # Match output nouns with input nouns as much as possible + for i in range(num_output): + if i < len(input_nouns): + pass + else: + # If we run out of input nouns, generate new ones + new_color = drawable.get_noun_id() + input_nouns.append(new_color) + for i, obj in enumerate(diagram.cod): wire_end = WireEndpoint( WireEndpointType.OUTPUT, obj=obj, x=drawable.wire_endpoints[scan[i]].x, - y=min_y - max_box_half_height - 1.5 * BOX_HEIGHT + y=min_y - max_box_half_height - 1.5 * BOX_HEIGHT, + color=input_nouns[i] ) wire_end_idx = drawable._add_wire_end(wire_end) drawable._add_wire(scan[i], wire_end_idx) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index bf85b75b..222e44b3 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -40,7 +40,8 @@ DEFAULT_ASPECT, DEFAULT_MARGINS, DrawingBackend, - FRAME_COLORS) + FRAME_COLORS, + WIRE_COLORS) from lambeq.backend.drawing.helpers import drawn_as_spider, needs_asymmetry from lambeq.backend.drawing.mat_backend import MatBackend from lambeq.backend.drawing.text_printer import PregroupTextPrinter @@ -110,6 +111,9 @@ def draw(diagram: Diagram, **params) -> None: params['coloring_mode'] = params.get( 'coloring_mode', ColoringMode.TYPE, ) + params['color_wires'] = params.get( + 'color_wires', diagram.has_frames, + ) if drawable is None: drawable = drawable_cls.from_diagram(diagram, params.get('foliated', False)) @@ -144,10 +148,11 @@ def draw(diagram: Diagram, **params) -> None: backend = _draw_controlled_gate(backend, drawable, node, **params) elif not drawn_as_spider(node.obj): backend = _draw_box(backend, drawable, node, **params) - + else: + wire_drawings = compute_spider_wires(node, drawable, **params) + backend.draw_spider(node,wire_drawings,**params) # Draw boxes first since they are filled backend = _draw_wires(backend, drawable, **params) - backend.draw_spiders(drawable, **params) backend.output( path=params.get('path', None), baseline=0, @@ -155,6 +160,44 @@ def draw(diagram: Diagram, **params) -> None: show=params.get('show', True), margins=params.get('margins', DEFAULT_MARGINS)) +def compute_spider_wires(node, drawable, **params)-> list: + """ + Compute the wire drawing requirements for spider. + + Computes all the wires (dom and cod) that need to be drawn for spider + and returns a list of wires. + """ + wire_color = 'black' + wire_drawings = [] + # Compute wires for cod_wires (outgoing wires) + for wire in node.cod_wires: + start_coordinates = node.coordinates + end_coordinates = drawable.wire_endpoints[wire].coordinates + if params['color_wires']: + wire_color = WIRE_COLORS[(drawable.wire_endpoints[wire].color - 1) % len(WIRE_COLORS)] + wire_drawings.append({ + 'start': start_coordinates, + 'end': end_coordinates, + 'bend_out': True, + 'is_leg': True, + 'color': wire_color + }) + + # Compute wires for dom_wires (incoming wires) + for wire in node.dom_wires: + start_coordinates = drawable.wire_endpoints[wire].coordinates + end_coordinates = node.coordinates + if params['color_wires']: + wire_color = WIRE_COLORS[(drawable.wire_endpoints[wire].color - 1) % len(WIRE_COLORS)] + wire_drawings.append({ + 'start': start_coordinates, + 'end': end_coordinates, + 'bend_in': True, + 'is_leg': True, + 'color': wire_color + }) + + return wire_drawings def draw_pregroup(diagram: Diagram, **params) -> None: """ Draw a pregroup grammar diagram. @@ -458,7 +501,9 @@ def _get_box_color(box: grammar.Diagrammable, color = FRAME_COLORS[(frame_attr - 1) % len(FRAME_COLORS)] return color - +def _get_wire_color(wire_id): + wire_color = WIRE_COLORS[(wire_id - 1) % len(WIRE_COLORS)] + return wire_color def _draw_pregroup_state(backend: DrawingBackend, drawable_box: BoxNode, @@ -524,9 +569,16 @@ def _draw_wires(backend: DrawingBackend, for src_idx, tgt_idx in drawable_diagram.wires: source = drawable_diagram.wire_endpoints[src_idx] target = drawable_diagram.wire_endpoints[tgt_idx] - + wire_color = 'black' + if params['color_wires']: + # Determine the color based on the type of the source + if source.kind in {WireEndpointType.INPUT}: + wire_color_id = source.color + else: + wire_color_id = target.color + wire_color = _get_wire_color(wire_color_id) backend.draw_wire( - source.coordinates, target.coordinates) + source.coordinates, target.coordinates, color=wire_color) if (params.get('draw_type_labels', True) and source.kind in {WireEndpointType.INPUT, WireEndpointType.COD}): diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index c99b24f3..e49a2e3c 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -30,6 +30,15 @@ DEFAULT_MARGINS = (.05, .1) DEFAULT_ASPECT = 'equal' +WIRE_COLORS = [ + "#A22417", "#D17800", "#F4A940", "#49A141", "#007765", + "#398889", "#0252A1", "#3831A0","#A629B3", "#B60539", + "#73190E", "#BE660F", "#F29A3B", "#3C8331", "#01594C", + "#2F7173", "#013B73", "#292372", "#271296", "#9526AF", + "#960131", "#450D06", "#9C540E", "#F07E33", "#003C33", + "#205356", "#002B54", "#201B5B", "#1D0B66", "#751FA5" +] + FRAME_COLORS: list[str] = [ '#fbe8e7', '#fee1ba', '#fff9e5', '#e8f8ea', '#dcfbf5', @@ -146,7 +155,8 @@ def draw_wire(self, bend_out: bool = False, bend_in: bool = False, is_leg: bool = False, - style: str | None = None) -> None: + style: str | None = None, + color: str = 'black') -> None: """ Draws a wire from source to target, possibly with a curve @@ -184,6 +194,22 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: """ + @abstractmethod + def draw_spider(self, node, wire_drawings, **params) -> None: + """ + Draws the spider node with the list of wires. + + Parameters + ---------- + node: DrawableDiagram + the node to be drawn. + wire_drawings: list of wires + list of wires in the spider + params: any + Additional parameters. + + """ + @abstractmethod def output(self, path: str | None = None, diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index 8392d16c..30e901ac 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -71,11 +71,12 @@ def draw_wire(self, bend_out: bool = False, bend_in: bool = False, is_leg: bool = False, - style: str | None = None) -> None: + style: str | None = None, + color: str = 'black') -> None: if style == '->': self.axis.arrow( *(source + (target[0] - source[0], target[1] - source[1])), - head_width=.02, color='black') + head_width=.02, color=color) else: if is_leg: mid = (target[0], source[1]) @@ -107,7 +108,7 @@ def draw_wire(self, ]) self.axis.add_patch(PathPatch( - path, facecolor='none', linewidth=self.linewidth)) + path, facecolor='none', linewidth=self.linewidth, edgecolor=color)) self.max_width = max(self.max_width, source[0], target[0]) @@ -128,6 +129,20 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: bend_in=True, is_leg=True) + def draw_spider(self, node, wire_drawings, **params) -> None: + if isinstance(node.obj, Spider): + self.draw_node(*node.coordinates, **params) + + for wire in wire_drawings: + self.draw_wire( + wire['start'], + wire['end'], + bend_out=wire.get('bend_out', False), + bend_in=wire.get('bend_in', False), + is_leg=wire['is_leg'], + color=wire['color'] + ) + def output(self, path: str | None = None, show: bool = True, From 0b3f2752dea092212af08b814cc44c12bcfb34f6 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 8 Nov 2024 10:45:32 +0000 Subject: [PATCH 02/41] review comments fixes, remove colors looks like similar --- lambeq/backend/drawing/drawable.py | 13 ++--- lambeq/backend/drawing/drawing.py | 63 +++++------------------ lambeq/backend/drawing/drawing_backend.py | 34 ++++++------ lambeq/backend/drawing/mat_backend.py | 30 ++++------- 4 files changed, 47 insertions(+), 93 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 4c3d0bc4..e88688d6 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -95,7 +95,7 @@ class WireEndpoint: x: float y: float - color: int = 0 # New attribute for wire noun + noun_id: int = 0 # New attribute for wire noun parent: Optional['BoxNode'] = None @property @@ -381,7 +381,7 @@ def _add_box(self, obj=obj, x=self.wire_endpoints[nbr_idx].x, y=y_pos + HALF_BOX_HEIGHT, - color=noun_id) + noun_id=noun_id) wire_idx = self._add_wire_end(wire_end) node.add_dom_wire(wire_idx) @@ -428,7 +428,7 @@ def _add_box(self, obj=obj, x=x, y=y, - color=noun_id) + noun_id=noun_id) wire_idx = self._add_wire_end(wire_end) scan_insert.append(wire_idx) @@ -820,7 +820,7 @@ class DrawableDiagramWithFrames(DrawableDiagram): """ #add counter for Nouns - noun_id_counter = 0 + noun_id_counter = 1 def _make_space(self, scan: list[int], box: grammar.Box, @@ -1039,7 +1039,7 @@ def from_diagram(cls, obj=obj, x=X_SPACING * i, y=1, - color=input_nouns[i]) + noun_id=input_nouns[i]) wire_end_idx = drawable._add_wire_end(wire_end) scan.append(wire_end_idx) @@ -1079,7 +1079,7 @@ def from_diagram(cls, obj=obj, x=drawable.wire_endpoints[scan[i]].x, y=min_y - max_box_half_height - 1.5 * BOX_HEIGHT, - color=input_nouns[i] + noun_id=input_nouns[i] ) wire_end_idx = drawable._add_wire_end(wire_end) drawable._add_wire(scan[i], wire_end_idx) @@ -1454,6 +1454,7 @@ def _merge_with(self, drawable: 'DrawableDiagramWithFrames') -> None: last_wire_endpoint = len(self.wire_endpoints) for wire_endpoint in drawable.wire_endpoints: + # wire_endpoint.noun_id = 0 self.wire_endpoints.append(wire_endpoint) for box in drawable.boxes: diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 783f3dfd..1df272c4 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -148,11 +148,10 @@ def draw(diagram: Diagram, **params) -> None: backend = _draw_controlled_gate(backend, drawable, node, **params) elif not drawn_as_spider(node.obj): backend = _draw_box(backend, drawable, node, **params) - else: - wire_drawings = compute_spider_wires(node, drawable, **params) - backend.draw_spider(node,wire_drawings,**params) + # Draw boxes first since they are filled backend = _draw_wires(backend, drawable, **params) + backend.draw_spiders(drawable, **params) backend.output( path=params.get('path', None), baseline=0, @@ -160,44 +159,6 @@ def draw(diagram: Diagram, **params) -> None: show=params.get('show', True), margins=params.get('margins', DEFAULT_MARGINS)) -def compute_spider_wires(node, drawable, **params)-> list: - """ - Compute the wire drawing requirements for spider. - - Computes all the wires (dom and cod) that need to be drawn for spider - and returns a list of wires. - """ - wire_color = 'black' - wire_drawings = [] - # Compute wires for cod_wires (outgoing wires) - for wire in node.cod_wires: - start_coordinates = node.coordinates - end_coordinates = drawable.wire_endpoints[wire].coordinates - if params['color_wires']: - wire_color = WIRE_COLORS[(drawable.wire_endpoints[wire].color - 1) % len(WIRE_COLORS)] - wire_drawings.append({ - 'start': start_coordinates, - 'end': end_coordinates, - 'bend_out': True, - 'is_leg': True, - 'color': wire_color - }) - - # Compute wires for dom_wires (incoming wires) - for wire in node.dom_wires: - start_coordinates = drawable.wire_endpoints[wire].coordinates - end_coordinates = node.coordinates - if params['color_wires']: - wire_color = WIRE_COLORS[(drawable.wire_endpoints[wire].color - 1) % len(WIRE_COLORS)] - wire_drawings.append({ - 'start': start_coordinates, - 'end': end_coordinates, - 'bend_in': True, - 'is_leg': True, - 'color': wire_color - }) - - return wire_drawings def draw_pregroup(diagram: Diagram, **params) -> None: """ Draw a pregroup grammar diagram. @@ -501,9 +462,13 @@ def _get_box_color(box: grammar.Diagrammable, color = FRAME_COLORS[(frame_attr - 1) % len(FRAME_COLORS)] return color + def _get_wire_color(wire_id): - wire_color = WIRE_COLORS[(wire_id - 1) % len(WIRE_COLORS)] - return wire_color + if wire_id == 0: + return '#000000' + else: + wire_color = WIRE_COLORS[(wire_id - 1) % len(WIRE_COLORS)] + return wire_color def _draw_pregroup_state(backend: DrawingBackend, drawable_box: BoxNode, @@ -569,16 +534,16 @@ def _draw_wires(backend: DrawingBackend, for src_idx, tgt_idx in drawable_diagram.wires: source = drawable_diagram.wire_endpoints[src_idx] target = drawable_diagram.wire_endpoints[tgt_idx] - wire_color = 'black' - if params['color_wires']: + wire_color_id = 0 + if params.get('color_wires'): # Determine the color based on the type of the source if source.kind in {WireEndpointType.INPUT}: - wire_color_id = source.color + wire_color_id = source.noun_id else: - wire_color_id = target.color - wire_color = _get_wire_color(wire_color_id) + wire_color_id = target.noun_id + # print('wire', wire_color_id) backend.draw_wire( - source.coordinates, target.coordinates, color=wire_color) + source.coordinates, target.coordinates, color_id=wire_color_id, **params) if (params.get('draw_type_labels', True) and source.kind in {WireEndpointType.INPUT, WireEndpointType.COD}): diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index e49a2e3c..b3c3df70 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -31,12 +31,12 @@ DEFAULT_ASPECT = 'equal' WIRE_COLORS = [ - "#A22417", "#D17800", "#F4A940", "#49A141", "#007765", - "#398889", "#0252A1", "#3831A0","#A629B3", "#B60539", - "#73190E", "#BE660F", "#F29A3B", "#3C8331", "#01594C", - "#2F7173", "#013B73", "#292372", "#271296", "#9526AF", - "#960131", "#450D06", "#9C540E", "#F07E33", "#003C33", - "#205356", "#002B54", "#201B5B", "#1D0B66", "#751FA5" + '#9c540e', '#f07e33', '#1d0b66', '#751fa5', '#740127', + '#a22417', '#d03b2d', '#fe9100', '#f8c84b', '#5ac358', + '#018c76', '#450d06', '#066ee2', '#574cfa', '#7446f2', + '#c330b9', '#e2074c', '#d17800', '#f4a940', '#49a141', + '#007765', '#398889', '#0252a1', '#3831a0', '#271296', + '#a629b3', '#b60539' '#3c8331', '#fea431', '#73b8fd' ] @@ -156,7 +156,8 @@ def draw_wire(self, bend_in: bool = False, is_leg: bool = False, style: str | None = None, - color: str = 'black') -> None: + color_id: int = 0, + **params)-> None: """ Draws a wire from source to target, possibly with a curve @@ -194,21 +195,16 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: """ - @abstractmethod - def draw_spider(self, node, wire_drawings, **params) -> None: + def _get_wire_color(self, wire_id, **params): """ - Draws the spider node with the list of wires. - - Parameters - ---------- - node: DrawableDiagram - the node to be drawn. - wire_drawings: list of wires - list of wires in the spider - params: any - Additional parameters. """ + print('wire_id-->', wire_id) + if not params.get('color_wires') or wire_id == 0: + return '#000000' + else: + wire_color = WIRE_COLORS[(wire_id - 1) % len(WIRE_COLORS)] + return wire_color @abstractmethod def output(self, diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index 30e901ac..7c892edb 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -72,7 +72,9 @@ def draw_wire(self, bend_in: bool = False, is_leg: bool = False, style: str | None = None, - color: str = 'black') -> None: + color_id: int = 0, + **params) -> None: + color = self._get_wire_color(color_id, **params) if style == '->': self.axis.arrow( *(source + (target[0] - source[0], target[1] - source[1])), @@ -116,32 +118,22 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: nodes = [node for node in drawable.boxes if drawn_as_spider(node.obj)] for node in nodes: - if isinstance(node.obj, Spider): - self.draw_node(*node.coordinates, **params) + for wire in node.cod_wires: self.draw_wire(node.coordinates, drawable.wire_endpoints[wire].coordinates, bend_out=True, - is_leg=True) + is_leg=True, + color_id=drawable.wire_endpoints[wire].noun_id, **params) for wire in node.dom_wires: + print('wire->', drawable.wire_endpoints[wire].noun_id) self.draw_wire(drawable.wire_endpoints[wire].coordinates, node.coordinates, bend_in=True, - is_leg=True) - - def draw_spider(self, node, wire_drawings, **params) -> None: - if isinstance(node.obj, Spider): - self.draw_node(*node.coordinates, **params) - - for wire in wire_drawings: - self.draw_wire( - wire['start'], - wire['end'], - bend_out=wire.get('bend_out', False), - bend_in=wire.get('bend_in', False), - is_leg=wire['is_leg'], - color=wire['color'] - ) + is_leg=True, + color_id=drawable.wire_endpoints[wire].noun_id, **params) + if isinstance(node.obj, Spider): + self.draw_node(*node.coordinates, **params) def output(self, path: str | None = None, From 84b44565a6b898ffbfa2f9ae073ac5ef72ffdab4 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 8 Nov 2024 16:34:06 +0000 Subject: [PATCH 03/41] rearrange colors to avoid similar shades comes together --- lambeq/backend/drawing/drawing_backend.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index b3c3df70..d2fc9b94 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -31,12 +31,12 @@ DEFAULT_ASPECT = 'equal' WIRE_COLORS = [ - '#9c540e', '#f07e33', '#1d0b66', '#751fa5', '#740127', - '#a22417', '#d03b2d', '#fe9100', '#f8c84b', '#5ac358', - '#018c76', '#450d06', '#066ee2', '#574cfa', '#7446f2', - '#c330b9', '#e2074c', '#d17800', '#f4a940', '#49a141', - '#007765', '#398889', '#0252a1', '#3831a0', '#271296', - '#a629b3', '#b60539' '#3c8331', '#fea431', '#73b8fd' + '#9c540e', '#d03b2d', '#066ee2', '#f4a940', '#271296', + '#f07e33', '#fe9100', '#574cfa', '#49a141', '#a629b3', + '#1d0b66', '#f8c84b', '#7446f2', '#007765', '#b60539', + '#751fa5', '#5ac358', '#c330b9', '#398889', '#3c8331', + '#740127', '#018c76', '#e2074c', '#0252a1', '#fea431', + '#a22417', '#450d06', '#d17800', '#3831a0', '#73b8fd' ] @@ -157,7 +157,7 @@ def draw_wire(self, is_leg: bool = False, style: str | None = None, color_id: int = 0, - **params)-> None: + **params) -> None: """ Draws a wire from source to target, possibly with a curve From 8b963d7a2c9d3da75d6bbc8b171067cbec3085da Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 8 Nov 2024 16:36:43 +0000 Subject: [PATCH 04/41] lint error fixes, flake8 fixes --- lambeq/backend/drawing/drawable.py | 64 ++++++++++++++--------- lambeq/backend/drawing/drawing.py | 6 ++- lambeq/backend/drawing/drawing_backend.py | 2 +- lambeq/backend/drawing/mat_backend.py | 11 ++-- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index e88688d6..6e14bfc3 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -95,7 +95,7 @@ class WireEndpoint: x: float y: float - noun_id: int = 0 # New attribute for wire noun + noun_id: int = 0 # New attribute for wire noun parent: Optional['BoxNode'] = None @property @@ -340,13 +340,15 @@ def _add_boxnode(self, box: BoxNode) -> int: self.boxes.append(box) return len(self.boxes) - 1 - def _add_box(self, - scan: list[int], - box: grammar.Box, - off: int, - x_pos: float, - y_pos: float, - input_nouns: list[str]=None) -> tuple[list[int], int, list[str]]: + def _add_box( + self, + scan: list[int], + box: grammar.Box, + off: int, + x_pos: float, + y_pos: float, + input_nouns: list[str] = None + ) -> tuple[list[int], int, list[str]]: """Add a box to the graph, creating necessary wire endpoints. Returns @@ -374,8 +376,10 @@ def _add_box(self, for i, obj in enumerate(box.dom): idx = off + i nbr_idx = scan[off + i] - noun_id = input_nouns[idx] if input_nouns and idx < len( - input_nouns) else DrawableDiagramWithFrames.get_noun_id() # Default to black if no input color available + noun_id = (input_nouns[idx] if input_nouns + and idx < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id() + ) # generate new noun id if needed wire_end = WireEndpoint(WireEndpointType.DOM, obj=obj, @@ -393,16 +397,25 @@ def _add_box(self, if input_nouns and len(box.dom) > 1: dom_idx_1 = off dom_idx_2 = off + 1 - input_nouns[dom_idx_1], input_nouns[dom_idx_2] = input_nouns[dom_idx_2], input_nouns[dom_idx_1] + input_nouns[dom_idx_1], input_nouns[dom_idx_2] \ + = (input_nouns[dom_idx_2], input_nouns[dom_idx_1]) # if Spider, expand or shrink the noun_ids based on type elif isinstance(node.obj, grammar.Spider): if len(box.dom) == 1 and len(box.cod) > 1: - dom_noun = input_nouns[off] if input_nouns and off < len(input_nouns) else DrawableDiagramWithFrames.get_noun_id() + dom_noun = (input_nouns[off] if input_nouns + and off < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id() + ) expanded_colors = [dom_noun] * len(box.cod) - input_nouns = input_nouns[:off] + expanded_colors + input_nouns[off + len(box.dom):] + input_nouns = (input_nouns[:off] + expanded_colors + + input_nouns[off + len(box.dom):]) elif len(box.dom) > 1 and len(box.cod) == 1: - cod_noun = input_nouns[off] if input_nouns and off < len(input_nouns) else DrawableDiagramWithFrames.get_noun_id() - input_nouns = input_nouns[:off] + [cod_noun] + input_nouns[off + len(box.dom):] + cod_noun = (input_nouns[off] if input_nouns + and off < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id() + ) + input_nouns = (input_nouns[:off] + [cod_noun] + + input_nouns[off + len(box.dom):]) num_output = off+len(box.cod) for i in range(num_output): @@ -423,7 +436,9 @@ def _add_box(self, x = x_pos + X_SPACING * (i - len(box.cod[1:]) / 2) y = y_pos - HALF_BOX_HEIGHT idx = off + i - noun_id = input_nouns[idx] if input_nouns and idx < len(input_nouns) else DrawableDiagramWithFrames.get_noun_id() + noun_id = (input_nouns[idx] if input_nouns + and idx < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id()) wire_end = WireEndpoint(WireEndpointType.COD, obj=obj, x=x, @@ -435,7 +450,8 @@ def _add_box(self, node.add_cod_wire(wire_idx) # Replace node's dom with its cod in scan - return scan[:off] + scan_insert + scan[off + len(box.dom):], box_ind, input_nouns + return (scan[:off] + scan_insert + scan[off + len(box.dom):], + box_ind, input_nouns) def _find_box_edges(self, box: grammar.Box, @@ -819,8 +835,9 @@ class DrawableDiagramWithFrames(DrawableDiagram): frame, carrying all information necessary to render it. """ - #add counter for Nouns + # add counter for Nouns noun_id_counter = 1 + def _make_space(self, scan: list[int], box: grammar.Box, @@ -991,7 +1008,6 @@ def calculate_bounds(self) -> tuple[float, float, float, float]: return min(all_xs), min(all_ys), max(all_xs), max(all_ys) - @staticmethod def get_noun_id() -> int: """Generate a new numerical ID for the noun box/wire.""" @@ -1031,8 +1047,8 @@ def from_diagram(cls, num_input = len(diagram.dom) input_nouns = [] for i in range(num_input): - new_color = drawable.get_noun_id() - input_nouns.append(new_color) + new_color = drawable.get_noun_id() + input_nouns.append(new_color) for i, obj in enumerate(diagram.dom): wire_end = WireEndpoint(WireEndpointType.INPUT, @@ -1051,7 +1067,8 @@ def from_diagram(cls, # TODO: Debug issues with y coord x, y = drawable._make_space(scan, box, off, foliated=foliated) - scan, box_ind, input_nouns = drawable._add_box(scan, box, off, x, y, input_nouns) + scan, box_ind, input_nouns = drawable._add_box(scan, box, off, + x, y, input_nouns) box_height = BOX_HEIGHT # Add drawables for the inside of the frame if isinstance(box, grammar.Frame): @@ -1063,7 +1080,6 @@ def from_diagram(cls, min_y = min(min_y, y) num_output = len(diagram.cod) - output_nouns = [] # Match output nouns with input nouns as much as possible for i in range(num_output): if i < len(input_nouns): @@ -1454,7 +1470,7 @@ def _merge_with(self, drawable: 'DrawableDiagramWithFrames') -> None: last_wire_endpoint = len(self.wire_endpoints) for wire_endpoint in drawable.wire_endpoints: - # wire_endpoint.noun_id = 0 + wire_endpoint.noun_id = 0 self.wire_endpoints.append(wire_endpoint) for box in drawable.boxes: diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 1df272c4..2d0fff1e 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -463,6 +463,7 @@ def _get_box_color(box: grammar.Diagrammable, return color + def _get_wire_color(wire_id): if wire_id == 0: return '#000000' @@ -470,6 +471,7 @@ def _get_wire_color(wire_id): wire_color = WIRE_COLORS[(wire_id - 1) % len(WIRE_COLORS)] return wire_color + def _draw_pregroup_state(backend: DrawingBackend, drawable_box: BoxNode, **params) -> DrawingBackend: @@ -542,8 +544,8 @@ def _draw_wires(backend: DrawingBackend, else: wire_color_id = target.noun_id # print('wire', wire_color_id) - backend.draw_wire( - source.coordinates, target.coordinates, color_id=wire_color_id, **params) + backend.draw_wire(source.coordinates, target.coordinates, + color_id=wire_color_id, **params) if (params.get('draw_type_labels', True) and source.kind in {WireEndpointType.INPUT, WireEndpointType.COD}): diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index d2fc9b94..388ac1a9 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -200,7 +200,7 @@ def _get_wire_color(self, wire_id, **params): """ print('wire_id-->', wire_id) - if not params.get('color_wires') or wire_id == 0: + if not params.get('color_wires') or wire_id == 0: return '#000000' else: wire_color = WIRE_COLORS[(wire_id - 1) % len(WIRE_COLORS)] diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index 7c892edb..7a173cec 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -109,8 +109,9 @@ def draw_wire(self, Path.CURVE3, ]) - self.axis.add_patch(PathPatch( - path, facecolor='none', linewidth=self.linewidth, edgecolor=color)) + self.axis.add_patch(PathPatch(path, facecolor='none', + linewidth=self.linewidth, + edgecolor=color)) self.max_width = max(self.max_width, source[0], target[0]) @@ -124,14 +125,16 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: drawable.wire_endpoints[wire].coordinates, bend_out=True, is_leg=True, - color_id=drawable.wire_endpoints[wire].noun_id, **params) + color_id=drawable.wire_endpoints[wire].noun_id, + **params) for wire in node.dom_wires: print('wire->', drawable.wire_endpoints[wire].noun_id) self.draw_wire(drawable.wire_endpoints[wire].coordinates, node.coordinates, bend_in=True, is_leg=True, - color_id=drawable.wire_endpoints[wire].noun_id, **params) + color_id=drawable.wire_endpoints[wire].noun_id, + **params) if isinstance(node.obj, Spider): self.draw_node(*node.coordinates, **params) From 885c9cbfe69d5edb0b7c3af29f69ddc32f01be51 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 8 Nov 2024 17:07:53 +0000 Subject: [PATCH 05/41] flake8 fixes --- lambeq/backend/drawing/drawable.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 6e14bfc3..27d13497 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -397,8 +397,8 @@ def _add_box( if input_nouns and len(box.dom) > 1: dom_idx_1 = off dom_idx_2 = off + 1 - input_nouns[dom_idx_1], input_nouns[dom_idx_2] \ - = (input_nouns[dom_idx_2], input_nouns[dom_idx_1]) + input_nouns[dom_idx_1], input_nouns[dom_idx_2] = ( + input_nouns[dom_idx_2], input_nouns[dom_idx_1]) # if Spider, expand or shrink the noun_ids based on type elif isinstance(node.obj, grammar.Spider): if len(box.dom) == 1 and len(box.cod) > 1: @@ -1046,7 +1046,7 @@ def from_diagram(cls, # Generate unique noun_ids for input wires num_input = len(diagram.dom) input_nouns = [] - for i in range(num_input): + for _ in range(num_input): new_color = drawable.get_noun_id() input_nouns.append(new_color) From 72b635f94b42d0fbecb8e2dddaca95e8286f33e1 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 14:36:29 +0000 Subject: [PATCH 06/41] inherit add_box to avoid side-effect in non-frame diagrams --- lambeq/backend/drawing/drawable.py | 194 +++++++++++++++++++---------- 1 file changed, 126 insertions(+), 68 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 27d13497..1505ba75 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -340,15 +340,12 @@ def _add_boxnode(self, box: BoxNode) -> int: self.boxes.append(box) return len(self.boxes) - 1 - def _add_box( - self, - scan: list[int], - box: grammar.Box, - off: int, - x_pos: float, - y_pos: float, - input_nouns: list[str] = None - ) -> tuple[list[int], int, list[str]]: + def _add_box(self, + scan: list[int], + box: grammar.Box, + off: int, + x_pos: float, + y_pos: float) -> tuple[list[int], int]: """Add a box to the graph, creating necessary wire endpoints. Returns @@ -357,74 +354,25 @@ def _add_box( The new scan of wire endpoints after adding the box box_ind : int The index of the newly added `BoxNode` - list[int] - The new order of input_nouns after adding the box """ node = BoxNode(box, x_pos, y_pos) box_ind = self._add_boxnode(node) - num_input = len(box.dom) - for i in range(num_input): - if i < len(input_nouns): - pass - else: - # If we run out of input nouns, generate new ones - new_color = self.get_noun_id() - input_nouns.append(new_color) # Create a node representing each element in the box's domain for i, obj in enumerate(box.dom): - idx = off + i nbr_idx = scan[off + i] - noun_id = (input_nouns[idx] if input_nouns - and idx < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id() - ) # generate new noun id if needed - wire_end = WireEndpoint(WireEndpointType.DOM, obj=obj, x=self.wire_endpoints[nbr_idx].x, - y=y_pos + HALF_BOX_HEIGHT, - noun_id=noun_id) + y=y_pos + HALF_BOX_HEIGHT) wire_idx = self._add_wire_end(wire_end) node.add_dom_wire(wire_idx) self._add_wire(nbr_idx, wire_idx) scan_insert = [] - # if Swap, exchange the noun_ids - if isinstance(box, grammar.Swap): - if input_nouns and len(box.dom) > 1: - dom_idx_1 = off - dom_idx_2 = off + 1 - input_nouns[dom_idx_1], input_nouns[dom_idx_2] = ( - input_nouns[dom_idx_2], input_nouns[dom_idx_1]) - # if Spider, expand or shrink the noun_ids based on type - elif isinstance(node.obj, grammar.Spider): - if len(box.dom) == 1 and len(box.cod) > 1: - dom_noun = (input_nouns[off] if input_nouns - and off < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id() - ) - expanded_colors = [dom_noun] * len(box.cod) - input_nouns = (input_nouns[:off] + expanded_colors - + input_nouns[off + len(box.dom):]) - elif len(box.dom) > 1 and len(box.cod) == 1: - cod_noun = (input_nouns[off] if input_nouns - and off < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id() - ) - input_nouns = (input_nouns[:off] + [cod_noun] - + input_nouns[off + len(box.dom):]) - num_output = off+len(box.cod) - for i in range(num_output): - if i < len(input_nouns): - pass - else: - # If we run out of input nouns, generate new ones - new_color = self.get_noun_id() - input_nouns.append(new_color) # Create a node representing each element in the box's codomain for i, obj in enumerate(box.cod): @@ -435,23 +383,18 @@ def _add_box( else: x = x_pos + X_SPACING * (i - len(box.cod[1:]) / 2) y = y_pos - HALF_BOX_HEIGHT - idx = off + i - noun_id = (input_nouns[idx] if input_nouns - and idx < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id()) + wire_end = WireEndpoint(WireEndpointType.COD, obj=obj, x=x, - y=y, - noun_id=noun_id) + y=y) wire_idx = self._add_wire_end(wire_end) scan_insert.append(wire_idx) node.add_cod_wire(wire_idx) # Replace node's dom with its cod in scan - return (scan[:off] + scan_insert + scan[off + len(box.dom):], - box_ind, input_nouns) + return scan[:off] + scan_insert + scan[off + len(box.dom):], box_ind def _find_box_edges(self, box: grammar.Box, @@ -900,6 +843,121 @@ def _make_space(self, return x, y + def _add_box( + self, + scan: list[int], + box: grammar.Box, + off: int, + x_pos: float, + y_pos: float, + input_nouns: list[str] = None + ) -> tuple[list[int], int, list[str]]: + """Add a box to the graph, creating necessary wire endpoints. + + Returns + ------- + list[int] + The new scan of wire endpoints after adding the box + box_ind : int + The index of the newly added `BoxNode` + list[int] + The new order of input_nouns after adding the box + """ + node = BoxNode(box, x_pos, y_pos) + + box_ind = self._add_boxnode(node) + num_input = len(box.dom) + input_nouns = input_nouns or [] + for i in range(num_input): + if i < len(input_nouns): + pass + else: + # If we run out of input nouns, generate new ones + new_color = self.get_noun_id() + input_nouns.append(new_color) + + # Create a node representing each element in the box's domain + for i, obj in enumerate(box.dom): + idx = off + i + nbr_idx = scan[off + i] + noun_id = (input_nouns[idx] if input_nouns + and idx < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id() + ) # generate new noun id if needed + + wire_end = WireEndpoint(WireEndpointType.DOM, + obj=obj, + x=self.wire_endpoints[nbr_idx].x, + y=y_pos + HALF_BOX_HEIGHT, + noun_id=noun_id) + + wire_idx = self._add_wire_end(wire_end) + node.add_dom_wire(wire_idx) + self._add_wire(nbr_idx, wire_idx) + + scan_insert = [] + # if Swap, exchange the noun_ids + if isinstance(box, grammar.Swap): + if input_nouns and len(box.dom) > 1: + dom_idx_1 = off + dom_idx_2 = off + 1 + input_nouns[dom_idx_1], input_nouns[dom_idx_2] = ( + input_nouns[dom_idx_2], input_nouns[dom_idx_1]) + # if Spider, expand or shrink the noun_ids based on type + elif isinstance(node.obj, grammar.Spider): + if len(box.dom) == 1 and len(box.cod) > 1: + dom_noun = (input_nouns[off] if input_nouns + and off < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id() + ) + expanded_colors = [dom_noun] * len(box.cod) + input_nouns = (input_nouns[:off] + expanded_colors + + input_nouns[off + len(box.dom):]) + elif len(box.dom) > 1 and len(box.cod) == 1: + cod_noun = (input_nouns[off] if input_nouns + and off < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id() + ) + input_nouns = (input_nouns[:off] + [cod_noun] + + input_nouns[off + len(box.dom):]) + + num_output = off+len(box.cod) + for i in range(num_output): + if i < len(input_nouns): + pass + else: + # If we run out of input nouns, generate new ones + new_color = self.get_noun_id() + input_nouns.append(new_color) + # Create a node representing each element in the box's codomain + for i, obj in enumerate(box.cod): + + # If the box is a quantum gate, retain x coordinate of wires + if box.category == quantum and len(box.dom) == len(box.cod): + nbr_idx = scan[off + i] + x = self.wire_endpoints[nbr_idx].x + else: + x = x_pos + X_SPACING * (i - len(box.cod[1:]) / 2) + y = y_pos - HALF_BOX_HEIGHT + idx = off + i + noun_id = (input_nouns[idx] if input_nouns + and idx < len(input_nouns) + else DrawableDiagramWithFrames.get_noun_id()) + wire_end = WireEndpoint(WireEndpointType.COD, + obj=obj, + x=x, + y=y, + noun_id=noun_id) + + wire_idx = self._add_wire_end(wire_end) + scan_insert.append(wire_idx) + node.add_cod_wire(wire_idx) + + # Replace node's dom with its cod in scan + return (scan[:off] + scan_insert + scan[off + len(box.dom):], + box_ind, input_nouns) + + def _make_space_for_frame(self, scan: list[int], off: int, @@ -1046,7 +1104,7 @@ def from_diagram(cls, # Generate unique noun_ids for input wires num_input = len(diagram.dom) input_nouns = [] - for _ in range(num_input): + for i in range(num_input): new_color = drawable.get_noun_id() input_nouns.append(new_color) From 9dbcc40cf9883a92b5311ab1da3ce65bc1d3a66d Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 14:37:24 +0000 Subject: [PATCH 07/41] remove debug logs --- lambeq/backend/drawing/drawing.py | 1 - lambeq/backend/drawing/drawing_backend.py | 1 - lambeq/backend/drawing/mat_backend.py | 1 - 3 files changed, 3 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 2d0fff1e..c4c27204 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -543,7 +543,6 @@ def _draw_wires(backend: DrawingBackend, wire_color_id = source.noun_id else: wire_color_id = target.noun_id - # print('wire', wire_color_id) backend.draw_wire(source.coordinates, target.coordinates, color_id=wire_color_id, **params) diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index 388ac1a9..04c97067 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -199,7 +199,6 @@ def _get_wire_color(self, wire_id, **params): """ """ - print('wire_id-->', wire_id) if not params.get('color_wires') or wire_id == 0: return '#000000' else: diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index 7a173cec..52062405 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -128,7 +128,6 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: color_id=drawable.wire_endpoints[wire].noun_id, **params) for wire in node.dom_wires: - print('wire->', drawable.wire_endpoints[wire].noun_id) self.draw_wire(drawable.wire_endpoints[wire].coordinates, node.coordinates, bend_in=True, From 3a8f66d83e5aaf31731f79665bab844039fac98b Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 14:38:55 +0000 Subject: [PATCH 08/41] add color params to draw method in Tikzit backend --- lambeq/backend/drawing/tikz_backend.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index dded2fa6..6f58b969 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -122,7 +122,11 @@ def draw_wire(self, bend_out: bool = False, bend_in: bool = False, is_leg: bool = False, - style: str | None = None) -> None: + style: str | None = None, + color_id: int = 0, + **params) -> None: + + color = self._get_wire_color(color_id, **params) out = (-90 if not bend_out or source[0] == target[0] else (180 if source[0] > target[0] else 0)) inp = (90 if not bend_in or source[0] == target[0] @@ -178,11 +182,15 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: for wire in node.cod_wires: self.draw_wire(node.coordinates, drawable.wire_endpoints[wire].coordinates, - bend_out=True) + bend_out=True, + color_id=drawable.wire_endpoints[wire].noun_id, + **params) for wire in node.dom_wires: self.draw_wire(drawable.wire_endpoints[wire].coordinates, node.coordinates, - bend_in=True) + bend_in=True, + color_id=drawable.wire_endpoints[wire].noun_id, + **params) def output(self, path=None, show=True, **params) -> None: baseline = params.get('baseline', 0) From 3ef64a5780896c8e41cf563a8df13be5fe5bf119 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 14:52:58 +0000 Subject: [PATCH 09/41] lint error fixes --- lambeq/backend/drawing/drawable.py | 5 ++--- lambeq/backend/drawing/tikz_backend.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 1505ba75..e43ed7f1 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -850,8 +850,8 @@ def _add_box( off: int, x_pos: float, y_pos: float, - input_nouns: list[str] = None - ) -> tuple[list[int], int, list[str]]: + input_nouns: list[int] = None + ) -> tuple[list[int], int, list[int]]: """Add a box to the graph, creating necessary wire endpoints. Returns @@ -957,7 +957,6 @@ def _add_box( return (scan[:off] + scan_insert + scan[off + len(box.dom):], box_ind, input_nouns) - def _make_space_for_frame(self, scan: list[int], off: int, diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 6f58b969..42cc4008 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -126,7 +126,7 @@ def draw_wire(self, color_id: int = 0, **params) -> None: - color = self._get_wire_color(color_id, **params) + # color = self._get_wire_color(color_id, **params) out = (-90 if not bend_out or source[0] == target[0] else (180 if source[0] > target[0] else 0)) inp = (90 if not bend_in or source[0] == target[0] From 1a1f2a04c8982adb4466a5e8a3d2248e6436375f Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 15:24:11 +0000 Subject: [PATCH 10/41] mypy suggestion fixes --- lambeq/backend/drawing/drawable.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index e43ed7f1..fb518ffd 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -843,14 +843,14 @@ def _make_space(self, return x, y - def _add_box( + def _add_box_with_nouns( self, scan: list[int], box: grammar.Box, off: int, x_pos: float, y_pos: float, - input_nouns: list[int] = None + input_nouns: list[int] = [] ) -> tuple[list[int], int, list[int]]: """Add a box to the graph, creating necessary wire endpoints. @@ -1103,7 +1103,7 @@ def from_diagram(cls, # Generate unique noun_ids for input wires num_input = len(diagram.dom) input_nouns = [] - for i in range(num_input): + for _ in range(num_input): new_color = drawable.get_noun_id() input_nouns.append(new_color) @@ -1124,8 +1124,8 @@ def from_diagram(cls, # TODO: Debug issues with y coord x, y = drawable._make_space(scan, box, off, foliated=foliated) - scan, box_ind, input_nouns = drawable._add_box(scan, box, off, - x, y, input_nouns) + scan, box_ind, input_nouns = drawable._add_box_with_nouns( + scan, box, off, x, y, input_nouns) box_height = BOX_HEIGHT # Add drawables for the inside of the frame if isinstance(box, grammar.Frame): From 94f6dbd0538b64f9b0030f9af3d5207343390daa Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 15:31:27 +0000 Subject: [PATCH 11/41] demo on simple-book notebook --- tests/backend/simple-books-frame-drawing.html | 8286 +++++++++++++++++ 1 file changed, 8286 insertions(+) create mode 100644 tests/backend/simple-books-frame-drawing.html diff --git a/tests/backend/simple-books-frame-drawing.html b/tests/backend/simple-books-frame-drawing.html new file mode 100644 index 00000000..f2dc8e24 --- /dev/null +++ b/tests/backend/simple-books-frame-drawing.html @@ -0,0 +1,8286 @@ + + + + + +simple-books-frame-drawing + + + + + + + + + + + + +
+
+ + From d89ec0c727b2dcd4f6794ec40ebbcff3c6008c99 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 15:39:19 +0000 Subject: [PATCH 12/41] change signature to fix flake8 error --- lambeq/backend/drawing/drawable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index fb518ffd..5e2ee534 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -850,7 +850,7 @@ def _add_box_with_nouns( off: int, x_pos: float, y_pos: float, - input_nouns: list[int] = [] + input_nouns: Optional[list[int]] ) -> tuple[list[int], int, list[int]]: """Add a box to the graph, creating necessary wire endpoints. From 8093b958ed6458704f262617246b26cb91456dca Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 11 Nov 2024 16:40:36 +0000 Subject: [PATCH 13/41] add doc strings to new functions --- lambeq/backend/drawing/drawable.py | 13 ++++++++++--- lambeq/backend/drawing/drawing_backend.py | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 5e2ee534..ac80b41a 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -856,11 +856,11 @@ def _add_box_with_nouns( Returns ------- - list[int] + list : int The new scan of wire endpoints after adding the box box_ind : int The index of the newly added `BoxNode` - list[int] + input_nouns : list[int] The new order of input_nouns after adding the box """ node = BoxNode(box, x_pos, y_pos) @@ -1067,7 +1067,14 @@ def calculate_bounds(self) -> tuple[float, float, float, float]: @staticmethod def get_noun_id() -> int: - """Generate a new numerical ID for the noun box/wire.""" + """Generate a new numerical ID for the noun box/wire. + + Returns + ------- + noun_id : int + returns a unique identifier for the noun wire/box + """ + # Increment and return the next available ID noun_id = DrawableDiagramWithFrames.noun_id_counter DrawableDiagramWithFrames.noun_id_counter += 1 diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index 04c97067..7863692a 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -195,8 +195,21 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: """ - def _get_wire_color(self, wire_id, **params): + def _get_wire_color(self, wire_id : int, **params) -> str: """ + Retrieves a color that uniquely represent a given wire ID. + + Parameters + ---------- + wire_id : int + The noun identifier of the wire for which the color is + being retrieved. + **params: + Additional parameters. + + Returns: + wire_color : str + The Hex color of the wire, represented as a string. """ if not params.get('color_wires') or wire_id == 0: From 69d983090c48c3cd70e67037a78da92b18286d5a Mon Sep 17 00:00:00 2001 From: ragunathc Date: Tue, 12 Nov 2024 15:48:37 +0000 Subject: [PATCH 14/41] make noun_id non-static variable --- lambeq/backend/drawing/drawable.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index ac80b41a..99fe9782 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -882,7 +882,7 @@ def _add_box_with_nouns( nbr_idx = scan[off + i] noun_id = (input_nouns[idx] if input_nouns and idx < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id() + else self.get_noun_id() ) # generate new noun id if needed wire_end = WireEndpoint(WireEndpointType.DOM, @@ -908,7 +908,7 @@ def _add_box_with_nouns( if len(box.dom) == 1 and len(box.cod) > 1: dom_noun = (input_nouns[off] if input_nouns and off < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id() + else self.get_noun_id() ) expanded_colors = [dom_noun] * len(box.cod) input_nouns = (input_nouns[:off] + expanded_colors @@ -916,7 +916,7 @@ def _add_box_with_nouns( elif len(box.dom) > 1 and len(box.cod) == 1: cod_noun = (input_nouns[off] if input_nouns and off < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id() + else self.get_noun_id() ) input_nouns = (input_nouns[:off] + [cod_noun] + input_nouns[off + len(box.dom):]) @@ -942,7 +942,7 @@ def _add_box_with_nouns( idx = off + i noun_id = (input_nouns[idx] if input_nouns and idx < len(input_nouns) - else DrawableDiagramWithFrames.get_noun_id()) + else self.get_noun_id()) wire_end = WireEndpoint(WireEndpointType.COD, obj=obj, x=x, @@ -1065,8 +1065,7 @@ def calculate_bounds(self) -> tuple[float, float, float, float]: return min(all_xs), min(all_ys), max(all_xs), max(all_ys) - @staticmethod - def get_noun_id() -> int: + def get_noun_id(self) -> int: """Generate a new numerical ID for the noun box/wire. Returns @@ -1076,8 +1075,8 @@ def get_noun_id() -> int: """ # Increment and return the next available ID - noun_id = DrawableDiagramWithFrames.noun_id_counter - DrawableDiagramWithFrames.noun_id_counter += 1 + noun_id = self.noun_id_counter + self.noun_id_counter += 1 return noun_id @classmethod From 3af9164454df308949f1a3211efeef34cb08cbcc Mon Sep 17 00:00:00 2001 From: ragunathc Date: Tue, 12 Nov 2024 15:50:21 +0000 Subject: [PATCH 15/41] remove different colours and remove colours with similar shades --- lambeq/backend/drawing/drawing_backend.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index 7863692a..7cddeb90 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -31,15 +31,14 @@ DEFAULT_ASPECT = 'equal' WIRE_COLORS = [ - '#9c540e', '#d03b2d', '#066ee2', '#f4a940', '#271296', - '#f07e33', '#fe9100', '#574cfa', '#49a141', '#a629b3', - '#1d0b66', '#f8c84b', '#7446f2', '#007765', '#b60539', - '#751fa5', '#5ac358', '#c330b9', '#398889', '#3c8331', - '#740127', '#018c76', '#e2074c', '#0252a1', '#fea431', - '#a22417', '#450d06', '#d17800', '#3831a0', '#73b8fd' + '#9c540e', '#f4a940', '#066ee2', '#d03b2d', '#f0e68c', + '#574cfa', '#49a141', '#a629b3', '#271296', '#ff6347', + '#adff2f', '#7446f2', '#007765', '#b60539', '#ff00ff', + '#c330b9', '#73b8fd', '#ff1493', '#00bfff', '#ffb6c1', + '#740127', '#e2074c', '#0252a1', '#fea431', '#ffff00', + '#450d06', '#d17800', '#3831a0', '#ff4500', '#d8bfd8' ] - FRAME_COLORS: list[str] = [ '#fbe8e7', '#fee1ba', '#fff9e5', '#e8f8ea', '#dcfbf5', '#e2effe', '#dfdefe', '#f0e8fc', '#f8e6f6', '#ffd0df', From 6bf61c8477d298ededb9aeb1d9f0f233cf422831 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Wed, 13 Nov 2024 13:42:08 +0000 Subject: [PATCH 16/41] remove yellow shades from colors list --- lambeq/backend/drawing/drawing_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index 7cddeb90..8c9493bb 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -31,11 +31,11 @@ DEFAULT_ASPECT = 'equal' WIRE_COLORS = [ - '#9c540e', '#f4a940', '#066ee2', '#d03b2d', '#f0e68c', + '#9c540e', '#f4a940', '#066ee2', '#d03b2d', '#7fd68b', '#574cfa', '#49a141', '#a629b3', '#271296', '#ff6347', '#adff2f', '#7446f2', '#007765', '#b60539', '#ff00ff', '#c330b9', '#73b8fd', '#ff1493', '#00bfff', '#ffb6c1', - '#740127', '#e2074c', '#0252a1', '#fea431', '#ffff00', + '#740127', '#e2074c', '#0252a1', '#fea431', '#205356', '#450d06', '#d17800', '#3831a0', '#ff4500', '#d8bfd8' ] From 222376afab8379d89e250b45d5453b15a9d3ae58 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Wed, 13 Nov 2024 14:32:36 +0000 Subject: [PATCH 17/41] remove optional for input_nouns --- lambeq/backend/drawing/drawable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 99fe9782..513bab48 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -850,7 +850,7 @@ def _add_box_with_nouns( off: int, x_pos: float, y_pos: float, - input_nouns: Optional[list[int]] + input_nouns: list[int] ) -> tuple[list[int], int, list[int]]: """Add a box to the graph, creating necessary wire endpoints. From d1a7100f485372674e678c0ebb84099af602c756 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Wed, 13 Nov 2024 15:33:44 +0000 Subject: [PATCH 18/41] different linewidth for box and wires, get from user using params --- lambeq/backend/drawing/drawing.py | 3 ++- lambeq/backend/drawing/mat_backend.py | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index c4c27204..0c9ea014 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -128,7 +128,8 @@ def draw(diagram: Diagram, **params) -> None: backend = TikzBackend( use_tikzstyles=params.get('use_tikzstyles', None)) else: - backend = MatBackend(figsize=params.get('figsize', None)) + backend = MatBackend(figsize=params.get('figsize', None), + wires_linewidth=params.get('wires_width', 1.25)) min_size = 0.01 max_v = max([v for point in ([point.coordinates for point in diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index 52062405..d2ab058f 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -37,10 +37,12 @@ class MatBackend(DrawingBackend): def __init__(self, axis: plt.Axes | None = None, figsize: tuple | None = None, - linewidth: float = 1): + box_linewidth: float = 1, + wires_linewidth: float = 1.25): self.axis = axis or plt.subplots(figsize=figsize, facecolor='white')[1] self.default_aspect = 'equal' if figsize is None else 'auto' - self.linewidth = linewidth + self.box_linewidth = box_linewidth + self.wires_linewidth = wires_linewidth self.max_width: float = 0 def draw_text(self, text: str, x: float, y: float, **params) -> None: @@ -63,7 +65,7 @@ def draw_polygon(self, *points: list[float], color: str = 'white') -> None: codes += len(points[1:]) * [Path.LINETO] + [Path.CLOSEPOLY] path = Path(points + points[:1], codes) self.axis.add_patch(PathPatch( - path, facecolor=COLORS[color], linewidth=self.linewidth)) + path, facecolor=COLORS[color], linewidth=self.box_linewidth)) def draw_wire(self, source: tuple[float, float], @@ -110,7 +112,7 @@ def draw_wire(self, ]) self.axis.add_patch(PathPatch(path, facecolor='none', - linewidth=self.linewidth, + linewidth=self.wires_linewidth, edgecolor=color)) self.max_width = max(self.max_width, source[0], target[0]) From 8da64d728f87af72a7fc9f66d0143c2edeca65f9 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 14 Nov 2024 21:00:03 +0000 Subject: [PATCH 19/41] remove invalid characters from stylenames which throw render errors --- lambeq/backend/drawing/tikz_backend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 42cc4008..6417c0c5 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -104,7 +104,8 @@ def draw_polygon(self, *points: list[float], color: str = 'white') -> None: nodes.append(nodes[0]) if self.use_tikzstyles: - style_name = 'box' if color == 'white' else f'{color}_box' + color_name = color.lstrip('#') + style_name = 'box' if color == 'white' else f'{color_name}_box' style = (f'\\tikzstyle{{{style_name}}}=' f'[-, fill={self.format_color(color)}]\n') if style not in self.edge_styles: From 3c83b8337bc47902b8af0b6c73ed25726ff1b948 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 14 Nov 2024 21:02:07 +0000 Subject: [PATCH 20/41] color wire changes in Tikz_backend --- lambeq/backend/drawing/tikz_backend.py | 56 ++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 6417c0c5..470debe8 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -40,9 +40,39 @@ def __init__(self, use_tikzstyles: bool = False): self.edgelayer: list[str] = [] self.max_width: float = 0 - @staticmethod - def format_color(color: str) -> str: + def format_color(self, color: str) -> str: + """ + Returns RGB value for the Hex. + + Parameters + ---------- + color : str + The Hex color code, represented as a string. + + Returns + ---------- + rgb-color: str + The RGB color format, represented as a string. + + """ hexcode = COLORS[color] + return self.get_rgb_for_hex(hexcode=hexcode) + + def get_rgb_for_hex(self, hexcode: str) -> str: + """ + Helper method to convert Hex to RGB + + Parameters + ---------- + hexcode : str + The Hex color, represented as a string. + + Returns + ---------- + rgb-color: str + The RGB color, represented as a string. + + """ rgb = [ int(hex, 16) for hex in [hexcode[1:3], hexcode[3:5], hexcode[5:]]] return f'{{rgb,255: red,{rgb[0]}; green,{rgb[1]}; blue,{rgb[2]}}}' @@ -127,7 +157,7 @@ def draw_wire(self, color_id: int = 0, **params) -> None: - # color = self._get_wire_color(color_id, **params) + color = self._get_wire_color(color_id, **params) out = (-90 if not bend_out or source[0] == target[0] else (180 if source[0] > target[0] else 0)) inp = (90 if not bend_in or source[0] == target[0] @@ -145,6 +175,24 @@ def draw_wire(self, style = '' style += f'looseness={looseness}' + if self.use_tikzstyles: + # TikZ style for the wire color + color_name = color.lstrip('#') + wire_style_name = (f'{color_name}_wire' + if color != '#000000' else 'black_wire') + wire_style = (f'\\tikzstyle{{{wire_style_name}}}=' + f'[-, draw={self.get_rgb_for_hex(color)}]\n') + if wire_style not in self.edge_styles: + self.edge_styles.append(wire_style) + wire_options = f'style={wire_style_name}' + + # Concatenate additional styles like looseness if present + if style: + wire_options += f', {style}' + + else: + wire_options = f'-, draw={{{color}}}' + cmd = ( '\\draw [in={}, out={}{}] ' '({}.center) to ({}.center);\n') @@ -156,7 +204,7 @@ def draw_wire(self, self.edgelayer.append(cmd.format( inp, out, - f', {style}' if style is not None else '', + f', {wire_options}' if wire_options is not None else '', self.nodes[source], self.nodes[target])) def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: From e8c04f32d78dd5287dbe0b94a407d20c6392d1c2 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 15 Nov 2024 12:14:26 +0000 Subject: [PATCH 21/41] remove extra {} --- lambeq/backend/drawing/tikz_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 470debe8..23a6ff64 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -191,7 +191,7 @@ def draw_wire(self, wire_options += f', {style}' else: - wire_options = f'-, draw={{{color}}}' + wire_options = f'-, draw={self.get_rgb_for_hex(color)}' cmd = ( '\\draw [in={}, out={}{}] ' From 7caef28707d8c8c86ff4e460a906b68259a01cc8 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 15 Nov 2024 22:17:54 +0000 Subject: [PATCH 22/41] static commands for tex file, new layer for labels --- lambeq/backend/drawing/tikz_backend.py | 45 +++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 23a6ff64..5f490c28 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -38,6 +38,7 @@ def __init__(self, use_tikzstyles: bool = False): self.nodes: dict[tuple[float, float], int] = {} self.nodelayer: list[str] = [] self.edgelayer: list[str] = [] + self.label_layer: list[str] = [] self.max_width: float = 0 def format_color(self, color: str) -> str: @@ -80,15 +81,21 @@ def get_rgb_for_hex(self, hexcode: str) -> str: def add_node(self, x: float, y: float, + is_label : bool = False, text: str | None = None, options: str | None = None) -> int: """ Add a node to the tikz picture, return its unique id. """ node = max(self.nodes.values()) + 1 if self.nodes else 1 text = '' if text is None else text - - self.nodelayer.append( - f'\\node [{options or ""}] ({node}) at ({x}, {y}) {{{text}}};\n') + if is_label: + self.label_layer.append( + f'\\node [{options or ""}] ({node}) ' + f'at ({x}, {y}) {{{text}}};\n') + else: + self.nodelayer.append( + f'\\node [{options or ""}] ({node}) ' + f'at ({x}, {y}) {{{text}}};\n') self.nodes.update({(x, y): node}) self.max_width = max(self.max_width, x) @@ -107,14 +114,14 @@ def draw_node(self, if 'color' in params: options.append(params['color']) - self.add_node(x, y, text, options=', '.join(options)) + self.add_node(x, y, text=text, options=', '.join(options)) def draw_text(self, text: str, x: float, y: float, **params) -> None: - options = 'style=none, fill=white' + options = 'style=none' if params.get('horizontalalignment', 'center') == 'left': options += ', anchor=west' @@ -123,7 +130,7 @@ def draw_text(self, if 'fontsize' in params and params['fontsize'] is not None: options += f', scale={params["fontsize"]}' - self.add_node(x, y, text, options) + self.add_node(x, y, text=text, options=options, is_label=True) def draw_polygon(self, *points: list[float], color: str = 'white') -> None: nodes: list[int] = [] @@ -142,7 +149,7 @@ def draw_polygon(self, *points: list[float], color: str = 'white') -> None: self.edge_styles.append(style) options = f'style={style_name}' else: - options = f'-, fill={{{color}}}' + options = f'-, fill={{{self.format_color(color)}}}' str_connections = ' to '.join(f'({node}.center)' for node in nodes) self.edgelayer.append(f'\\draw [{options}] {str_connections};\n') @@ -226,7 +233,7 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: if params.get('nodesize', 1) != 1: options += f', scale={params.get("nodesize")}' - self.add_node(i, j, '', options) + self.add_node(i, j, is_label=False, text='', options=options) for wire in node.cod_wires: self.draw_wire(node.coordinates, @@ -254,8 +261,17 @@ def output(self, path=None, show=True, **params) -> None: + self.nodelayer + ['\\end{pgfonlayer}\n']) edges = (['\\begin{pgfonlayer}{edgelayer}\n'] + self.edgelayer + ['\\end{pgfonlayer}\n']) + labels = (['\\begin{pgfonlayer}{labellayer}\n'] + self.label_layer + + ['\\end{pgfonlayer}\n']) end = ['\\end{tikzpicture}\n'] - + tex_comments = ( + "% When embedding into a *.tex file, uncomment and include " + "the following lines:\n" + "% \\pgfdeclarelayer{nodelayer}\n" + "% \\pgfdeclarelayer{edgelayer}\n" + "% \\pgfdeclarelayer{labellayer}\n" + "% \\pgfsetlayers{nodelayer, edgelayer, labellayer}\n" + ) if path is not None: if output_tikzstyle: style_path = '.'.join(path.split('.')[:-1]) + '.tikzstyles' @@ -263,9 +279,14 @@ def output(self, path=None, show=True, **params) -> None: file.writelines(['% Node styles\n'] + self.node_styles) file.writelines(['% Edge styles\n'] + self.edge_styles) with open(path, 'w+') as file: - file.writelines(begin + nodes + edges + end) + file.writelines([tex_comments] + begin + nodes + edges + + labels + end) elif show: + tex_output = tex_comments + if output_tikzstyle: - print(''.join(self.node_styles + self.edge_styles)) - print(''.join(begin + nodes + edges + end)) + tex_output += ''.join(self.node_styles + self.edge_styles) + + tex_output += ''.join(begin + nodes + edges + labels + end) + print(tex_output) From 3d9be557e63aaad73c39022809899bb39ddc7dff Mon Sep 17 00:00:00 2001 From: ragunathc Date: Fri, 15 Nov 2024 22:28:21 +0000 Subject: [PATCH 23/41] flake8 suggestion to remove quotes --- lambeq/backend/drawing/tikz_backend.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 5f490c28..ac93127f 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -265,12 +265,12 @@ def output(self, path=None, show=True, **params) -> None: + ['\\end{pgfonlayer}\n']) end = ['\\end{tikzpicture}\n'] tex_comments = ( - "% When embedding into a *.tex file, uncomment and include " - "the following lines:\n" - "% \\pgfdeclarelayer{nodelayer}\n" - "% \\pgfdeclarelayer{edgelayer}\n" - "% \\pgfdeclarelayer{labellayer}\n" - "% \\pgfsetlayers{nodelayer, edgelayer, labellayer}\n" + '% When embedding into a *.tex file, uncomment and include ' + 'the following lines:\n' + '% \\pgfdeclarelayer{nodelayer}\n' + '% \\pgfdeclarelayer{edgelayer}\n' + '% \\pgfdeclarelayer{labellayer}\n' + '% \\pgfsetlayers{nodelayer, edgelayer, labellayer}\n' ) if path is not None: if output_tikzstyle: From 57fe2d9e582c1436432433838da2d6eedf198ec6 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 18 Nov 2024 16:41:21 +0000 Subject: [PATCH 24/41] remove extra {} --- lambeq/backend/drawing/tikz_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index ac93127f..a25cb2cb 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -149,7 +149,7 @@ def draw_polygon(self, *points: list[float], color: str = 'white') -> None: self.edge_styles.append(style) options = f'style={style_name}' else: - options = f'-, fill={{{self.format_color(color)}}}' + options = f'-, fill={self.format_color(color)}' str_connections = ' to '.join(f'({node}.center)' for node in nodes) self.edgelayer.append(f'\\draw [{options}] {str_connections};\n') From edac6cd3ce7c8d3a6f11a74fc6d453dcbf2e4d3d Mon Sep 17 00:00:00 2001 From: ragunathc Date: Mon, 18 Nov 2024 16:42:46 +0000 Subject: [PATCH 25/41] delete sample file --- tests/backend/simple-books-frame-drawing.html | 8286 ----------------- 1 file changed, 8286 deletions(-) delete mode 100644 tests/backend/simple-books-frame-drawing.html diff --git a/tests/backend/simple-books-frame-drawing.html b/tests/backend/simple-books-frame-drawing.html deleted file mode 100644 index f2dc8e24..00000000 --- a/tests/backend/simple-books-frame-drawing.html +++ /dev/null @@ -1,8286 +0,0 @@ - - - - - -simple-books-frame-drawing - - - - - - - - - - - - -
-
- - From 353df2f6117c0073eb04d64ae40084f3d96bee38 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Tue, 19 Nov 2024 11:55:35 +0000 Subject: [PATCH 26/41] cosmetic readability fixes --- lambeq/backend/drawing/drawing_backend.py | 9 +++++---- lambeq/backend/drawing/tikz_backend.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index 8c9493bb..2778d3f3 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -30,7 +30,7 @@ DEFAULT_MARGINS = (.05, .1) DEFAULT_ASPECT = 'equal' -WIRE_COLORS = [ +WIRE_COLORS: list[str] = [ '#9c540e', '#f4a940', '#066ee2', '#d03b2d', '#7fd68b', '#574cfa', '#49a141', '#a629b3', '#271296', '#ff6347', '#adff2f', '#7446f2', '#007765', '#b60539', '#ff00ff', @@ -196,7 +196,7 @@ def draw_spiders(self, drawable: DrawableDiagram, **params) -> None: def _get_wire_color(self, wire_id : int, **params) -> str: """ - Retrieves a color that uniquely represent a given wire ID. + Retrieves a color that uniquely represent a given wire ID. Parameters ---------- @@ -206,9 +206,10 @@ def _get_wire_color(self, wire_id : int, **params) -> str: **params: Additional parameters. - Returns: + Returns + ------- wire_color : str - The Hex color of the wire, represented as a string. + The hex color of the wire, represented as a string. """ if not params.get('color_wires') or wire_id == 0: diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index a25cb2cb..718d9083 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -43,16 +43,16 @@ def __init__(self, use_tikzstyles: bool = False): def format_color(self, color: str) -> str: """ - Returns RGB value for the Hex. + Returns RGB value for the hex. Parameters ---------- color : str - The Hex color code, represented as a string. + The hex color code, represented as a string. Returns - ---------- - rgb-color: str + ------- + rgb-color : str The RGB color format, represented as a string. """ @@ -61,16 +61,16 @@ def format_color(self, color: str) -> str: def get_rgb_for_hex(self, hexcode: str) -> str: """ - Helper method to convert Hex to RGB + Helper method to convert hex to RGB Parameters ---------- hexcode : str - The Hex color, represented as a string. + The hex color, represented as a string. Returns - ---------- - rgb-color: str + ------- + rgb-color : str The RGB color, represented as a string. """ From 8d43b7912500948abb9b02c0822cd919dfb9f369 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Tue, 19 Nov 2024 16:51:45 +0000 Subject: [PATCH 27/41] refactor wire colour formatting like boxes --- lambeq/backend/drawing/drawing_backend.py | 6 ++++++ lambeq/backend/drawing/tikz_backend.py | 20 +++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lambeq/backend/drawing/drawing_backend.py b/lambeq/backend/drawing/drawing_backend.py index 2778d3f3..867ca73f 100644 --- a/lambeq/backend/drawing/drawing_backend.py +++ b/lambeq/backend/drawing/drawing_backend.py @@ -38,6 +38,12 @@ '#740127', '#e2074c', '#0252a1', '#fea431', '#205356', '#450d06', '#d17800', '#3831a0', '#ff4500', '#d8bfd8' ] +WIRE_COLORS_NAMES: dict[str, str] = { + '#ffffff' : '#ffffff', + '#000000' : '#000000' +} +for color in WIRE_COLORS: + WIRE_COLORS_NAMES[color] = color FRAME_COLORS: list[str] = [ '#fbe8e7', '#fee1ba', '#fff9e5', '#e8f8ea', '#dcfbf5', diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 718d9083..ebd5e70d 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -45,17 +45,8 @@ def format_color(self, color: str) -> str: """ Returns RGB value for the hex. - Parameters - ---------- - color : str - The hex color code, represented as a string. - - Returns - ------- - rgb-color : str - The RGB color format, represented as a string. - - """ + @staticmethod + def format_color(color: str) -> str: hexcode = COLORS[color] return self.get_rgb_for_hex(hexcode=hexcode) @@ -78,6 +69,13 @@ def get_rgb_for_hex(self, hexcode: str) -> str: int(hex, 16) for hex in [hexcode[1:3], hexcode[3:5], hexcode[5:]]] return f'{{rgb,255: red,{rgb[0]}; green,{rgb[1]}; blue,{rgb[2]}}}' + @staticmethod + def format_wire_color(color: str) -> str: + hexcode = WIRE_COLORS_NAMES[color] + rgb = [ + int(hex, 16) for hex in [hexcode[1:3], hexcode[3:5], hexcode[5:]]] + return f'{{rgb,255: red,{rgb[0]}; green,{rgb[1]}; blue,{rgb[2]}}}' + def add_node(self, x: float, y: float, From 78fbfee7c5970111e757cd345554ddb46a97da75 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Tue, 19 Nov 2024 16:53:52 +0000 Subject: [PATCH 28/41] wires width changes for Tikz backend --- lambeq/backend/drawing/drawing.py | 12 +++++-- lambeq/backend/drawing/tikz_backend.py | 44 +++++++++----------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 0c9ea014..f113a70b 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -48,6 +48,8 @@ from lambeq.backend.drawing.tikz_backend import TikzBackend from lambeq.backend.grammar import Box, Diagram +WIRES_DEFAULT_WIDTH_MAT = 1.25 +WIRES_DEFAULT_WIDTH_TIKZ = 1.25 * 0.4 # Tikz default standard is 0.4pt if TYPE_CHECKING: from IPython.core.display import HTML as HTML_ty @@ -126,10 +128,14 @@ def draw(diagram: Diagram, **params) -> None: backend: DrawingBackend = params.pop('backend') elif params.get('to_tikz', False): backend = TikzBackend( - use_tikzstyles=params.get('use_tikzstyles', None)) + use_tikzstyles=params.get('use_tikzstyles', None), + wires_linewidth=params.get('wires_linewidth', + WIRES_DEFAULT_WIDTH_TIKZ)) else: - backend = MatBackend(figsize=params.get('figsize', None), - wires_linewidth=params.get('wires_width', 1.25)) + backend = ( + MatBackend(figsize=params.get('figsize', None), + wires_linewidth=params.get('wires_linewidth', + WIRES_DEFAULT_WIDTH_MAT))) min_size = 0.01 max_v = max([v for point in ([point.coordinates for point in diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index ebd5e70d..f4bb335e 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -23,7 +23,8 @@ from math import sqrt from lambeq.backend.drawing.drawable import DrawableDiagram -from lambeq.backend.drawing.drawing_backend import COLORS, DrawingBackend +from lambeq.backend.drawing.drawing_backend import (COLORS, WIRE_COLORS_NAMES, + DrawingBackend) from lambeq.backend.drawing.helpers import drawn_as_spider from lambeq.backend.grammar import Spider @@ -31,7 +32,8 @@ class TikzBackend(DrawingBackend): """ Tikz drawing backend. """ - def __init__(self, use_tikzstyles: bool = False): + def __init__(self, use_tikzstyles: bool = False, + wires_linewidth: float = 0.4): self.use_tikzstyles = use_tikzstyles self.node_styles: list[str] = [] self.edge_styles: list[str] = [] @@ -40,31 +42,11 @@ def __init__(self, use_tikzstyles: bool = False): self.edgelayer: list[str] = [] self.label_layer: list[str] = [] self.max_width: float = 0 - - def format_color(self, color: str) -> str: - """ - Returns RGB value for the hex. + self.wires_linewidth = wires_linewidth @staticmethod def format_color(color: str) -> str: hexcode = COLORS[color] - return self.get_rgb_for_hex(hexcode=hexcode) - - def get_rgb_for_hex(self, hexcode: str) -> str: - """ - Helper method to convert hex to RGB - - Parameters - ---------- - hexcode : str - The hex color, represented as a string. - - Returns - ------- - rgb-color : str - The RGB color, represented as a string. - - """ rgb = [ int(hex, 16) for hex in [hexcode[1:3], hexcode[3:5], hexcode[5:]]] return f'{{rgb,255: red,{rgb[0]}; green,{rgb[1]}; blue,{rgb[2]}}}' @@ -186,18 +168,22 @@ def draw_wire(self, wire_style_name = (f'{color_name}_wire' if color != '#000000' else 'black_wire') wire_style = (f'\\tikzstyle{{{wire_style_name}}}=' - f'[-, draw={self.get_rgb_for_hex(color)}]\n') + f'[-, draw={self.format_wire_color(color)}') + + # Concatenate additional styles like looseness if present + if style: + wire_style += f', {style}' + wire_style += f', line width={self.wires_linewidth}]\n' + if wire_style not in self.edge_styles: self.edge_styles.append(wire_style) wire_options = f'style={wire_style_name}' - # Concatenate additional styles like looseness if present + else: + wire_options = f'-, draw={self.format_wire_color(color)}' + wire_options += f', line width={self.wires_linewidth}' if style: wire_options += f', {style}' - - else: - wire_options = f'-, draw={self.get_rgb_for_hex(color)}' - cmd = ( '\\draw [in={}, out={}{}] ' '({}.center) to ({}.center);\n') From ba8dc7f7e78062d6552485181d91c8190c6a7da0 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Tue, 19 Nov 2024 17:01:09 +0000 Subject: [PATCH 29/41] fix for flake8 import order error --- lambeq/backend/drawing/tikz_backend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index f4bb335e..698c137e 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -23,8 +23,9 @@ from math import sqrt from lambeq.backend.drawing.drawable import DrawableDiagram -from lambeq.backend.drawing.drawing_backend import (COLORS, WIRE_COLORS_NAMES, - DrawingBackend) +from lambeq.backend.drawing.drawing_backend import (COLORS, DrawingBackend, + WIRE_COLORS_NAMES + ) from lambeq.backend.drawing.helpers import drawn_as_spider from lambeq.backend.grammar import Spider From ae698575b2d5a7aeac4fced10646ff443f19ffb7 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Wed, 20 Nov 2024 11:59:41 +0000 Subject: [PATCH 30/41] update testcases for frame drawing with wire colouring --- tests/backend/test_frame_drawing.py | 346 +++++++++++++++------------- 1 file changed, 180 insertions(+), 166 deletions(-) diff --git a/tests/backend/test_frame_drawing.py b/tests/backend/test_frame_drawing.py index 128bdb61..bb319f67 100644 --- a/tests/backend/test_frame_drawing.py +++ b/tests/backend/test_frame_drawing.py @@ -166,39 +166,38 @@ tikz_outputs = [ -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (2.25, 11.625) {}; \\node [] (2) at (3.25, 11.625) {}; \\node [] (3) at (3.25, 12.125) {}; \\node [] (4) at (2.25, 12.125) {}; -\\node [style=none, fill=white] (5) at (2.75, 11.875) {Alice}; \\node [] (6) at (4.75, 11.625) {}; \\node [] (7) at (5.75, 11.625) {}; \\node [] (8) at (5.75, 12.125) {}; \\node [] (9) at (4.75, 12.125) {}; -\\node [style=none, fill=white] (10) at (5.25, 11.875) {Bob}; \\node [] (11) at (7.25, 11.625) {}; \\node [] (12) at (8.25, 11.625) {}; \\node [] (13) at (8.25, 12.125) {}; \\node [] (14) at (7.25, 12.125) {}; -\\node [style=none, fill=white] (15) at (7.75, 11.875) {cake}; \\node [] (16) at (9.75, 11.625) {}; \\node [] (17) at (10.75, 11.625) {}; \\node [] (18) at (10.75, 12.125) {}; \\node [] (19) at (9.75, 12.125) {}; -\\node [style=none, fill=white] (20) at (10.25, 11.875) {coffee}; \\node [] (21) at (2.25, 9.125) {}; \\node [] (22) at (5.75, 9.125) {}; \\node [] (23) at (5.75, 9.625) {}; \\node [] (24) at (2.25, 9.625) {}; -\\node [style=none, fill=white] (25) at (4.0, 9.375) {told}; \\node [] (26) at (-1.5, -1.875) {}; \\node [] (27) at (14.5, -1.875) {}; \\node [] (28) at (14.5, 7.125) {}; \\node [] (29) at (-1.5, 7.125) {}; -\\node [style=none, fill=white] (30) at (6.5, 6.625) {and}; \\node [] (31) at (-1.0, 1.625) {}; \\node [] (32) at (3.5, 1.625) {}; \\node [] (33) at (3.5, 3.625) {}; @@ -207,7 +206,6 @@ \\node [] (36) at (3.0, 2.375) {}; \\node [] (37) at (3.0, 2.875) {}; \\node [] (38) at (-0.5, 2.875) {}; -\\node [style=none, fill=white] (39) at (1.25, 2.625) {eats}; \\node [] (40) at (4.25, 1.625) {}; \\node [] (41) at (8.75, 1.625) {}; \\node [] (42) at (8.75, 3.625) {}; @@ -216,7 +214,6 @@ \\node [] (45) at (8.25, 2.375) {}; \\node [] (46) at (8.25, 2.875) {}; \\node [] (47) at (4.75, 2.875) {}; -\\node [style=none, fill=white] (48) at (6.5, 2.625) {drinks}; \\node [] (49) at (9.5, -0.875) {}; \\node [] (50) at (14.0, -0.875) {}; \\node [] (51) at (14.0, 6.125) {}; @@ -225,151 +222,161 @@ \\node [] (54) at (12.25, 4.875) {}; \\node [] (55) at (12.25, 5.375) {}; \\node [] (56) at (11.25, 5.375) {}; -\\node [style=none, fill=white] (57) at (11.75, 5.125) {runs}; \\node [] (58) at (10.0, 2.375) {}; \\node [] (59) at (13.5, 2.375) {}; \\node [] (60) at (13.5, 2.875) {}; \\node [] (61) at (10.0, 2.875) {}; -\\node [style=none, fill=white] (62) at (11.75, 2.625) {x}; \\node [] (63) at (10.0, -0.125) {}; \\node [] (64) at (11.0, -0.125) {}; \\node [] (65) at (11.0, 0.375) {}; \\node [] (66) at (10.0, 0.375) {}; -\\node [style=none, fill=white] (67) at (10.5, 0.125) {y}; \\node [] (68) at (6.0, -4.375) {}; \\node [] (69) at (9.5, -4.375) {}; \\node [] (70) at (9.5, -3.875) {}; \\node [] (71) at (6.0, -3.875) {}; -\\node [style=none, fill=white] (72) at (7.75, -4.125) {test}; \\node [] (73) at (3.5, -4.375) {}; \\node [] (74) at (4.5, -4.375) {}; \\node [] (75) at (4.5, -3.875) {}; \\node [] (76) at (3.5, -3.875) {}; -\\node [style=none, fill=white] (77) at (4.0, -4.125) {a}; \\node [] (78) at (8.5, -6.875) {}; \\node [] (79) at (9.5, -6.875) {}; \\node [] (80) at (9.5, -6.375) {}; \\node [] (81) at (8.5, -6.375) {}; -\\node [style=none, fill=white] (82) at (9.0, -6.625) {b}; \\node [] (83) at (2.75, 11.625) {}; \\node [] (84) at (2.75, 9.625) {}; -\\node [style=none, fill=white, right] (85) at (2.85, 11.525) {n}; \\node [] (86) at (5.25, 11.625) {}; \\node [] (87) at (5.25, 9.625) {}; -\\node [style=none, fill=white, right] (88) at (5.35, 11.525) {n}; \\node [] (89) at (2.75, 9.125) {}; \\node [] (90) at (2.75, 7.125) {}; -\\node [style=none, fill=white, right] (91) at (2.85, 9.025) {n}; \\node [] (92) at (5.25, 9.125) {}; \\node [] (93) at (5.25, 7.125) {}; -\\node [style=none, fill=white, right] (94) at (5.35, 9.025) {n}; \\node [] (95) at (7.75, 11.625) {}; \\node [] (96) at (7.75, 7.125) {}; -\\node [style=none, fill=white, right] (97) at (7.85, 11.525) {n}; \\node [] (98) at (10.25, 11.625) {}; \\node [] (99) at (10.25, 7.125) {}; -\\node [style=none, fill=white, right] (100) at (10.35, 11.525) {n}; \\node [] (101) at (0.0, 3.625) {}; \\node [] (102) at (0.0, 2.875) {}; -\\node [style=none, fill=white, right] (103) at (0.1, 3.625) {n}; \\node [] (104) at (2.5, 3.625) {}; \\node [] (105) at (2.5, 2.875) {}; -\\node [style=none, fill=white, right] (106) at (2.6, 3.625) {n}; \\node [] (107) at (0.0, 2.375) {}; \\node [] (108) at (0.0, 1.625) {}; -\\node [style=none, fill=white, right] (109) at (0.1, 2.275) {n}; \\node [] (110) at (2.5, 2.375) {}; \\node [] (111) at (2.5, 1.625) {}; -\\node [style=none, fill=white, right] (112) at (2.6, 2.275) {n}; \\node [] (113) at (5.25, 3.625) {}; \\node [] (114) at (5.25, 2.875) {}; -\\node [style=none, fill=white, right] (115) at (5.35, 3.625) {n}; \\node [] (116) at (7.75, 3.625) {}; \\node [] (117) at (7.75, 2.875) {}; -\\node [style=none, fill=white, right] (118) at (7.85, 3.625) {n}; \\node [] (119) at (5.25, 2.375) {}; \\node [] (120) at (5.25, 1.625) {}; -\\node [style=none, fill=white, right] (121) at (5.35, 2.275) {n}; \\node [] (122) at (7.75, 2.375) {}; \\node [] (123) at (7.75, 1.625) {}; -\\node [style=none, fill=white, right] (124) at (7.85, 2.275) {n}; \\node [] (125) at (11.75, 6.125) {}; \\node [] (126) at (11.75, 5.375) {}; -\\node [style=none, fill=white, right] (127) at (11.85, 6.125) {n}; \\node [] (128) at (11.75, 4.875) {}; \\node [] (129) at (11.75, 2.875) {}; -\\node [style=none, fill=white, right] (130) at (11.85, 4.775) {n}; \\node [] (131) at (10.5, 2.375) {}; \\node [] (132) at (10.5, 0.375) {}; -\\node [style=none, fill=white, right] (133) at (10.6, 2.275) {s}; \\node [] (134) at (10.5, -0.125) {}; \\node [] (135) at (10.5, -0.875) {}; -\\node [style=none, fill=white, right] (136) at (10.6, -0.225) {s}; \\node [] (137) at (13.0, 2.375) {}; \\node [] (138) at (13.0, -0.875) {}; -\\node [style=none, fill=white, right] (139) at (13.1, 2.275) {s}; \\node [] (140) at (6.5, -1.875) {}; \\node [] (141) at (6.5, -3.875) {}; -\\node [style=none, fill=white, right] (142) at (6.6, -1.975) {n}; \\node [] (143) at (9.0, -1.875) {}; \\node [] (144) at (9.0, -3.875) {}; -\\node [style=none, fill=white, right] (145) at (9.1, -1.975) {n}; \\node [] (146) at (4.0, -1.875) {}; \\node [] (147) at (4.0, -3.875) {}; -\\node [style=none, fill=white, right] (148) at (4.1, -1.975) {n}; \\node [] (149) at (9.0, -4.375) {}; \\node [] (150) at (9.0, -6.375) {}; -\\node [style=none, fill=white, right] (151) at (9.1, -4.475) {n}; \\node [] (152) at (4.0, -4.375) {}; \\node [] (153) at (4.0, -11.875) {}; -\\node [style=none, fill=white, right] (154) at (4.1, -4.475) {n}; \\node [] (155) at (6.5, -4.375) {}; \\node [] (156) at (6.5, -11.875) {}; -\\node [style=none, fill=white, right] (157) at (6.6, -4.475) {n}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={white}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [-, fill={white}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); -\\draw [-, fill={white}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); -\\draw [-, fill={white}] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); -\\draw [-, fill={white}] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); -\\draw [-, fill={white}] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); -\\draw [-, fill={white}] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); -\\draw [-, fill={white}] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); -\\draw [-, fill={white}] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); -\\draw [-, fill={white}] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); -\\draw [-, fill={white}] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); -\\draw [-, fill={white}] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); -\\draw [-, fill={white}] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); -\\draw [-, fill={white}] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); -\\draw [-, fill={white}] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); -\\draw [-, fill={white}] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); -\\draw [in=90, out=-90] (83.center) to (84.center); -\\draw [in=90, out=-90] (86.center) to (87.center); -\\draw [in=90, out=-90] (89.center) to (90.center); -\\draw [in=90, out=-90] (92.center) to (93.center); -\\draw [in=90, out=-90] (95.center) to (96.center); -\\draw [in=90, out=-90] (98.center) to (99.center); -\\draw [in=90, out=-90] (101.center) to (102.center); -\\draw [in=90, out=-90] (104.center) to (105.center); -\\draw [in=90, out=-90] (107.center) to (108.center); -\\draw [in=90, out=-90] (110.center) to (111.center); -\\draw [in=90, out=-90] (113.center) to (114.center); -\\draw [in=90, out=-90] (116.center) to (117.center); -\\draw [in=90, out=-90] (119.center) to (120.center); -\\draw [in=90, out=-90] (122.center) to (123.center); -\\draw [in=90, out=-90] (125.center) to (126.center); -\\draw [in=90, out=-90] (128.center) to (129.center); -\\draw [in=90, out=-90] (131.center) to (132.center); -\\draw [in=90, out=-90] (134.center) to (135.center); -\\draw [in=90, out=-90] (137.center) to (138.center); -\\draw [in=90, out=-90] (140.center) to (141.center); -\\draw [in=90, out=-90] (143.center) to (144.center); -\\draw [in=90, out=-90] (146.center) to (147.center); -\\draw [in=90, out=-90] (149.center) to (150.center); -\\draw [in=90, out=-90] (152.center) to (153.center); -\\draw [in=90, out=-90] (155.center) to (156.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (83.center) to (84.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (86.center) to (87.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (89.center) to (90.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (92.center) to (93.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (95.center) to (96.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (98.center) to (99.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (101.center) to (102.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (104.center) to (105.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (107.center) to (108.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (110.center) to (111.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (113.center) to (114.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (116.center) to (117.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (119.center) to (120.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (122.center) to (123.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (125.center) to (126.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (128.center) to (129.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (131.center) to (132.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (134.center) to (135.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (137.center) to (138.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (140.center) to (141.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (143.center) to (144.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (146.center) to (147.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (149.center) to (150.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (152.center) to (153.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (155.center) to (156.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (2.75, 11.875) {Alice}; +\\node [style=none] (10) at (5.25, 11.875) {Bob}; +\\node [style=none] (15) at (7.75, 11.875) {cake}; +\\node [style=none] (20) at (10.25, 11.875) {coffee}; +\\node [style=none] (25) at (4.0, 9.375) {told}; +\\node [style=none] (30) at (6.5, 6.625) {and}; +\\node [style=none] (39) at (1.25, 2.625) {eats}; +\\node [style=none] (48) at (6.5, 2.625) {drinks}; +\\node [style=none] (57) at (11.75, 5.125) {runs}; +\\node [style=none] (62) at (11.75, 2.625) {x}; +\\node [style=none] (67) at (10.5, 0.125) {y}; +\\node [style=none] (72) at (7.75, -4.125) {test}; +\\node [style=none] (77) at (4.0, -4.125) {a}; +\\node [style=none] (82) at (9.0, -6.625) {b}; +\\node [style=none, right] (85) at (2.85, 11.525) {n}; +\\node [style=none, right] (88) at (5.35, 11.525) {n}; +\\node [style=none, right] (91) at (2.85, 9.025) {n}; +\\node [style=none, right] (94) at (5.35, 9.025) {n}; +\\node [style=none, right] (97) at (7.85, 11.525) {n}; +\\node [style=none, right] (100) at (10.35, 11.525) {n}; +\\node [style=none, right] (103) at (0.1, 3.625) {n}; +\\node [style=none, right] (106) at (2.6, 3.625) {n}; +\\node [style=none, right] (109) at (0.1, 2.275) {n}; +\\node [style=none, right] (112) at (2.6, 2.275) {n}; +\\node [style=none, right] (115) at (5.35, 3.625) {n}; +\\node [style=none, right] (118) at (7.85, 3.625) {n}; +\\node [style=none, right] (121) at (5.35, 2.275) {n}; +\\node [style=none, right] (124) at (7.85, 2.275) {n}; +\\node [style=none, right] (127) at (11.85, 6.125) {n}; +\\node [style=none, right] (130) at (11.85, 4.775) {n}; +\\node [style=none, right] (133) at (10.6, 2.275) {s}; +\\node [style=none, right] (136) at (10.6, -0.225) {s}; +\\node [style=none, right] (139) at (13.1, 2.275) {s}; +\\node [style=none, right] (142) at (6.6, -1.975) {n}; +\\node [style=none, right] (145) at (9.1, -1.975) {n}; +\\node [style=none, right] (148) at (4.1, -1.975) {n}; +\\node [style=none, right] (151) at (9.1, -4.475) {n}; +\\node [style=none, right] (154) at (4.1, -4.475) {n}; +\\node [style=none, right] (157) at (6.6, -4.475) {n}; \\end{pgfonlayer} \\end{tikzpicture} @@ -378,39 +385,38 @@ colored_tikz_outputs = [ -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (2.25, 11.625) {}; \\node [] (2) at (3.25, 11.625) {}; \\node [] (3) at (3.25, 12.125) {}; \\node [] (4) at (2.25, 12.125) {}; -\\node [style=none, fill=white] (5) at (2.75, 11.875) {Alice}; \\node [] (6) at (4.75, 11.625) {}; \\node [] (7) at (5.75, 11.625) {}; \\node [] (8) at (5.75, 12.125) {}; \\node [] (9) at (4.75, 12.125) {}; -\\node [style=none, fill=white] (10) at (5.25, 11.875) {Bob}; \\node [] (11) at (7.25, 11.625) {}; \\node [] (12) at (8.25, 11.625) {}; \\node [] (13) at (8.25, 12.125) {}; \\node [] (14) at (7.25, 12.125) {}; -\\node [style=none, fill=white] (15) at (7.75, 11.875) {cake}; \\node [] (16) at (9.75, 11.625) {}; \\node [] (17) at (10.75, 11.625) {}; \\node [] (18) at (10.75, 12.125) {}; \\node [] (19) at (9.75, 12.125) {}; -\\node [style=none, fill=white] (20) at (10.25, 11.875) {coffee}; \\node [] (21) at (2.25, 9.125) {}; \\node [] (22) at (5.75, 9.125) {}; \\node [] (23) at (5.75, 9.625) {}; \\node [] (24) at (2.25, 9.625) {}; -\\node [style=none, fill=white] (25) at (4.0, 9.375) {told}; \\node [] (26) at (-1.5, -1.875) {}; \\node [] (27) at (14.5, -1.875) {}; \\node [] (28) at (14.5, 7.125) {}; \\node [] (29) at (-1.5, 7.125) {}; -\\node [style=none, fill=white] (30) at (6.5, 6.625) {and}; \\node [] (31) at (-1.0, 1.625) {}; \\node [] (32) at (3.5, 1.625) {}; \\node [] (33) at (3.5, 3.625) {}; @@ -419,7 +425,6 @@ \\node [] (36) at (3.0, 2.375) {}; \\node [] (37) at (3.0, 2.875) {}; \\node [] (38) at (-0.5, 2.875) {}; -\\node [style=none, fill=white] (39) at (1.25, 2.625) {eats}; \\node [] (40) at (4.25, 1.625) {}; \\node [] (41) at (8.75, 1.625) {}; \\node [] (42) at (8.75, 3.625) {}; @@ -428,7 +433,6 @@ \\node [] (45) at (8.25, 2.375) {}; \\node [] (46) at (8.25, 2.875) {}; \\node [] (47) at (4.75, 2.875) {}; -\\node [style=none, fill=white] (48) at (6.5, 2.625) {drinks}; \\node [] (49) at (9.5, -0.875) {}; \\node [] (50) at (14.0, -0.875) {}; \\node [] (51) at (14.0, 6.125) {}; @@ -437,151 +441,161 @@ \\node [] (54) at (12.25, 4.875) {}; \\node [] (55) at (12.25, 5.375) {}; \\node [] (56) at (11.25, 5.375) {}; -\\node [style=none, fill=white] (57) at (11.75, 5.125) {runs}; \\node [] (58) at (10.0, 2.375) {}; \\node [] (59) at (13.5, 2.375) {}; \\node [] (60) at (13.5, 2.875) {}; \\node [] (61) at (10.0, 2.875) {}; -\\node [style=none, fill=white] (62) at (11.75, 2.625) {x}; \\node [] (63) at (10.0, -0.125) {}; \\node [] (64) at (11.0, -0.125) {}; \\node [] (65) at (11.0, 0.375) {}; \\node [] (66) at (10.0, 0.375) {}; -\\node [style=none, fill=white] (67) at (10.5, 0.125) {y}; \\node [] (68) at (6.0, -4.375) {}; \\node [] (69) at (9.5, -4.375) {}; \\node [] (70) at (9.5, -3.875) {}; \\node [] (71) at (6.0, -3.875) {}; -\\node [style=none, fill=white] (72) at (7.75, -4.125) {test}; \\node [] (73) at (3.5, -4.375) {}; \\node [] (74) at (4.5, -4.375) {}; \\node [] (75) at (4.5, -3.875) {}; \\node [] (76) at (3.5, -3.875) {}; -\\node [style=none, fill=white] (77) at (4.0, -4.125) {a}; \\node [] (78) at (8.5, -6.875) {}; \\node [] (79) at (9.5, -6.875) {}; \\node [] (80) at (9.5, -6.375) {}; \\node [] (81) at (8.5, -6.375) {}; -\\node [style=none, fill=white] (82) at (9.0, -6.625) {b}; \\node [] (83) at (2.75, 11.625) {}; \\node [] (84) at (2.75, 9.625) {}; -\\node [style=none, fill=white, right] (85) at (2.85, 11.525) {n}; \\node [] (86) at (5.25, 11.625) {}; \\node [] (87) at (5.25, 9.625) {}; -\\node [style=none, fill=white, right] (88) at (5.35, 11.525) {n}; \\node [] (89) at (2.75, 9.125) {}; \\node [] (90) at (2.75, 7.125) {}; -\\node [style=none, fill=white, right] (91) at (2.85, 9.025) {n}; \\node [] (92) at (5.25, 9.125) {}; \\node [] (93) at (5.25, 7.125) {}; -\\node [style=none, fill=white, right] (94) at (5.35, 9.025) {n}; \\node [] (95) at (7.75, 11.625) {}; \\node [] (96) at (7.75, 7.125) {}; -\\node [style=none, fill=white, right] (97) at (7.85, 11.525) {n}; \\node [] (98) at (10.25, 11.625) {}; \\node [] (99) at (10.25, 7.125) {}; -\\node [style=none, fill=white, right] (100) at (10.35, 11.525) {n}; \\node [] (101) at (0.0, 3.625) {}; \\node [] (102) at (0.0, 2.875) {}; -\\node [style=none, fill=white, right] (103) at (0.1, 3.625) {n}; \\node [] (104) at (2.5, 3.625) {}; \\node [] (105) at (2.5, 2.875) {}; -\\node [style=none, fill=white, right] (106) at (2.6, 3.625) {n}; \\node [] (107) at (0.0, 2.375) {}; \\node [] (108) at (0.0, 1.625) {}; -\\node [style=none, fill=white, right] (109) at (0.1, 2.275) {n}; \\node [] (110) at (2.5, 2.375) {}; \\node [] (111) at (2.5, 1.625) {}; -\\node [style=none, fill=white, right] (112) at (2.6, 2.275) {n}; \\node [] (113) at (5.25, 3.625) {}; \\node [] (114) at (5.25, 2.875) {}; -\\node [style=none, fill=white, right] (115) at (5.35, 3.625) {n}; \\node [] (116) at (7.75, 3.625) {}; \\node [] (117) at (7.75, 2.875) {}; -\\node [style=none, fill=white, right] (118) at (7.85, 3.625) {n}; \\node [] (119) at (5.25, 2.375) {}; \\node [] (120) at (5.25, 1.625) {}; -\\node [style=none, fill=white, right] (121) at (5.35, 2.275) {n}; \\node [] (122) at (7.75, 2.375) {}; \\node [] (123) at (7.75, 1.625) {}; -\\node [style=none, fill=white, right] (124) at (7.85, 2.275) {n}; \\node [] (125) at (11.75, 6.125) {}; \\node [] (126) at (11.75, 5.375) {}; -\\node [style=none, fill=white, right] (127) at (11.85, 6.125) {n}; \\node [] (128) at (11.75, 4.875) {}; \\node [] (129) at (11.75, 2.875) {}; -\\node [style=none, fill=white, right] (130) at (11.85, 4.775) {n}; \\node [] (131) at (10.5, 2.375) {}; \\node [] (132) at (10.5, 0.375) {}; -\\node [style=none, fill=white, right] (133) at (10.6, 2.275) {s}; \\node [] (134) at (10.5, -0.125) {}; \\node [] (135) at (10.5, -0.875) {}; -\\node [style=none, fill=white, right] (136) at (10.6, -0.225) {s}; \\node [] (137) at (13.0, 2.375) {}; \\node [] (138) at (13.0, -0.875) {}; -\\node [style=none, fill=white, right] (139) at (13.1, 2.275) {s}; \\node [] (140) at (6.5, -1.875) {}; \\node [] (141) at (6.5, -3.875) {}; -\\node [style=none, fill=white, right] (142) at (6.6, -1.975) {n}; \\node [] (143) at (9.0, -1.875) {}; \\node [] (144) at (9.0, -3.875) {}; -\\node [style=none, fill=white, right] (145) at (9.1, -1.975) {n}; \\node [] (146) at (4.0, -1.875) {}; \\node [] (147) at (4.0, -3.875) {}; -\\node [style=none, fill=white, right] (148) at (4.1, -1.975) {n}; \\node [] (149) at (9.0, -4.375) {}; \\node [] (150) at (9.0, -6.375) {}; -\\node [style=none, fill=white, right] (151) at (9.1, -4.475) {n}; \\node [] (152) at (4.0, -4.375) {}; \\node [] (153) at (4.0, -11.875) {}; -\\node [style=none, fill=white, right] (154) at (4.1, -4.475) {n}; \\node [] (155) at (6.5, -4.375) {}; \\node [] (156) at (6.5, -11.875) {}; -\\node [style=none, fill=white, right] (157) at (6.6, -4.475) {n}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={gray}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={gray}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [-, fill={gray}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); -\\draw [-, fill={gray}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); -\\draw [-, fill={gray}] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); -\\draw [-, fill={#fff9e5}] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); -\\draw [-, fill={white}] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); -\\draw [-, fill={gray}] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); -\\draw [-, fill={white}] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); -\\draw [-, fill={gray}] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); -\\draw [-, fill={white}] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); -\\draw [-, fill={gray}] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); -\\draw [-, fill={gray}] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); -\\draw [-, fill={gray}] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); -\\draw [-, fill={gray}] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); -\\draw [-, fill={gray}] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); -\\draw [-, fill={gray}] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); -\\draw [in=90, out=-90] (83.center) to (84.center); -\\draw [in=90, out=-90] (86.center) to (87.center); -\\draw [in=90, out=-90] (89.center) to (90.center); -\\draw [in=90, out=-90] (92.center) to (93.center); -\\draw [in=90, out=-90] (95.center) to (96.center); -\\draw [in=90, out=-90] (98.center) to (99.center); -\\draw [in=90, out=-90] (101.center) to (102.center); -\\draw [in=90, out=-90] (104.center) to (105.center); -\\draw [in=90, out=-90] (107.center) to (108.center); -\\draw [in=90, out=-90] (110.center) to (111.center); -\\draw [in=90, out=-90] (113.center) to (114.center); -\\draw [in=90, out=-90] (116.center) to (117.center); -\\draw [in=90, out=-90] (119.center) to (120.center); -\\draw [in=90, out=-90] (122.center) to (123.center); -\\draw [in=90, out=-90] (125.center) to (126.center); -\\draw [in=90, out=-90] (128.center) to (129.center); -\\draw [in=90, out=-90] (131.center) to (132.center); -\\draw [in=90, out=-90] (134.center) to (135.center); -\\draw [in=90, out=-90] (137.center) to (138.center); -\\draw [in=90, out=-90] (140.center) to (141.center); -\\draw [in=90, out=-90] (143.center) to (144.center); -\\draw [in=90, out=-90] (146.center) to (147.center); -\\draw [in=90, out=-90] (149.center) to (150.center); -\\draw [in=90, out=-90] (152.center) to (153.center); -\\draw [in=90, out=-90] (155.center) to (156.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); +\\draw [-, fill={rgb,255: red,255; green,249; blue,229}] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (83.center) to (84.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (86.center) to (87.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (89.center) to (90.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (92.center) to (93.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=0.5] (95.center) to (96.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,208; green,59; blue,45}, line width=0.5] (98.center) to (99.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (101.center) to (102.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (104.center) to (105.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (107.center) to (108.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (110.center) to (111.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (113.center) to (114.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (116.center) to (117.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (119.center) to (120.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (122.center) to (123.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (125.center) to (126.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (128.center) to (129.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (131.center) to (132.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (134.center) to (135.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (137.center) to (138.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (140.center) to (141.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=0.5] (143.center) to (144.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (146.center) to (147.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=0.5] (149.center) to (150.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (152.center) to (153.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (155.center) to (156.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (2.75, 11.875) {Alice}; +\\node [style=none] (10) at (5.25, 11.875) {Bob}; +\\node [style=none] (15) at (7.75, 11.875) {cake}; +\\node [style=none] (20) at (10.25, 11.875) {coffee}; +\\node [style=none] (25) at (4.0, 9.375) {told}; +\\node [style=none] (30) at (6.5, 6.625) {and}; +\\node [style=none] (39) at (1.25, 2.625) {eats}; +\\node [style=none] (48) at (6.5, 2.625) {drinks}; +\\node [style=none] (57) at (11.75, 5.125) {runs}; +\\node [style=none] (62) at (11.75, 2.625) {x}; +\\node [style=none] (67) at (10.5, 0.125) {y}; +\\node [style=none] (72) at (7.75, -4.125) {test}; +\\node [style=none] (77) at (4.0, -4.125) {a}; +\\node [style=none] (82) at (9.0, -6.625) {b}; +\\node [style=none, right] (85) at (2.85, 11.525) {n}; +\\node [style=none, right] (88) at (5.35, 11.525) {n}; +\\node [style=none, right] (91) at (2.85, 9.025) {n}; +\\node [style=none, right] (94) at (5.35, 9.025) {n}; +\\node [style=none, right] (97) at (7.85, 11.525) {n}; +\\node [style=none, right] (100) at (10.35, 11.525) {n}; +\\node [style=none, right] (103) at (0.1, 3.625) {n}; +\\node [style=none, right] (106) at (2.6, 3.625) {n}; +\\node [style=none, right] (109) at (0.1, 2.275) {n}; +\\node [style=none, right] (112) at (2.6, 2.275) {n}; +\\node [style=none, right] (115) at (5.35, 3.625) {n}; +\\node [style=none, right] (118) at (7.85, 3.625) {n}; +\\node [style=none, right] (121) at (5.35, 2.275) {n}; +\\node [style=none, right] (124) at (7.85, 2.275) {n}; +\\node [style=none, right] (127) at (11.85, 6.125) {n}; +\\node [style=none, right] (130) at (11.85, 4.775) {n}; +\\node [style=none, right] (133) at (10.6, 2.275) {s}; +\\node [style=none, right] (136) at (10.6, -0.225) {s}; +\\node [style=none, right] (139) at (13.1, 2.275) {s}; +\\node [style=none, right] (142) at (6.6, -1.975) {n}; +\\node [style=none, right] (145) at (9.1, -1.975) {n}; +\\node [style=none, right] (148) at (4.1, -1.975) {n}; +\\node [style=none, right] (151) at (9.1, -4.475) {n}; +\\node [style=none, right] (154) at (4.1, -4.475) {n}; +\\node [style=none, right] (157) at (6.6, -4.475) {n}; \\end{pgfonlayer} \\end{tikzpicture} @@ -605,7 +619,7 @@ def test_drawable_generation(diagram, drawable): @pytest.mark.parametrize('diagram, tikz', zip(diagrams, tikz_outputs)) def test_tikz_drawing(diagram, tikz, capsys): - diagram.draw(backend=TikzBackend(), color_boxes=False) + diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=False, color_boxes=False) tikz_op, _ = capsys.readouterr() assert tikz_op == tikz @@ -614,7 +628,7 @@ def test_tikz_drawing(diagram, tikz, capsys): @pytest.mark.parametrize('diagram, tikz', zip(diagrams, colored_tikz_outputs)) def test_tikz_colored_drawing(diagram, tikz, capsys): - diagram.draw(backend=TikzBackend(), color_boxes=True) + diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=True, color_boxes=True) tikz_op, _ = capsys.readouterr() assert tikz_op == tikz From c829e4f38c757bea55d5de5b5eda2bca722f032a Mon Sep 17 00:00:00 2001 From: ragunathc Date: Wed, 20 Nov 2024 12:32:01 +0000 Subject: [PATCH 31/41] change label flag as hidden by default --- tests/backend/test_frame_drawing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/backend/test_frame_drawing.py b/tests/backend/test_frame_drawing.py index 9383849f..08fb0b01 100644 --- a/tests/backend/test_frame_drawing.py +++ b/tests/backend/test_frame_drawing.py @@ -619,7 +619,7 @@ def test_drawable_generation(diagram, drawable): @pytest.mark.parametrize('diagram, tikz', zip(diagrams, tikz_outputs)) def test_tikz_drawing(diagram, tikz, capsys): - diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=False, color_boxes=False) + diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=False, color_boxes=False, draw_type_labels=True) tikz_op, _ = capsys.readouterr() @@ -629,7 +629,7 @@ def test_tikz_drawing(diagram, tikz, capsys): @pytest.mark.parametrize('diagram, tikz', zip(diagrams, colored_tikz_outputs)) def test_tikz_colored_drawing(diagram, tikz, capsys): - diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=True, color_boxes=True) + diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=True, color_boxes=True, draw_type_labels=True) tikz_op, _ = capsys.readouterr() From 99ed5e4fe2b273410fd6867c791fad7eb54d2eea Mon Sep 17 00:00:00 2001 From: "Neil John D. Ortega" Date: Thu, 21 Nov 2024 10:37:12 +0000 Subject: [PATCH 32/41] Fix code formatting --- lambeq/backend/drawing/drawing.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 66bafd0b..106666fa 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -133,12 +133,14 @@ def draw(diagram: Diagram, **params) -> None: backend = TikzBackend( use_tikzstyles=params.get('use_tikzstyles', None), wires_linewidth=params.get('wires_linewidth', - WIRES_DEFAULT_WIDTH_TIKZ)) + WIRES_DEFAULT_WIDTH_TIKZ) + ) else: - backend = ( - MatBackend(figsize=params.get('figsize', None), - wires_linewidth=params.get('wires_linewidth', - WIRES_DEFAULT_WIDTH_MAT))) + backend = MatBackend( + figsize=params.get('figsize', None), + wires_linewidth=params.get('wires_linewidth', + WIRES_DEFAULT_WIDTH_MAT) + ) min_size = 0.01 max_v = max([v for point in ([point.coordinates for point in From 5ee51b2677dd7439d7f95fc0690d074bc17cb1b8 Mon Sep 17 00:00:00 2001 From: "Neil John D. Ortega" Date: Thu, 21 Nov 2024 11:19:19 +0000 Subject: [PATCH 33/41] Update constants --- lambeq/backend/drawing/drawing.py | 18 ++++++++++-------- lambeq/backend/drawing/mat_backend.py | 15 ++++++++++----- lambeq/backend/drawing/tikz_backend.py | 12 ++++++++---- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 106666fa..f774f02f 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -43,13 +43,15 @@ FRAME_COLORS, WIRE_COLORS) from lambeq.backend.drawing.helpers import drawn_as_spider, needs_asymmetry -from lambeq.backend.drawing.mat_backend import MatBackend +from lambeq.backend.drawing.mat_backend import ( + MatBackend, WIRE_LINEWIDTH as MAT_WIRE_LINEWIDTH +) from lambeq.backend.drawing.text_printer import PregroupTextPrinter -from lambeq.backend.drawing.tikz_backend import TikzBackend +from lambeq.backend.drawing.tikz_backend import ( + TikzBackend, WIRE_LINEWIDTH as TIKZ_WIRE_LINEWIDTH +) from lambeq.backend.grammar import Box, Diagram -WIRES_DEFAULT_WIDTH_MAT = 1.25 -WIRES_DEFAULT_WIDTH_TIKZ = 1.25 * 0.4 # Tikz default standard is 0.4pt if TYPE_CHECKING: from IPython.core.display import HTML as HTML_ty @@ -132,14 +134,14 @@ def draw(diagram: Diagram, **params) -> None: elif params.get('to_tikz', False): backend = TikzBackend( use_tikzstyles=params.get('use_tikzstyles', None), - wires_linewidth=params.get('wires_linewidth', - WIRES_DEFAULT_WIDTH_TIKZ) + wire_linewidth=params.get('wire_linewidth', + TIKZ_WIRE_LINEWIDTH) ) else: backend = MatBackend( figsize=params.get('figsize', None), - wires_linewidth=params.get('wires_linewidth', - WIRES_DEFAULT_WIDTH_MAT) + wire_linewidth=params.get('wire_linewidth', + MAT_WIRE_LINEWIDTH) ) min_size = 0.01 diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index d2ab058f..2f598b87 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -31,22 +31,27 @@ from lambeq.backend.grammar import Spider +BOX_LINEWIDTH = 1.0 +WIRE_LINEWIDTH = BOX_LINEWIDTH * 1.25 +FONTSIZE = 12 + + class MatBackend(DrawingBackend): """ Matplotlib drawing backend. """ def __init__(self, axis: plt.Axes | None = None, figsize: tuple | None = None, - box_linewidth: float = 1, - wires_linewidth: float = 1.25): + box_linewidth: float = BOX_LINEWIDTH, + wire_linewidth: float = WIRE_LINEWIDTH): self.axis = axis or plt.subplots(figsize=figsize, facecolor='white')[1] self.default_aspect = 'equal' if figsize is None else 'auto' self.box_linewidth = box_linewidth - self.wires_linewidth = wires_linewidth + self.wire_linewidth = wire_linewidth self.max_width: float = 0 def draw_text(self, text: str, x: float, y: float, **params) -> None: - params['fontsize'] = params.get('fontsize', 12) + params['fontsize'] = params.get('fontsize', FONTSIZE) self.axis.text(x, y, text, **params) self.max_width = max(self.max_width, x) @@ -112,7 +117,7 @@ def draw_wire(self, ]) self.axis.add_patch(PathPatch(path, facecolor='none', - linewidth=self.wires_linewidth, + linewidth=self.wire_linewidth, edgecolor=color)) self.max_width = max(self.max_width, source[0], target[0]) diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index 698c137e..c8d3b640 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -30,11 +30,15 @@ from lambeq.backend.grammar import Spider +BOX_LINEWIDTH = 0.4 +WIRE_LINEWIDTH = BOX_LINEWIDTH * 1.25 + + class TikzBackend(DrawingBackend): """ Tikz drawing backend. """ def __init__(self, use_tikzstyles: bool = False, - wires_linewidth: float = 0.4): + wire_linewidth: float = WIRE_LINEWIDTH): self.use_tikzstyles = use_tikzstyles self.node_styles: list[str] = [] self.edge_styles: list[str] = [] @@ -43,7 +47,7 @@ def __init__(self, use_tikzstyles: bool = False, self.edgelayer: list[str] = [] self.label_layer: list[str] = [] self.max_width: float = 0 - self.wires_linewidth = wires_linewidth + self.wire_linewidth = wire_linewidth @staticmethod def format_color(color: str) -> str: @@ -174,7 +178,7 @@ def draw_wire(self, # Concatenate additional styles like looseness if present if style: wire_style += f', {style}' - wire_style += f', line width={self.wires_linewidth}]\n' + wire_style += f', line width={self.wire_linewidth}]\n' if wire_style not in self.edge_styles: self.edge_styles.append(wire_style) @@ -182,7 +186,7 @@ def draw_wire(self, else: wire_options = f'-, draw={self.format_wire_color(color)}' - wire_options += f', line width={self.wires_linewidth}' + wire_options += f', line width={self.wire_linewidth}' if style: wire_options += f', {style}' cmd = ( From 294cd72f1ce6dd4c33d278e1cbc5611adc49761b Mon Sep 17 00:00:00 2001 From: "Neil John D. Ortega" Date: Thu, 21 Nov 2024 11:54:36 +0000 Subject: [PATCH 34/41] Update tests for Tikz circuit --- tests/backend/test_circuit_drawing.py | 672 ++++++++++++++------------ 1 file changed, 358 insertions(+), 314 deletions(-) diff --git a/tests/backend/test_circuit_drawing.py b/tests/backend/test_circuit_drawing.py index 59c27778..819d9382 100644 --- a/tests/backend/test_circuit_drawing.py +++ b/tests/backend/test_circuit_drawing.py @@ -16,6 +16,7 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): (qubit @ CX @ qubit >> qubit @ H @ qubit @ qubit >> qubit @ Bra(0) @ Bra(0) @ qubit >> CX >> H @ qubit >> Bra(0) @ Bra(0)), # Nested cups + # TODO: Doublecheck why 'U2' label is not centered (Controlled(X, 1) @Id(qubit) >> Controlled(X, -1) @ qubit >> qubit @ Controlled(X, 1) >> qubit @ Controlled(X, -1) >> Controlled(X, 2) >> Controlled(X, -2) >> qubit @ Controlled(U,-1) >> @@ -25,6 +26,7 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): (Controlled(Controlled(X, 1), 1) >> Controlled(Controlled(X,-1), 1) >> Controlled(Controlled(X, -1), -1)), # Multi-controlled X + # TODO: Check wavy discard on Tikz (Ket(0, 1) @ MixedState() @ Encode() >> Measure() @ Bra(0, 1) @ Discard()), # Initialisation and measurement @@ -34,26 +36,27 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): ] -tikz_outputs = ["""\\begin{tikzpicture}[baseline=(0.base)] +tikz_outputs = ["""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 1.75) {}; \\node [] (2) at (0.5, 1.75) {}; \\node [] (3) at (0.0, 2.25) {}; -\\node [style=none, fill=white] (4) at (0, 2.0) {0}; \\node [] (5) at (2.0, 1.75) {}; \\node [] (6) at (3.0, 1.75) {}; \\node [] (7) at (2.5, 2.25) {}; -\\node [style=none, fill=white] (8) at (2.5, 2.0) {0}; \\node [] (9) at (4.5, 1.75) {}; \\node [] (10) at (5.5, 1.75) {}; \\node [] (11) at (5.0, 2.25) {}; -\\node [style=none, fill=white] (12) at (5.0, 2.0) {0}; \\node [] (13) at (-0.5, 0.75) {}; \\node [] (14) at (0.5, 0.75) {}; \\node [] (15) at (0.5, 1.25) {}; \\node [] (16) at (-0.5, 1.25) {}; -\\node [style=none, fill=white] (17) at (0.0, 1.0) {H}; \\node [circle, black] (18) at (0.0, 0.0) {}; \\node [circle, white] (19) at (2.5, 0.0) {}; \\node [plus] (20) at (2.5, 0.0) {}; @@ -70,45 +73,56 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (31) at (2.5, -0.75) {}; \\node [] (32) at (0.0, 1.75) {}; \\node [] (33) at (0.0, 1.25) {}; -\\node [style=none, fill=white, right] (34) at (0.1, 1.65) {qubit}; \\node [] (35) at (0.0, 0.75) {}; -\\node [style=none, fill=white, right] (36) at (0.1, 0.65) {qubit}; \\node [] (37) at (2.5, 1.75) {}; -\\node [style=none, fill=white, right] (38) at (2.6, 1.65) {qubit}; -\\node [style=none, fill=white, right] (39) at (2.6, -0.35) {qubit}; \\node [] (40) at (5.0, 1.75) {}; -\\node [style=none, fill=white, right] (41) at (5.1, 1.65) {qubit}; \\node [] (42) at (0.0, -2.0) {}; -\\node [style=none, fill=white, right] (43) at (0.1, -0.35) {qubit}; \\node [] (44) at (2.5, -2.0) {}; -\\node [style=none, fill=white, right] (45) at (2.6, -1.35) {qubit}; \\node [] (46) at (5.0, -2.0) {}; -\\node [style=none, fill=white, right] (47) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (1.center); -\\draw [-, fill={white}] (5.center) to (6.center) to (7.center) to (5.center); -\\draw [-, fill={white}] (9.center) to (10.center) to (11.center) to (9.center); -\\draw [-, fill={white}] (13.center) to (14.center) to (15.center) to (16.center) to (13.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (23.center) to (24.center); -\\draw [in=180, out=0] (18.center) to (20.center); -\\draw [in=90, out=-90] (28.center) to (29.center); -\\draw [in=90, out=-90] (30.center) to (31.center); -\\draw [in=180, out=0] (25.center) to (27.center); -\\draw [in=90, out=-90] (32.center) to (33.center); -\\draw [in=90, out=-90] (35.center) to (24.center); -\\draw [in=90, out=-90] (37.center) to (22.center); -\\draw [in=90, out=-90] (21.center) to (31.center); -\\draw [in=90, out=-90] (40.center) to (29.center); -\\draw [in=90, out=-90] (23.center) to (42.center); -\\draw [in=90, out=-90] (30.center) to (44.center); -\\draw [in=90, out=-90] (28.center) to (46.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (5.center) to (6.center) to (7.center) to (5.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (9.center) to (10.center) to (11.center) to (9.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (13.center) to (14.center) to (15.center) to (16.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (23.center) to (24.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (18.center) to (20.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (28.center) to (29.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (30.center) to (31.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (25.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (32.center) to (33.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (35.center) to (24.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (37.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (31.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (40.center) to (29.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (23.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (30.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (28.center) to (46.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (4) at (0, 2.0) {0}; +\\node [style=none] (8) at (2.5, 2.0) {0}; +\\node [style=none] (12) at (5.0, 2.0) {0}; +\\node [style=none] (17) at (0.0, 1.0) {H}; +\\node [style=none, right] (34) at (0.1, 1.65) {qubit}; +\\node [style=none, right] (36) at (0.1, 0.65) {qubit}; +\\node [style=none, right] (38) at (2.6, 1.65) {qubit}; +\\node [style=none, right] (39) at (2.6, -0.35) {qubit}; +\\node [style=none, right] (41) at (5.1, 1.65) {qubit}; +\\node [style=none, right] (43) at (0.1, -0.35) {qubit}; +\\node [style=none, right] (45) at (2.6, -1.35) {qubit}; +\\node [style=none, right] (47) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [circle, black] (1) at (2.5, 2.0) {}; @@ -122,15 +136,12 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (9) at (3.0, 0.75) {}; \\node [] (10) at (3.0, 1.25) {}; \\node [] (11) at (2.0, 1.25) {}; -\\node [style=none, fill=white] (12) at (2.5, 1.0) {H}; \\node [] (13) at (2.0, 0.25) {}; \\node [] (14) at (3.0, 0.25) {}; \\node [] (15) at (2.5, -0.25) {}; -\\node [style=none, fill=white] (16) at (2.5, 0.0) {0}; \\node [] (17) at (4.5, 1.25) {}; \\node [] (18) at (5.5, 1.25) {}; \\node [] (19) at (5.0, 0.75) {}; -\\node [style=none, fill=white] (20) at (5.0, 1.0) {0}; \\node [circle, black] (21) at (0.0, -1.0) {}; \\node [circle, white] (22) at (7.5, -1.0) {}; \\node [plus] (23) at (7.5, -1.0) {}; @@ -142,66 +153,76 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (29) at (0.5, -2.25) {}; \\node [] (30) at (0.5, -1.75) {}; \\node [] (31) at (-0.5, -1.75) {}; -\\node [style=none, fill=white] (32) at (0.0, -2.0) {H}; \\node [] (33) at (-0.5, -2.75) {}; \\node [] (34) at (0.5, -2.75) {}; \\node [] (35) at (0.0, -3.25) {}; -\\node [style=none, fill=white] (36) at (0.0, -3.0) {0}; \\node [] (37) at (7.0, -1.75) {}; \\node [] (38) at (8.0, -1.75) {}; \\node [] (39) at (7.5, -2.25) {}; -\\node [style=none, fill=white] (40) at (7.5, -2.0) {0}; \\node [] (41) at (2.5, 3.0) {}; -\\node [style=none, fill=white, right] (42) at (2.6, 3.0) {qubit}; \\node [] (43) at (5.0, 3.0) {}; -\\node [style=none, fill=white, right] (44) at (5.1, 3.0) {qubit}; \\node [] (45) at (2.5, 1.25) {}; -\\node [style=none, fill=white, right] (46) at (2.6, 1.65) {qubit}; \\node [] (47) at (2.5, 0.75) {}; \\node [] (48) at (2.5, 0.25) {}; -\\node [style=none, fill=white, right] (49) at (2.6, 0.65) {qubit}; \\node [] (50) at (5.0, 1.25) {}; -\\node [style=none, fill=white, right] (51) at (5.1, 1.65) {qubit}; \\node [] (52) at (0.0, 3.0) {}; -\\node [style=none, fill=white, right] (53) at (0.1, 3.0) {qubit}; \\node [] (54) at (7.5, 3.0) {}; -\\node [style=none, fill=white, right] (55) at (7.6, 3.0) {qubit}; \\node [] (56) at (0.0, -1.75) {}; -\\node [style=none, fill=white, right] (57) at (0.1, -1.35) {qubit}; \\node [] (58) at (0.0, -2.25) {}; \\node [] (59) at (0.0, -2.75) {}; -\\node [style=none, fill=white, right] (60) at (0.1, -2.35) {qubit}; \\node [] (61) at (7.5, -1.75) {}; -\\node [style=none, fill=white, right] (62) at (7.6, -1.35) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [in=90, out=-90] (4.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=180, out=0] (1.center) to (3.center); -\\draw [-, fill={white}] (8.center) to (9.center) to (10.center) to (11.center) to (8.center); -\\draw [-, fill={white}] (13.center) to (14.center) to (15.center) to (13.center); -\\draw [-, fill={white}] (17.center) to (18.center) to (19.center) to (17.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=-90] (26.center) to (27.center); -\\draw [in=180, out=0] (21.center) to (23.center); -\\draw [-, fill={white}] (28.center) to (29.center) to (30.center) to (31.center) to (28.center); -\\draw [-, fill={white}] (33.center) to (34.center) to (35.center) to (33.center); -\\draw [-, fill={white}] (37.center) to (38.center) to (39.center) to (37.center); -\\draw [in=90, out=-90] (41.center) to (7.center); -\\draw [in=90, out=-90] (43.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (45.center); -\\draw [in=90, out=-90] (47.center) to (48.center); -\\draw [in=90, out=-90] (4.center) to (50.center); -\\draw [in=90, out=-90] (52.center) to (27.center); -\\draw [in=90, out=-90] (54.center) to (25.center); -\\draw [in=90, out=-90] (26.center) to (56.center); -\\draw [in=90, out=-90] (58.center) to (59.center); -\\draw [in=90, out=-90] (24.center) to (61.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (4.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (7.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (1.center) to (3.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (8.center) to (9.center) to (10.center) to (11.center) to (8.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (13.center) to (14.center) to (15.center) to (13.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (17.center) to (18.center) to (19.center) to (17.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (24.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (26.center) to (27.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (23.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (28.center) to (29.center) to (30.center) to (31.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (33.center) to (34.center) to (35.center) to (33.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (37.center) to (38.center) to (39.center) to (37.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (41.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (43.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (45.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (47.center) to (48.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (4.center) to (50.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (52.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (54.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (26.center) to (56.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (58.center) to (59.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (24.center) to (61.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (12) at (2.5, 1.0) {H}; +\\node [style=none] (16) at (2.5, 0.0) {0}; +\\node [style=none] (20) at (5.0, 1.0) {0}; +\\node [style=none] (32) at (0.0, -2.0) {H}; +\\node [style=none] (36) at (0.0, -3.0) {0}; +\\node [style=none] (40) at (7.5, -2.0) {0}; +\\node [style=none, right] (42) at (2.6, 3.0) {qubit}; +\\node [style=none, right] (44) at (5.1, 3.0) {qubit}; +\\node [style=none, right] (46) at (2.6, 1.65) {qubit}; +\\node [style=none, right] (49) at (2.6, 0.65) {qubit}; +\\node [style=none, right] (51) at (5.1, 1.65) {qubit}; +\\node [style=none, right] (53) at (0.1, 3.0) {qubit}; +\\node [style=none, right] (55) at (7.6, 3.0) {qubit}; +\\node [style=none, right] (57) at (0.1, -1.35) {qubit}; +\\node [style=none, right] (60) at (0.1, -2.35) {qubit}; +\\node [style=none, right] (62) at (7.6, -1.35) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [circle, black] (1) at (0.0, 5.5) {}; @@ -255,7 +276,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (49) at (3.0, -0.75) {}; \\node [] (50) at (3.0, -0.25) {}; \\node [] (51) at (2.0, -0.25) {}; -\\node [style=none, fill=white] (52) at (2.5, -0.5) {U}; \\node [] (53) at (5.0, -0.75) {}; \\node [] (54) at (5.0, -0.25) {}; \\node [] (55) at (3.0, -0.5) {}; @@ -264,7 +284,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (58) at (3.0, -1.75) {}; \\node [] (59) at (3.0, -1.25) {}; \\node [] (60) at (2.0, -1.25) {}; -\\node [style=none, fill=white] (61) at (2.5, -1.5) {U}; \\node [] (62) at (0.0, -1.75) {}; \\node [] (63) at (0.0, -1.25) {}; \\node [] (64) at (2.0, -1.5) {}; @@ -273,7 +292,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (67) at (0.5, -2.75) {}; \\node [] (68) at (0.5, -2.25) {}; \\node [] (69) at (-0.5, -2.25) {}; -\\node [style=none, fill=white] (70) at (0.0, -2.5) {U}; \\node [] (71) at (5.0, -2.75) {}; \\node [] (72) at (5.0, -2.25) {}; \\node [] (73) at (2.5, -2.75) {}; @@ -284,7 +302,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (78) at (5.5, -3.75) {}; \\node [] (79) at (5.5, -3.25) {}; \\node [] (80) at (4.5, -3.25) {}; -\\node [style=none, fill=white] (81) at (5.0, -3.5) {U}; \\node [] (82) at (0.0, -3.75) {}; \\node [] (83) at (0.0, -3.25) {}; \\node [] (84) at (2.5, -3.75) {}; @@ -295,7 +312,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (89) at (3.0, -4.75) {}; \\node [] (90) at (3.0, -4.25) {}; \\node [] (91) at (-0.5, -4.25) {}; -\\node [style=none, fill=white] (92) at (2.0, -4.5) {U2}; \\node [] (93) at (5.0, -4.75) {}; \\node [] (94) at (5.0, -4.25) {}; \\node [] (95) at (3.0, -4.5) {}; @@ -304,145 +320,157 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (98) at (5.5, -5.75) {}; \\node [] (99) at (5.5, -5.25) {}; \\node [] (100) at (2.0, -5.25) {}; -\\node [style=none, fill=white] (101) at (3.0, -5.5) {U2}; \\node [] (102) at (0.0, -5.75) {}; \\node [] (103) at (0.0, -5.25) {}; \\node [] (104) at (2.0, -5.5) {}; \\node [] (105) at (0.0, 6.5) {}; -\\node [style=none, fill=white, right] (106) at (0.1, 6.5) {qubit}; \\node [] (107) at (2.5, 6.5) {}; -\\node [style=none, fill=white, right] (108) at (2.6, 6.5) {qubit}; -\\node [style=none, fill=white, right] (109) at (0.1, 5.15) {qubit}; -\\node [style=none, fill=white, right] (110) at (2.6, 5.15) {qubit}; -\\node [style=none, fill=white, right] (111) at (2.6, 4.15) {qubit}; \\node [] (112) at (5.0, 6.5) {}; -\\node [style=none, fill=white, right] (113) at (5.1, 6.5) {qubit}; -\\node [style=none, fill=white, right] (114) at (2.6, 3.15) {qubit}; -\\node [style=none, fill=white, right] (115) at (5.1, 3.15) {qubit}; -\\node [style=none, fill=white, right] (116) at (0.1, 4.15) {qubit}; -\\node [style=none, fill=white, right] (117) at (2.6, 2.15) {qubit}; -\\node [style=none, fill=white, right] (118) at (5.1, 2.15) {qubit}; -\\node [style=none, fill=white, right] (119) at (0.1, 1.15) {qubit}; -\\node [style=none, fill=white, right] (120) at (2.6, 1.15) {qubit}; -\\node [style=none, fill=white, right] (121) at (5.1, 1.15) {qubit}; \\node [] (122) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (123) at (2.6, 0.15) {qubit}; -\\node [style=none, fill=white, right] (124) at (5.1, 0.15) {qubit}; -\\node [style=none, fill=white, right] (125) at (0.1, 0.15) {qubit}; \\node [] (126) at (2.5, -0.75) {}; \\node [] (127) at (2.5, -1.25) {}; -\\node [style=none, fill=white, right] (128) at (2.6, -0.85) {qubit}; \\node [] (129) at (0.0, -2.25) {}; -\\node [style=none, fill=white, right] (130) at (0.1, -1.85) {qubit}; \\node [] (131) at (2.5, -1.75) {}; -\\node [style=none, fill=white, right] (132) at (2.6, -1.85) {qubit}; -\\node [style=none, fill=white, right] (133) at (5.1, -0.85) {qubit}; \\node [] (134) at (0.0, -2.75) {}; -\\node [style=none, fill=white, right] (135) at (0.1, -2.85) {qubit}; -\\node [style=none, fill=white, right] (136) at (2.6, -2.85) {qubit}; \\node [] (137) at (5.0, -3.25) {}; -\\node [style=none, fill=white, right] (138) at (5.1, -2.85) {qubit}; \\node [] (139) at (0.0, -4.25) {}; -\\node [style=none, fill=white, right] (140) at (0.1, -3.85) {qubit}; \\node [] (141) at (2.5, -4.25) {}; -\\node [style=none, fill=white, right] (142) at (2.6, -3.85) {qubit}; \\node [] (143) at (5.0, -3.75) {}; -\\node [style=none, fill=white, right] (144) at (5.1, -3.85) {qubit}; \\node [] (145) at (0.0, -4.75) {}; -\\node [style=none, fill=white, right] (146) at (0.1, -4.85) {qubit}; \\node [] (147) at (2.5, -4.75) {}; \\node [] (148) at (2.5, -5.25) {}; -\\node [style=none, fill=white, right] (149) at (2.6, -4.85) {qubit}; \\node [] (150) at (5.0, -5.25) {}; -\\node [style=none, fill=white, right] (151) at (5.1, -4.85) {qubit}; \\node [] (152) at (0.0, -6.5) {}; -\\node [style=none, fill=white, right] (153) at (0.1, -5.85) {qubit}; \\node [] (154) at (2.5, -5.75) {}; \\node [] (155) at (2.5, -6.5) {}; -\\node [style=none, fill=white, right] (156) at (2.6, -5.85) {qubit}; \\node [] (157) at (5.0, -5.75) {}; \\node [] (158) at (5.0, -6.5) {}; -\\node [style=none, fill=white, right] (159) at (5.1, -5.85) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [in=90, out=-90] (4.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=180, out=0] (1.center) to (3.center); -\\draw [in=90, out=-90] (11.center) to (12.center); -\\draw [in=90, out=-90] (13.center) to (14.center); -\\draw [in=0, out=180] (8.center) to (10.center); -\\draw [in=90, out=-90] (18.center) to (19.center); -\\draw [in=90, out=-90] (20.center) to (21.center); -\\draw [in=180, out=0] (15.center) to (17.center); -\\draw [in=90, out=-90] (25.center) to (26.center); -\\draw [in=90, out=-90] (27.center) to (28.center); -\\draw [in=0, out=180] (22.center) to (24.center); -\\draw [in=90, out=-90] (32.center) to (33.center); -\\draw [in=90, out=-90] (34.center) to (35.center); -\\draw [in=90, out=-90] (36.center) to (37.center); -\\draw [in=180, out=0] (29.center) to (31.center); -\\draw [in=90, out=-90] (41.center) to (42.center); -\\draw [in=90, out=-90] (43.center) to (44.center); -\\draw [in=90, out=-90] (45.center) to (46.center); -\\draw [in=0, out=180] (38.center) to (40.center); -\\draw [-, fill={white}] (48.center) to (49.center) to (50.center) to (51.center) to (48.center); -\\draw [in=90, out=-90] (53.center) to (54.center); -\\draw [in=0, out=180] (47.center) to (55.center); -\\draw [-, fill={white}] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); -\\draw [in=90, out=-90] (62.center) to (63.center); -\\draw [in=180, out=0] (56.center) to (64.center); -\\draw [-, fill={white}] (66.center) to (67.center) to (68.center) to (69.center) to (66.center); -\\draw [in=90, out=-90] (71.center) to (72.center); -\\draw [in=90, out=-90] (73.center) to (74.center); -\\draw [in=0, out=180] (65.center) to (75.center); -\\draw [-, fill={white}] (77.center) to (78.center) to (79.center) to (80.center) to (77.center); -\\draw [in=90, out=-90] (82.center) to (83.center); -\\draw [in=90, out=-90] (84.center) to (85.center); -\\draw [in=180, out=0] (76.center) to (86.center); -\\draw [-, fill={white}] (88.center) to (89.center) to (90.center) to (91.center) to (88.center); -\\draw [in=90, out=-90] (93.center) to (94.center); -\\draw [in=0, out=180] (87.center) to (95.center); -\\draw [-, fill={white}] (97.center) to (98.center) to (99.center) to (100.center) to (97.center); -\\draw [in=90, out=-90] (102.center) to (103.center); -\\draw [in=180, out=0] (96.center) to (104.center); -\\draw [in=90, out=-90] (105.center) to (7.center); -\\draw [in=90, out=-90] (107.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (12.center); -\\draw [in=90, out=-90] (4.center) to (14.center); -\\draw [in=90, out=-90] (13.center) to (21.center); -\\draw [in=90, out=-90] (112.center) to (19.center); -\\draw [in=90, out=-90] (20.center) to (26.center); -\\draw [in=90, out=-90] (18.center) to (28.center); -\\draw [in=90, out=-90] (11.center) to (35.center); -\\draw [in=90, out=-90] (25.center) to (37.center); -\\draw [in=90, out=-90] (27.center) to (33.center); -\\draw [in=90, out=-90] (34.center) to (42.center); -\\draw [in=90, out=-90] (36.center) to (46.center); -\\draw [in=90, out=-90] (32.center) to (44.center); -\\draw [in=90, out=-90] (45.center) to (122.center); -\\draw [in=90, out=-90] (43.center) to (54.center); -\\draw [in=90, out=-90] (41.center) to (63.center); -\\draw [in=90, out=-90] (126.center) to (127.center); -\\draw [in=90, out=-90] (62.center) to (129.center); -\\draw [in=90, out=-90] (131.center) to (74.center); -\\draw [in=90, out=-90] (53.center) to (72.center); -\\draw [in=90, out=-90] (134.center) to (83.center); -\\draw [in=90, out=-90] (73.center) to (85.center); -\\draw [in=90, out=-90] (71.center) to (137.center); -\\draw [in=90, out=-90] (82.center) to (139.center); -\\draw [in=90, out=-90] (84.center) to (141.center); -\\draw [in=90, out=-90] (143.center) to (94.center); -\\draw [in=90, out=-90] (145.center) to (103.center); -\\draw [in=90, out=-90] (147.center) to (148.center); -\\draw [in=90, out=-90] (93.center) to (150.center); -\\draw [in=90, out=-90] (102.center) to (152.center); -\\draw [in=90, out=-90] (154.center) to (155.center); -\\draw [in=90, out=-90] (157.center) to (158.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (4.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (7.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (1.center) to (3.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (11.center) to (12.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (13.center) to (14.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (8.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (18.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (20.center) to (21.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (17.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (25.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (27.center) to (28.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (22.center) to (24.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (32.center) to (33.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (34.center) to (35.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (36.center) to (37.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (29.center) to (31.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (41.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (43.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (45.center) to (46.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (38.center) to (40.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (48.center) to (49.center) to (50.center) to (51.center) to (48.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (53.center) to (54.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (47.center) to (55.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (62.center) to (63.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (56.center) to (64.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (66.center) to (67.center) to (68.center) to (69.center) to (66.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (71.center) to (72.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (73.center) to (74.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (65.center) to (75.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (77.center) to (78.center) to (79.center) to (80.center) to (77.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (82.center) to (83.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (84.center) to (85.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (76.center) to (86.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (88.center) to (89.center) to (90.center) to (91.center) to (88.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (93.center) to (94.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (87.center) to (95.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (97.center) to (98.center) to (99.center) to (100.center) to (97.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (102.center) to (103.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (96.center) to (104.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (105.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (107.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (12.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (4.center) to (14.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (13.center) to (21.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (112.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (20.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (18.center) to (28.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (11.center) to (35.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (25.center) to (37.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (27.center) to (33.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (34.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (36.center) to (46.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (32.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (45.center) to (122.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (43.center) to (54.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (41.center) to (63.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (126.center) to (127.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (62.center) to (129.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (131.center) to (74.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (53.center) to (72.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (134.center) to (83.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (73.center) to (85.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (71.center) to (137.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (82.center) to (139.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (84.center) to (141.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (143.center) to (94.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (145.center) to (103.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (147.center) to (148.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (93.center) to (150.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (102.center) to (152.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (154.center) to (155.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (157.center) to (158.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (52) at (2.5, -0.5) {U}; +\\node [style=none] (61) at (2.5, -1.5) {U}; +\\node [style=none] (70) at (0.0, -2.5) {U}; +\\node [style=none] (81) at (5.0, -3.5) {U}; +\\node [style=none] (92) at (2.0, -4.5) {U2}; +\\node [style=none] (101) at (3.0, -5.5) {U2}; +\\node [style=none, right] (106) at (0.1, 6.5) {qubit}; +\\node [style=none, right] (108) at (2.6, 6.5) {qubit}; +\\node [style=none, right] (109) at (0.1, 5.15) {qubit}; +\\node [style=none, right] (110) at (2.6, 5.15) {qubit}; +\\node [style=none, right] (111) at (2.6, 4.15) {qubit}; +\\node [style=none, right] (113) at (5.1, 6.5) {qubit}; +\\node [style=none, right] (114) at (2.6, 3.15) {qubit}; +\\node [style=none, right] (115) at (5.1, 3.15) {qubit}; +\\node [style=none, right] (116) at (0.1, 4.15) {qubit}; +\\node [style=none, right] (117) at (2.6, 2.15) {qubit}; +\\node [style=none, right] (118) at (5.1, 2.15) {qubit}; +\\node [style=none, right] (119) at (0.1, 1.15) {qubit}; +\\node [style=none, right] (120) at (2.6, 1.15) {qubit}; +\\node [style=none, right] (121) at (5.1, 1.15) {qubit}; +\\node [style=none, right] (123) at (2.6, 0.15) {qubit}; +\\node [style=none, right] (124) at (5.1, 0.15) {qubit}; +\\node [style=none, right] (125) at (0.1, 0.15) {qubit}; +\\node [style=none, right] (128) at (2.6, -0.85) {qubit}; +\\node [style=none, right] (130) at (0.1, -1.85) {qubit}; +\\node [style=none, right] (132) at (2.6, -1.85) {qubit}; +\\node [style=none, right] (133) at (5.1, -0.85) {qubit}; +\\node [style=none, right] (135) at (0.1, -2.85) {qubit}; +\\node [style=none, right] (136) at (2.6, -2.85) {qubit}; +\\node [style=none, right] (138) at (5.1, -2.85) {qubit}; +\\node [style=none, right] (140) at (0.1, -3.85) {qubit}; +\\node [style=none, right] (142) at (2.6, -3.85) {qubit}; +\\node [style=none, right] (144) at (5.1, -3.85) {qubit}; +\\node [style=none, right] (146) at (0.1, -4.85) {qubit}; +\\node [style=none, right] (149) at (2.6, -4.85) {qubit}; +\\node [style=none, right] (151) at (5.1, -4.85) {qubit}; +\\node [style=none, right] (153) at (0.1, -5.85) {qubit}; +\\node [style=none, right] (156) at (2.6, -5.85) {qubit}; +\\node [style=none, right] (159) at (5.1, -5.85) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [circle, black] (1) at (0.0, 1.0) {}; @@ -476,77 +504,80 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (29) at (5.0, -1.25) {}; \\node [] (30) at (5.0, -0.75) {}; \\node [] (31) at (0.0, 2.0) {}; -\\node [style=none, fill=white, right] (32) at (0.1, 2.0) {qubit}; \\node [] (33) at (2.5, 2.0) {}; -\\node [style=none, fill=white, right] (34) at (2.6, 2.0) {qubit}; \\node [] (35) at (5.0, 2.0) {}; -\\node [style=none, fill=white, right] (36) at (5.1, 2.0) {qubit}; -\\node [style=none, fill=white, right] (37) at (0.1, 0.65) {qubit}; -\\node [style=none, fill=white, right] (38) at (2.6, 0.65) {qubit}; -\\node [style=none, fill=white, right] (39) at (5.1, 0.65) {qubit}; -\\node [style=none, fill=white, right] (40) at (0.1, -0.35) {qubit}; -\\node [style=none, fill=white, right] (41) at (2.6, -0.35) {qubit}; -\\node [style=none, fill=white, right] (42) at (5.1, -0.35) {qubit}; \\node [] (43) at (0.0, -2.0) {}; -\\node [style=none, fill=white, right] (44) at (0.1, -1.35) {qubit}; \\node [] (45) at (2.5, -2.0) {}; -\\node [style=none, fill=white, right] (46) at (2.6, -1.35) {qubit}; \\node [] (47) at (5.0, -2.0) {}; -\\node [style=none, fill=white, right] (48) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [in=90, out=-90] (5.center) to (6.center); -\\draw [in=90, out=-90] (7.center) to (8.center); -\\draw [in=180, out=0] (2.center) to (4.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=180, out=0] (1.center) to (2.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=90, out=-90] (17.center) to (18.center); -\\draw [in=0, out=180] (12.center) to (14.center); -\\draw [in=90, out=-90] (19.center) to (20.center); -\\draw [in=180, out=0] (11.center) to (14.center); -\\draw [in=90, out=-90] (25.center) to (26.center); -\\draw [in=90, out=-90] (27.center) to (28.center); -\\draw [in=0, out=180] (22.center) to (24.center); -\\draw [in=90, out=-90] (29.center) to (30.center); -\\draw [in=0, out=180] (21.center) to (22.center); -\\draw [in=90, out=-90] (31.center) to (10.center); -\\draw [in=90, out=-90] (33.center) to (8.center); -\\draw [in=90, out=-90] (35.center) to (6.center); -\\draw [in=90, out=-90] (9.center) to (20.center); -\\draw [in=90, out=-90] (7.center) to (16.center); -\\draw [in=90, out=-90] (5.center) to (18.center); -\\draw [in=90, out=-90] (19.center) to (26.center); -\\draw [in=90, out=-90] (15.center) to (28.center); -\\draw [in=90, out=-90] (17.center) to (30.center); -\\draw [in=90, out=-90] (25.center) to (43.center); -\\draw [in=90, out=-90] (27.center) to (45.center); -\\draw [in=90, out=-90] (29.center) to (47.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (5.center) to (6.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (7.center) to (8.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (2.center) to (4.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (9.center) to (10.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (1.center) to (2.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (17.center) to (18.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (12.center) to (14.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (19.center) to (20.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (11.center) to (14.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (25.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (27.center) to (28.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (22.center) to (24.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (29.center) to (30.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (31.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (33.center) to (8.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (35.center) to (6.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (9.center) to (20.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (7.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (5.center) to (18.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (19.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (28.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (17.center) to (30.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (25.center) to (43.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (27.center) to (45.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (29.center) to (47.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none, right] (32) at (0.1, 2.0) {qubit}; +\\node [style=none, right] (34) at (2.6, 2.0) {qubit}; +\\node [style=none, right] (36) at (5.1, 2.0) {qubit}; +\\node [style=none, right] (37) at (0.1, 0.65) {qubit}; +\\node [style=none, right] (38) at (2.6, 0.65) {qubit}; +\\node [style=none, right] (39) at (5.1, 0.65) {qubit}; +\\node [style=none, right] (40) at (0.1, -0.35) {qubit}; +\\node [style=none, right] (41) at (2.6, -0.35) {qubit}; +\\node [style=none, right] (42) at (5.1, -0.35) {qubit}; +\\node [style=none, right] (44) at (0.1, -1.35) {qubit}; +\\node [style=none, right] (46) at (2.6, -1.35) {qubit}; +\\node [style=none, right] (48) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.25) {}; \\node [] (2) at (0.5, 0.25) {}; \\node [] (3) at (0.0, 0.75) {}; -\\node [style=none, fill=white] (4) at (0.0, 0.5) {0}; \\node [] (5) at (2.0, 0.25) {}; \\node [] (6) at (3.0, 0.25) {}; \\node [] (7) at (2.5, 0.75) {}; -\\node [style=none, fill=white] (8) at (2.5, 0.5) {1}; \\node [] (9) at (4.5, 0.25) {}; \\node [] (10) at (5.5, 0.25) {}; \\node [] (11) at (5.5, 0.75) {}; \\node [] (12) at (4.5, 0.75) {}; -\\node [style=none, fill=white] (13) at (5.0, 0.5) {MixedState}; \\node [] (14) at (7.0, 0.25) {}; \\node [] (15) at (8.0, 0.25) {}; \\node [] (16) at (8.0, 0.75) {}; \\node [] (17) at (7.0, 0.75) {}; -\\node [style=none, fill=white] (18) at (7.5, 0.5) {Encode}; \\node [] (19) at (-0.5, -0.75) {}; \\node [] (20) at (0.5, -0.75) {}; \\node [] (21) at (0.5, -0.25) {}; @@ -559,11 +590,9 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (28) at (2.0, -0.25) {}; \\node [] (29) at (3.0, -0.25) {}; \\node [] (30) at (2.5, -0.75) {}; -\\node [style=none, fill=white] (31) at (2.5, -0.5) {0}; \\node [] (32) at (4.5, -0.25) {}; \\node [] (33) at (5.5, -0.25) {}; \\node [] (34) at (5.0, -0.75) {}; -\\node [style=none, fill=white] (35) at (5.0, -0.5) {1}; \\node [] (36) at (7.0, -0.25) {}; \\node [] (37) at (8.0, -0.25) {}; \\node [] (38) at (7.1, -0.35) {}; @@ -572,194 +601,209 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (41) at (7.8, -0.45) {}; \\node [] (42) at (7.5, 1.5) {}; \\node [] (43) at (7.5, 0.75) {}; -\\node [style=none, fill=white, right] (44) at (7.6, 1.5) {bit}; \\node [] (45) at (0.0, 0.25) {}; \\node [] (46) at (0.0, -0.25) {}; -\\node [style=none, fill=white, right] (47) at (0.1, 0.15) {qubit}; \\node [] (48) at (2.5, 0.25) {}; \\node [] (49) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (50) at (2.6, 0.15) {qubit}; \\node [] (51) at (5.0, 0.25) {}; \\node [] (52) at (5.0, -0.25) {}; -\\node [style=none, fill=white, right] (53) at (5.1, 0.15) {qubit}; \\node [] (54) at (7.5, 0.25) {}; \\node [] (55) at (7.5, -0.25) {}; -\\node [style=none, fill=white, right] (56) at (7.6, 0.15) {qubit}; \\node [] (57) at (0.0, -0.75) {}; \\node [] (58) at (0.0, -1.5) {}; -\\node [style=none, fill=white, right] (59) at (0.1, -0.85) {bit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (1.center); -\\draw [-, fill={white}] (5.center) to (6.center) to (7.center) to (5.center); -\\draw [-, fill={white}] (9.center) to (10.center) to (11.center) to (12.center) to (9.center); -\\draw [-, fill={white}] (14.center) to (15.center) to (16.center) to (17.center) to (14.center); -\\draw [-, fill={white}] (19.center) to (20.center) to (21.center) to (22.center) to (19.center); -\\draw [in=180, out=-90, looseness=1.26] (23.center) to (24.center); -\\draw [in=90, out=0, looseness=1.26] (24.center) to (25.center); -\\draw [in=90, out=-90, ->looseness=0.4118] (26.center) to (27.center); -\\draw [-, fill={white}] (28.center) to (29.center) to (30.center) to (28.center); -\\draw [-, fill={white}] (32.center) to (33.center) to (34.center) to (32.center); -\\draw [in=90, out=-90] (36.center) to (37.center); -\\draw [in=90, out=-90] (38.center) to (39.center); -\\draw [in=90, out=-90] (40.center) to (41.center); -\\draw [in=90, out=-90] (42.center) to (43.center); -\\draw [in=90, out=-90] (45.center) to (46.center); -\\draw [in=90, out=-90] (48.center) to (49.center); -\\draw [in=90, out=-90] (51.center) to (52.center); -\\draw [in=90, out=-90] (54.center) to (55.center); -\\draw [in=90, out=-90] (57.center) to (58.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (5.center) to (6.center) to (7.center) to (5.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (9.center) to (10.center) to (11.center) to (12.center) to (9.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (14.center) to (15.center) to (16.center) to (17.center) to (14.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (19.center) to (20.center) to (21.center) to (22.center) to (19.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=1.26] (23.center) to (24.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=1.26] (24.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, ->looseness=0.4118] (26.center) to (27.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (28.center) to (29.center) to (30.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (32.center) to (33.center) to (34.center) to (32.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (36.center) to (37.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (38.center) to (39.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (40.center) to (41.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (42.center) to (43.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (45.center) to (46.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (48.center) to (49.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (51.center) to (52.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (54.center) to (55.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (57.center) to (58.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (4) at (0.0, 0.5) {0}; +\\node [style=none] (8) at (2.5, 0.5) {1}; +\\node [style=none] (13) at (5.0, 0.5) {MixedState}; +\\node [style=none] (18) at (7.5, 0.5) {Encode}; +\\node [style=none] (31) at (2.5, -0.5) {0}; +\\node [style=none] (35) at (5.0, -0.5) {1}; +\\node [style=none, right] (44) at (7.6, 1.5) {bit}; +\\node [style=none, right] (47) at (0.1, 0.15) {qubit}; +\\node [style=none, right] (50) at (2.6, 0.15) {qubit}; +\\node [style=none, right] (53) at (5.1, 0.15) {qubit}; +\\node [style=none, right] (56) at (7.6, 0.15) {qubit}; +\\node [style=none, right] (59) at (0.1, -0.85) {bit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 1.25) {}; \\node [] (2) at (0.5, 1.25) {}; \\node [] (3) at (0.0, 1.75) {}; -\\node [style=none, fill=white] (4) at (0.0, 1.5) {0}; \\node [] (5) at (2.0, 1.25) {}; \\node [] (6) at (3.0, 1.25) {}; \\node [] (7) at (2.5, 1.75) {}; -\\node [style=none, fill=white] (8) at (2.5, 1.5) {0}; \\node [] (9) at (7.0, 1.25) {}; \\node [] (10) at (8.0, 1.25) {}; \\node [] (11) at (7.5, 1.75) {}; -\\node [style=none, fill=white] (12) at (7.5, 1.5) {0}; \\node [] (13) at (9.5, 1.25) {}; \\node [] (14) at (10.5, 1.25) {}; \\node [] (15) at (10.0, 1.75) {}; -\\node [style=none, fill=white] (16) at (10.0, 1.5) {0}; \\node [] (17) at (-0.5, 0.25) {}; \\node [] (18) at (0.5, 0.25) {}; \\node [] (19) at (0.5, 0.75) {}; \\node [] (20) at (-0.5, 0.75) {}; -\\node [style=none, fill=white] (21) at (0.0, 0.5) {S}; \\node [] (22) at (2.0, 0.25) {}; \\node [] (23) at (3.0, 0.25) {}; \\node [] (24) at (3.0, 0.75) {}; \\node [] (25) at (2.0, 0.75) {}; -\\node [style=none, fill=white] (26) at (2.5, 0.5) {X}; \\node [] (27) at (7.0, 0.25) {}; \\node [] (28) at (8.0, 0.25) {}; \\node [] (29) at (8.0, 0.75) {}; \\node [] (30) at (7.0, 0.75) {}; -\\node [style=none, fill=white] (31) at (7.5, 0.5) {Y}; \\node [] (32) at (9.5, 0.25) {}; \\node [] (33) at (10.5, 0.25) {}; \\node [] (34) at (10.5, 0.75) {}; \\node [] (35) at (9.5, 0.75) {}; -\\node [style=none, fill=white] (36) at (10.0, 0.5) {Z}; \\node [] (37) at (-0.5, -0.75) {}; \\node [] (38) at (0.5, -0.75) {}; \\node [] (39) at (0.5, -0.25) {}; \\node [] (40) at (-0.5, -0.25) {}; -\\node [style=none, fill=white] (41) at (0.0, -0.5) {Rx(0.3)}; \\node [] (42) at (2.0, -0.75) {}; \\node [] (43) at (3.0, -0.75) {}; \\node [] (44) at (3.0, -0.25) {}; \\node [] (45) at (2.0, -0.25) {}; -\\node [style=none, fill=white] (46) at (2.5, -0.5) {Ry(0.2)}; \\node [] (47) at (4.5, 1.25) {}; \\node [] (48) at (5.5, 1.25) {}; \\node [] (49) at (5.5, 1.75) {}; \\node [] (50) at (4.5, 1.75) {}; -\\node [style=none, fill=white] (51) at (5.0, 1.5) {0.500}; \\node [] (52) at (7.0, -0.75) {}; \\node [] (53) at (8.0, -0.75) {}; \\node [] (54) at (8.0, -0.25) {}; \\node [] (55) at (7.0, -0.25) {}; -\\node [style=none, fill=white] (56) at (7.5, -0.5) {Rz(0.1)}; \\node [] (57) at (9.5, -0.75) {}; \\node [] (58) at (10.5, -0.75) {}; \\node [] (59) at (10.5, -0.25) {}; \\node [] (60) at (9.5, -0.25) {}; -\\node [style=none, fill=white] (61) at (10.0, -0.5) {H}; \\node [] (62) at (-0.5, -1.25) {}; \\node [] (63) at (0.5, -1.25) {}; \\node [] (64) at (0.0, -1.75) {}; -\\node [style=none, fill=white] (65) at (0.0, -1.5) {0}; \\node [] (66) at (2.0, -1.25) {}; \\node [] (67) at (3.0, -1.25) {}; \\node [] (68) at (2.5, -1.75) {}; -\\node [style=none, fill=white] (69) at (2.5, -1.5) {0}; \\node [] (70) at (7.0, -1.25) {}; \\node [] (71) at (8.0, -1.25) {}; \\node [] (72) at (7.5, -1.75) {}; -\\node [style=none, fill=white] (73) at (7.5, -1.5) {0}; \\node [] (74) at (9.5, -1.25) {}; \\node [] (75) at (10.5, -1.25) {}; \\node [] (76) at (10.0, -1.75) {}; -\\node [style=none, fill=white] (77) at (10.0, -1.5) {0}; \\node [] (78) at (0.0, 1.25) {}; \\node [] (79) at (0.0, 0.75) {}; -\\node [style=none, fill=white, right] (80) at (0.1, 1.15) {qubit}; \\node [] (81) at (2.5, 1.25) {}; \\node [] (82) at (2.5, 0.75) {}; -\\node [style=none, fill=white, right] (83) at (2.6, 1.15) {qubit}; \\node [] (84) at (7.5, 1.25) {}; \\node [] (85) at (7.5, 0.75) {}; -\\node [style=none, fill=white, right] (86) at (7.6, 1.15) {qubit}; \\node [] (87) at (10.0, 1.25) {}; \\node [] (88) at (10.0, 0.75) {}; -\\node [style=none, fill=white, right] (89) at (10.1, 1.15) {qubit}; \\node [] (90) at (0.0, 0.25) {}; \\node [] (91) at (0.0, -0.25) {}; -\\node [style=none, fill=white, right] (92) at (0.1, 0.15) {qubit}; \\node [] (93) at (2.5, 0.25) {}; \\node [] (94) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (95) at (2.6, 0.15) {qubit}; \\node [] (96) at (7.5, 0.25) {}; \\node [] (97) at (7.5, -0.25) {}; -\\node [style=none, fill=white, right] (98) at (7.6, 0.15) {qubit}; \\node [] (99) at (10.0, 0.25) {}; \\node [] (100) at (10.0, -0.25) {}; -\\node [style=none, fill=white, right] (101) at (10.1, 0.15) {qubit}; \\node [] (102) at (0.0, -0.75) {}; \\node [] (103) at (0.0, -1.25) {}; -\\node [style=none, fill=white, right] (104) at (0.1, -0.85) {qubit}; \\node [] (105) at (2.5, -0.75) {}; \\node [] (106) at (2.5, -1.25) {}; -\\node [style=none, fill=white, right] (107) at (2.6, -0.85) {qubit}; \\node [] (108) at (7.5, -0.75) {}; \\node [] (109) at (7.5, -1.25) {}; -\\node [style=none, fill=white, right] (110) at (7.6, -0.85) {qubit}; \\node [] (111) at (10.0, -0.75) {}; \\node [] (112) at (10.0, -1.25) {}; -\\node [style=none, fill=white, right] (113) at (10.1, -0.85) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (1.center); -\\draw [-, fill={white}] (5.center) to (6.center) to (7.center) to (5.center); -\\draw [-, fill={white}] (9.center) to (10.center) to (11.center) to (9.center); -\\draw [-, fill={white}] (13.center) to (14.center) to (15.center) to (13.center); -\\draw [-, fill={white}] (17.center) to (18.center) to (19.center) to (20.center) to (17.center); -\\draw [-, fill={white}] (22.center) to (23.center) to (24.center) to (25.center) to (22.center); -\\draw [-, fill={white}] (27.center) to (28.center) to (29.center) to (30.center) to (27.center); -\\draw [-, fill={white}] (32.center) to (33.center) to (34.center) to (35.center) to (32.center); -\\draw [-, fill={white}] (37.center) to (38.center) to (39.center) to (40.center) to (37.center); -\\draw [-, fill={white}] (42.center) to (43.center) to (44.center) to (45.center) to (42.center); -\\draw [-, fill={white}] (47.center) to (48.center) to (49.center) to (50.center) to (47.center); -\\draw [-, fill={white}] (52.center) to (53.center) to (54.center) to (55.center) to (52.center); -\\draw [-, fill={white}] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); -\\draw [-, fill={white}] (62.center) to (63.center) to (64.center) to (62.center); -\\draw [-, fill={white}] (66.center) to (67.center) to (68.center) to (66.center); -\\draw [-, fill={white}] (70.center) to (71.center) to (72.center) to (70.center); -\\draw [-, fill={white}] (74.center) to (75.center) to (76.center) to (74.center); -\\draw [in=90, out=-90] (78.center) to (79.center); -\\draw [in=90, out=-90] (81.center) to (82.center); -\\draw [in=90, out=-90] (84.center) to (85.center); -\\draw [in=90, out=-90] (87.center) to (88.center); -\\draw [in=90, out=-90] (90.center) to (91.center); -\\draw [in=90, out=-90] (93.center) to (94.center); -\\draw [in=90, out=-90] (96.center) to (97.center); -\\draw [in=90, out=-90] (99.center) to (100.center); -\\draw [in=90, out=-90] (102.center) to (103.center); -\\draw [in=90, out=-90] (105.center) to (106.center); -\\draw [in=90, out=-90] (108.center) to (109.center); -\\draw [in=90, out=-90] (111.center) to (112.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (5.center) to (6.center) to (7.center) to (5.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (9.center) to (10.center) to (11.center) to (9.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (13.center) to (14.center) to (15.center) to (13.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (17.center) to (18.center) to (19.center) to (20.center) to (17.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (22.center) to (23.center) to (24.center) to (25.center) to (22.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (27.center) to (28.center) to (29.center) to (30.center) to (27.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (32.center) to (33.center) to (34.center) to (35.center) to (32.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (37.center) to (38.center) to (39.center) to (40.center) to (37.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (42.center) to (43.center) to (44.center) to (45.center) to (42.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (47.center) to (48.center) to (49.center) to (50.center) to (47.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (52.center) to (53.center) to (54.center) to (55.center) to (52.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (62.center) to (63.center) to (64.center) to (62.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (66.center) to (67.center) to (68.center) to (66.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (70.center) to (71.center) to (72.center) to (70.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (74.center) to (75.center) to (76.center) to (74.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (78.center) to (79.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (81.center) to (82.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (84.center) to (85.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (87.center) to (88.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (90.center) to (91.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (93.center) to (94.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (96.center) to (97.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (99.center) to (100.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (102.center) to (103.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (105.center) to (106.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (108.center) to (109.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (111.center) to (112.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (4) at (0.0, 1.5) {0}; +\\node [style=none] (8) at (2.5, 1.5) {0}; +\\node [style=none] (12) at (7.5, 1.5) {0}; +\\node [style=none] (16) at (10.0, 1.5) {0}; +\\node [style=none] (21) at (0.0, 0.5) {S}; +\\node [style=none] (26) at (2.5, 0.5) {X}; +\\node [style=none] (31) at (7.5, 0.5) {Y}; +\\node [style=none] (36) at (10.0, 0.5) {Z}; +\\node [style=none] (41) at (0.0, -0.5) {Rx(0.3)}; +\\node [style=none] (46) at (2.5, -0.5) {Ry(0.2)}; +\\node [style=none] (51) at (5.0, 1.5) {0.500}; +\\node [style=none] (56) at (7.5, -0.5) {Rz(0.1)}; +\\node [style=none] (61) at (10.0, -0.5) {H}; +\\node [style=none] (65) at (0.0, -1.5) {0}; +\\node [style=none] (69) at (2.5, -1.5) {0}; +\\node [style=none] (73) at (7.5, -1.5) {0}; +\\node [style=none] (77) at (10.0, -1.5) {0}; +\\node [style=none, right] (80) at (0.1, 1.15) {qubit}; +\\node [style=none, right] (83) at (2.6, 1.15) {qubit}; +\\node [style=none, right] (86) at (7.6, 1.15) {qubit}; +\\node [style=none, right] (89) at (10.1, 1.15) {qubit}; +\\node [style=none, right] (92) at (0.1, 0.15) {qubit}; +\\node [style=none, right] (95) at (2.6, 0.15) {qubit}; +\\node [style=none, right] (98) at (7.6, 0.15) {qubit}; +\\node [style=none, right] (101) at (10.1, 0.15) {qubit}; +\\node [style=none, right] (104) at (0.1, -0.85) {qubit}; +\\node [style=none, right] (107) at (2.6, -0.85) {qubit}; +\\node [style=none, right] (110) at (7.6, -0.85) {qubit}; +\\node [style=none, right] (113) at (10.1, -0.85) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} From 02b35f3b7d206ead11d151b6744adce875e0fe7b Mon Sep 17 00:00:00 2001 From: "Neil John D. Ortega" Date: Thu, 21 Nov 2024 12:04:40 +0000 Subject: [PATCH 35/41] Update tests for Tikz diagrams --- tests/backend/test_drawing.py | 290 +++++++++++++++++++--------------- 1 file changed, 166 insertions(+), 124 deletions(-) diff --git a/tests/backend/test_drawing.py b/tests/backend/test_drawing.py index e2146245..89d4b6e0 100644 --- a/tests/backend/test_drawing.py +++ b/tests/backend/test_drawing.py @@ -188,201 +188,236 @@ tikz_outputs = [ -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, -0.25) {}; \\node [] (2) at (3.0, -0.25) {}; \\node [] (3) at (3.0, 0.25) {}; \\node [] (4) at (-0.5, 0.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 0.0) {BX1}; \\node [] (6) at (1.25, 1.0) {}; \\node [] (7) at (1.25, 0.25) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 1.0) {s}; \\node [] (9) at (0.0, -0.25) {}; \\node [] (10) at (0.0, -1.0) {}; -\\node [style=none, fill=white, right] (11) at (0.1, -0.35) {s}; \\node [] (12) at (2.5, -0.25) {}; \\node [] (13) at (2.5, -1.0) {}; -\\node [style=none, fill=white, right] (14) at (2.6, -0.35) {s}; \\node [] (15) at (5.0, 1.0) {}; \\node [] (16) at (5.0, -1.0) {}; -\\node [style=none, fill=white, right] (17) at (5.1, 1.0) {s}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (16.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 0.0) {BX1}; +\\node [style=none, right] (8) at (1.35, 1.0) {s}; +\\node [style=none, right] (11) at (0.1, -0.35) {s}; +\\node [style=none, right] (14) at (2.6, -0.35) {s}; +\\node [style=none, right] (17) at (5.1, 1.0) {s}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.25) {}; \\node [] (2) at (3.0, 0.25) {}; \\node [] (3) at (3.25, 0.75) {}; \\node [] (4) at (-0.5, 0.75) {}; -\\node [style=none, fill=white] (5) at (1.25, 0.5) {BX1}; \\node [] (6) at (-0.5, -0.75) {}; \\node [] (7) at (3.25, -0.75) {}; \\node [] (8) at (3.0, -0.25) {}; \\node [] (9) at (-0.5, -0.25) {}; -\\node [style=none, fill=white] (10) at (1.25, -0.5) {BX1†}; \\node [] (11) at (1.25, 1.5) {}; \\node [] (12) at (1.25, 0.75) {}; -\\node [style=none, fill=white, right] (13) at (1.35, 1.5) {s}; \\node [] (14) at (0.0, 0.25) {}; \\node [] (15) at (0.0, -0.25) {}; -\\node [style=none, fill=white, right] (16) at (0.1, 0.15) {s}; \\node [] (17) at (2.5, 0.25) {}; \\node [] (18) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (19) at (2.6, 0.15) {s}; \\node [] (20) at (1.25, -0.75) {}; \\node [] (21) at (1.25, -1.5) {}; -\\node [style=none, fill=white, right] (22) at (1.35, -0.85) {s}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={white}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [in=90, out=-90] (11.center) to (12.center); -\\draw [in=90, out=-90] (14.center) to (15.center); -\\draw [in=90, out=-90] (17.center) to (18.center); -\\draw [in=90, out=-90] (20.center) to (21.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (11.center) to (12.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (14.center) to (15.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (17.center) to (18.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (20.center) to (21.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 0.5) {BX1}; +\\node [style=none] (10) at (1.25, -0.5) {BX1†}; +\\node [style=none, right] (13) at (1.35, 1.5) {s}; +\\node [style=none, right] (16) at (0.1, 0.15) {s}; +\\node [style=none, right] (19) at (2.6, 0.15) {s}; +\\node [style=none, right] (22) at (1.35, -0.85) {s}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.25) {}; \\node [] (2) at (3.0, 0.25) {}; \\node [] (3) at (3.0, 0.75) {}; \\node [] (4) at (-0.5, 0.75) {}; -\\node [style=none, fill=white] (5) at (1.25, 0.5) {BX1}; \\node [] (6) at (1.25, 1.5) {}; \\node [] (7) at (1.25, 0.75) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 1.5) {s}; \\node [] (9) at (2.5, 0.25) {}; \\node [] (10) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (11) at (2.6, 0.15) {s}; \\node [] (12) at (5.0, 1.5) {}; \\node [] (13) at (5.0, -0.25) {}; -\\node [style=none, fill=white, right] (14) at (5.1, 1.5) {s.r}; \\node [] (15) at (0.0, 0.25) {}; \\node [] (16) at (0.0, -1.5) {}; -\\node [style=none, fill=white, right] (17) at (0.1, 0.15) {s}; \\node [] (18) at (3.75, -0.5) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=180, out=-90, looseness=0.4118] (10.center) to (18.center); -\\draw [in=0, out=-90, looseness=0.4118] (13.center) to (18.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (16.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (10.center) to (18.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (13.center) to (18.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 0.5) {BX1}; +\\node [style=none, right] (8) at (1.35, 1.5) {s}; +\\node [style=none, right] (11) at (2.6, 0.15) {s}; +\\node [style=none, right] (14) at (5.1, 1.5) {s.r}; +\\node [style=none, right] (17) at (0.1, 0.15) {s}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.75) {}; \\node [] (2) at (3.0, 0.75) {}; \\node [] (3) at (3.0, 1.25) {}; \\node [] (4) at (-0.5, 1.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 1.0) {BX2}; \\node [] (6) at (1.25, 2.0) {}; \\node [] (7) at (1.25, 1.25) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 2.0) {s}; \\node [] (9) at (2.5, 0.75) {}; \\node [] (10) at (2.5, 0.25) {}; -\\node [style=none, fill=white, right] (11) at (2.6, 0.65) {s.r}; \\node [] (12) at (5.0, 2.0) {}; \\node [] (13) at (5.0, 0.25) {}; -\\node [style=none, fill=white, right] (14) at (5.1, 2.0) {s.r}; \\node [] (15) at (7.5, 2.0) {}; \\node [] (16) at (7.5, 0.25) {}; -\\node [style=none, fill=white, right] (17) at (7.6, 2.0) {s.r}; \\node [] (18) at (0.0, 0.75) {}; \\node [] (19) at (0.0, -0.75) {}; -\\node [style=none, fill=white, right] (20) at (0.1, 0.65) {s}; \\node [] (21) at (3.75, -0.25) {}; \\node [] (22) at (3.75, -0.75) {}; -\\node [style=none, fill=white, right] (23) at (3.85, -0.35) {s.r}; \\node [] (24) at (6.25, -0.25) {}; \\node [] (25) at (6.25, -2.0) {}; -\\node [style=none, fill=white, right] (26) at (6.35, -0.35) {s.r}; \\node [circle, fill=black, scale=0.365] (27) at (5.0, 0.0) {}; \\node [] (28) at (1.875, -1.0) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=90, out=-90] (18.center) to (19.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=180, looseness=0.4118] (27.center) to (21.center); -\\draw [in=90, out=0, looseness=0.4118] (27.center) to (24.center); -\\draw [in=180, out=-90, looseness=0.209] (10.center) to (27.center); -\\draw [in=90, out=-90] (13.center) to (27.center); -\\draw [in=0, out=-90, looseness=0.209] (16.center) to (27.center); -\\draw [in=180, out=-90, looseness=0.2775] (19.center) to (28.center); -\\draw [in=0, out=-90, looseness=0.2775] (22.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (18.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (24.center) to (25.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (27.center) to (21.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (27.center) to (24.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (10.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (13.center) to (27.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (16.center) to (27.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.2775] (19.center) to (28.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.2775] (22.center) to (28.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 1.0) {BX2}; +\\node [style=none, right] (8) at (1.35, 2.0) {s}; +\\node [style=none, right] (11) at (2.6, 0.65) {s.r}; +\\node [style=none, right] (14) at (5.1, 2.0) {s.r}; +\\node [style=none, right] (17) at (7.6, 2.0) {s.r}; +\\node [style=none, right] (20) at (0.1, 0.65) {s}; +\\node [style=none, right] (23) at (3.85, -0.35) {s.r}; +\\node [style=none, right] (26) at (6.35, -0.35) {s.r}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (0.75, 0.75) {}; \\node [] (2) at (1.75, 0.75) {}; \\node [] (3) at (2.0, 1.25) {}; \\node [] (4) at (0.75, 1.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 1.0) {BX3}; \\node [] (6) at (-0.5, -0.25) {}; \\node [] (7) at (3.0, -0.25) {}; \\node [] (8) at (3.25, 0.25) {}; \\node [] (9) at (-0.5, 0.25) {}; -\\node [style=none, fill=white] (10) at (1.25, 0.0) {BX1}; \\node [] (11) at (2.0, -1.25) {}; \\node [] (12) at (3.25, -1.25) {}; \\node [] (13) at (3.0, -0.75) {}; \\node [] (14) at (2.0, -0.75) {}; -\\node [style=none, fill=white] (15) at (2.5, -1.0) {BX3†}; \\node [] (16) at (-0.5, -1.25) {}; \\node [] (17) at (0.75, -1.25) {}; \\node [] (18) at (0.5, -0.75) {}; \\node [] (19) at (-0.5, -0.75) {}; -\\node [style=none, fill=white] (20) at (0.0, -1.0) {BX3†}; \\node [] (21) at (1.25, 0.75) {}; \\node [] (22) at (1.25, 0.25) {}; -\\node [style=none, fill=white, right] (23) at (1.35, 0.65) {s}; \\node [] (24) at (2.5, -0.25) {}; \\node [] (25) at (2.5, -0.75) {}; -\\node [style=none, fill=white, right] (26) at (2.6, -0.35) {s}; \\node [] (27) at (0.0, -0.25) {}; \\node [] (28) at (0.0, -0.75) {}; -\\node [style=none, fill=white, right] (29) at (0.1, -0.35) {s}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={white}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [-, fill={white}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); -\\draw [-, fill={white}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=-90] (27.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (24.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (27.center) to (28.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 1.0) {BX3}; +\\node [style=none] (10) at (1.25, 0.0) {BX1}; +\\node [style=none] (15) at (2.5, -1.0) {BX3†}; +\\node [style=none] (20) at (0.0, -1.0) {BX3†}; +\\node [style=none, right] (23) at (1.35, 0.65) {s}; +\\node [style=none, right] (26) at (2.6, -0.35) {s}; +\\node [style=none, right] (29) at (0.1, -0.35) {s}; \\end{pgfonlayer} \\end{tikzpicture} @@ -498,98 +533,105 @@ def test_tikz_drawing(diagram, tikz, capsys): assert tikz_op == tikz -expected_equation_tikz = """\\begin{tikzpicture}[baseline=(0.base)] +expected_equation_tikz = """% When embedding into a *.tex file, uncomment and include the following lines: +% \pgfdeclarelayer{nodelayer} +% \pgfdeclarelayer{edgelayer} +% \pgfdeclarelayer{labellayer} +% \pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.75) {}; \\node [] (2) at (3.0, 0.75) {}; \\node [] (3) at (3.25, 1.25) {}; \\node [] (4) at (-0.5, 1.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 1.0) {BX2}; \\node [] (6) at (1.25, 2.0) {}; \\node [] (7) at (1.25, 1.25) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 2.0) {s}; \\node [] (9) at (2.5, 0.75) {}; \\node [] (10) at (2.5, 0.25) {}; -\\node [style=none, fill=white, right] (11) at (2.6, 0.65) {s.r}; \\node [] (12) at (5.0, 2.0) {}; \\node [] (13) at (5.0, 0.25) {}; -\\node [style=none, fill=white, right] (14) at (5.1, 2.0) {s.r}; \\node [] (15) at (7.5, 2.0) {}; \\node [] (16) at (7.5, 0.25) {}; -\\node [style=none, fill=white, right] (17) at (7.6, 2.0) {s.r}; \\node [] (18) at (0.0, 0.75) {}; \\node [] (19) at (0.0, -0.75) {}; -\\node [style=none, fill=white, right] (20) at (0.1, 0.65) {s}; \\node [] (21) at (3.75, -0.25) {}; \\node [] (22) at (3.75, -0.75) {}; -\\node [style=none, fill=white, right] (23) at (3.85, -0.35) {s.r}; \\node [] (24) at (6.25, -0.25) {}; \\node [] (25) at (6.25, -2.0) {}; -\\node [style=none, fill=white, right] (26) at (6.35, -0.35) {s.r}; \\node [circle, fill=black, scale=0.365] (27) at (5.0, 0.0) {}; \\node [] (28) at (1.875, -1.0) {}; -\\node [style=none, fill=white] (29) at (8.6, 0) {=}; \\node [] (30) at (9.1, -1.25) {}; \\node [] (31) at (12.85, -1.25) {}; \\node [] (32) at (12.6, -0.75) {}; \\node [] (33) at (9.1, -0.75) {}; -\\node [style=none, fill=white] (34) at (10.85, -1.0) {BX2†}; \\node [] (35) at (13.35, 0.75) {}; \\node [] (36) at (13.35, 0.25) {}; -\\node [style=none, fill=white, right] (37) at (13.45, 0.65) {s.r}; \\node [] (38) at (15.85, 2.0) {}; \\node [] (39) at (15.85, 0.25) {}; -\\node [style=none, fill=white, right] (40) at (15.95, 2.0) {s.r}; \\node [] (41) at (9.6, 0.75) {}; \\node [] (42) at (9.6, -0.75) {}; -\\node [style=none, fill=white, right] (43) at (9.7, 0.65) {s}; \\node [] (44) at (12.1, -0.25) {}; \\node [] (45) at (12.1, -0.75) {}; -\\node [style=none, fill=white, right] (46) at (12.2, -0.35) {s.r}; \\node [] (47) at (10.85, -1.25) {}; \\node [] (48) at (10.85, -2.0) {}; -\\node [style=none, fill=white, right] (49) at (10.95, -1.35) {s}; \\node [] (50) at (14.6, -0.25) {}; \\node [] (51) at (14.6, -2.0) {}; -\\node [style=none, fill=white, right] (52) at (14.7, -0.35) {s.r}; \\node [] (53) at (17.1, -0.25) {}; \\node [] (54) at (17.1, -2.0) {}; -\\node [style=none, fill=white, right] (55) at (17.200000000000003, -0.35) {s.r}; \\node [] (56) at (12.1, 1.0) {}; \\node [circle, fill=black, scale=0.242] (57) at (14.6, 0.0) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=90, out=-90] (18.center) to (19.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=180, looseness=0.4118] (27.center) to (21.center); -\\draw [in=90, out=0, looseness=0.4118] (27.center) to (24.center); -\\draw [in=180, out=-90, looseness=0.209] (10.center) to (27.center); -\\draw [in=90, out=-90] (13.center) to (27.center); -\\draw [in=0, out=-90, looseness=0.209] (16.center) to (27.center); -\\draw [in=180, out=-90, looseness=0.2775] (19.center) to (28.center); -\\draw [in=0, out=-90, looseness=0.2775] (22.center) to (28.center); -\\draw [-, fill={white}] (30.center) to (31.center) to (32.center) to (33.center) to (30.center); -\\draw [in=90, out=-90] (35.center) to (36.center); -\\draw [in=90, out=-90] (38.center) to (39.center); -\\draw [in=90, out=-90] (41.center) to (42.center); -\\draw [in=90, out=-90] (44.center) to (45.center); -\\draw [in=90, out=-90] (47.center) to (48.center); -\\draw [in=90, out=-90] (50.center) to (51.center); -\\draw [in=90, out=-90] (53.center) to (54.center); -\\draw [in=90, out=180, looseness=0.209] (56.center) to (41.center); -\\draw [in=90, out=0, looseness=0.4118] (56.center) to (35.center); -\\draw [in=90, out=180, looseness=0.209] (57.center) to (44.center); -\\draw [in=90, out=-90] (57.center) to (50.center); -\\draw [in=90, out=0, looseness=0.209] (57.center) to (53.center); -\\draw [in=180, out=-90, looseness=0.4118] (36.center) to (57.center); -\\draw [in=0, out=-90, looseness=0.4118] (39.center) to (57.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (15.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (18.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (24.center) to (25.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (27.center) to (21.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (27.center) to (24.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (10.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (13.center) to (27.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (16.center) to (27.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.2775] (19.center) to (28.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.2775] (22.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (30.center) to (31.center) to (32.center) to (33.center) to (30.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (35.center) to (36.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (38.center) to (39.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (41.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (44.center) to (45.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (47.center) to (48.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (50.center) to (51.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (53.center) to (54.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (56.center) to (41.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (56.center) to (35.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (57.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (57.center) to (50.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.209] (57.center) to (53.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (36.center) to (57.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5, looseness=0.4118] (39.center) to (57.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 1.0) {BX2}; +\\node [style=none, right] (8) at (1.35, 2.0) {s}; +\\node [style=none, right] (11) at (2.6, 0.65) {s.r}; +\\node [style=none, right] (14) at (5.1, 2.0) {s.r}; +\\node [style=none, right] (17) at (7.6, 2.0) {s.r}; +\\node [style=none, right] (20) at (0.1, 0.65) {s}; +\\node [style=none, right] (23) at (3.85, -0.35) {s.r}; +\\node [style=none, right] (26) at (6.35, -0.35) {s.r}; +\\node [style=none] (29) at (8.6, 0) {=}; +\\node [style=none] (34) at (10.85, -1.0) {BX2†}; +\\node [style=none, right] (37) at (13.45, 0.65) {s.r}; +\\node [style=none, right] (40) at (15.95, 2.0) {s.r}; +\\node [style=none, right] (43) at (9.7, 0.65) {s}; +\\node [style=none, right] (46) at (12.2, -0.35) {s.r}; +\\node [style=none, right] (49) at (10.95, -1.35) {s}; +\\node [style=none, right] (52) at (14.7, -0.35) {s.r}; +\\node [style=none, right] (55) at (17.200000000000003, -0.35) {s.r}; \\end{pgfonlayer} \\end{tikzpicture} From 697a0ee3a95ec71656015a2d14379ad8a1694bf6 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 21 Nov 2024 16:34:33 +0000 Subject: [PATCH 36/41] add box_linewidth to Tikz backend --- lambeq/backend/drawing/drawing.py | 6 ++++-- lambeq/backend/drawing/tikz_backend.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index f774f02f..12075273 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -48,7 +48,8 @@ ) from lambeq.backend.drawing.text_printer import PregroupTextPrinter from lambeq.backend.drawing.tikz_backend import ( - TikzBackend, WIRE_LINEWIDTH as TIKZ_WIRE_LINEWIDTH + TikzBackend, WIRE_LINEWIDTH as TIKZ_WIRE_LINEWIDTH, + BOX_LINEWIDTH as TIKZ_BOX_LINEWIDTH ) from lambeq.backend.grammar import Box, Diagram @@ -135,7 +136,8 @@ def draw(diagram: Diagram, **params) -> None: backend = TikzBackend( use_tikzstyles=params.get('use_tikzstyles', None), wire_linewidth=params.get('wire_linewidth', - TIKZ_WIRE_LINEWIDTH) + TIKZ_WIRE_LINEWIDTH), + box_linewidth=params.get('box_linewidth', TIKZ_BOX_LINEWIDTH) ) else: backend = MatBackend( diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index c8d3b640..f6d54d96 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -38,7 +38,8 @@ class TikzBackend(DrawingBackend): """ Tikz drawing backend. """ def __init__(self, use_tikzstyles: bool = False, - wire_linewidth: float = WIRE_LINEWIDTH): + wire_linewidth: float = WIRE_LINEWIDTH, + box_linewidth: float = BOX_LINEWIDTH): self.use_tikzstyles = use_tikzstyles self.node_styles: list[str] = [] self.edge_styles: list[str] = [] @@ -48,6 +49,7 @@ def __init__(self, use_tikzstyles: bool = False, self.label_layer: list[str] = [] self.max_width: float = 0 self.wire_linewidth = wire_linewidth + self.box_linewidth = box_linewidth @staticmethod def format_color(color: str) -> str: @@ -129,12 +131,14 @@ def draw_polygon(self, *points: list[float], color: str = 'white') -> None: color_name = color.lstrip('#') style_name = 'box' if color == 'white' else f'{color_name}_box' style = (f'\\tikzstyle{{{style_name}}}=' - f'[-, fill={self.format_color(color)}]\n') + f'[-, fill={self.format_color(color)}') + style += f', line width={self.box_linewidth}pt]\n' if style not in self.edge_styles: self.edge_styles.append(style) options = f'style={style_name}' else: options = f'-, fill={self.format_color(color)}' + options += f', line width={self.box_linewidth}pt' str_connections = ' to '.join(f'({node}.center)' for node in nodes) self.edgelayer.append(f'\\draw [{options}] {str_connections};\n') @@ -178,7 +182,7 @@ def draw_wire(self, # Concatenate additional styles like looseness if present if style: wire_style += f', {style}' - wire_style += f', line width={self.wire_linewidth}]\n' + wire_style += f', line width={self.wire_linewidth}pt]\n' if wire_style not in self.edge_styles: self.edge_styles.append(wire_style) @@ -186,7 +190,7 @@ def draw_wire(self, else: wire_options = f'-, draw={self.format_wire_color(color)}' - wire_options += f', line width={self.wire_linewidth}' + wire_options += f', line width={self.wire_linewidth}pt' if style: wire_options += f', {style}' cmd = ( From 5d18c22da21d8535a92d93a35a6d19b7b618ddc5 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 21 Nov 2024 16:37:42 +0000 Subject: [PATCH 37/41] update frame-drawing tests with linewidth changes --- tests/backend/test_frame_drawing.py | 293 +++++++++++++--------------- 1 file changed, 134 insertions(+), 159 deletions(-) diff --git a/tests/backend/test_frame_drawing.py b/tests/backend/test_frame_drawing.py index 08fb0b01..d3e23053 100644 --- a/tests/backend/test_frame_drawing.py +++ b/tests/backend/test_frame_drawing.py @@ -294,48 +294,48 @@ \\node [] (156) at (6.5, -11.875) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (83.center) to (84.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (86.center) to (87.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (89.center) to (90.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (92.center) to (93.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (95.center) to (96.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (98.center) to (99.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (101.center) to (102.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (104.center) to (105.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (107.center) to (108.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (110.center) to (111.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (113.center) to (114.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (116.center) to (117.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (119.center) to (120.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (122.center) to (123.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (125.center) to (126.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (128.center) to (129.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (131.center) to (132.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (134.center) to (135.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (137.center) to (138.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (140.center) to (141.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (143.center) to (144.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (146.center) to (147.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (149.center) to (150.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (152.center) to (153.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (155.center) to (156.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (83.center) to (84.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (86.center) to (87.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (89.center) to (90.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (92.center) to (93.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (95.center) to (96.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (98.center) to (99.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (101.center) to (102.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (104.center) to (105.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (107.center) to (108.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (110.center) to (111.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (113.center) to (114.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (116.center) to (117.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (119.center) to (120.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (122.center) to (123.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (125.center) to (126.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (128.center) to (129.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (131.center) to (132.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (134.center) to (135.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (137.center) to (138.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (140.center) to (141.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (143.center) to (144.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (146.center) to (147.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (149.center) to (150.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (152.center) to (153.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (155.center) to (156.center); \\end{pgfonlayer} \\begin{pgfonlayer}{labellayer} \\node [style=none] (5) at (2.75, 11.875) {Alice}; @@ -463,98 +463,98 @@ \\node [] (81) at (8.5, -6.375) {}; \\node [] (83) at (2.75, 11.625) {}; \\node [] (84) at (2.75, 9.625) {}; -\\node [] (86) at (5.25, 11.625) {}; -\\node [] (87) at (5.25, 9.625) {}; -\\node [] (89) at (2.75, 9.125) {}; -\\node [] (90) at (2.75, 7.125) {}; -\\node [] (92) at (5.25, 9.125) {}; -\\node [] (93) at (5.25, 7.125) {}; -\\node [] (95) at (7.75, 11.625) {}; -\\node [] (96) at (7.75, 7.125) {}; -\\node [] (98) at (10.25, 11.625) {}; -\\node [] (99) at (10.25, 7.125) {}; -\\node [] (101) at (0.0, 3.625) {}; -\\node [] (102) at (0.0, 2.875) {}; -\\node [] (104) at (2.5, 3.625) {}; -\\node [] (105) at (2.5, 2.875) {}; -\\node [] (107) at (0.0, 2.375) {}; -\\node [] (108) at (0.0, 1.625) {}; -\\node [] (110) at (2.5, 2.375) {}; -\\node [] (111) at (2.5, 1.625) {}; -\\node [] (113) at (5.25, 3.625) {}; -\\node [] (114) at (5.25, 2.875) {}; -\\node [] (116) at (7.75, 3.625) {}; -\\node [] (117) at (7.75, 2.875) {}; -\\node [] (119) at (5.25, 2.375) {}; -\\node [] (120) at (5.25, 1.625) {}; -\\node [] (122) at (7.75, 2.375) {}; -\\node [] (123) at (7.75, 1.625) {}; -\\node [] (125) at (11.75, 6.125) {}; -\\node [] (126) at (11.75, 5.375) {}; -\\node [] (128) at (11.75, 4.875) {}; -\\node [] (129) at (11.75, 2.875) {}; -\\node [] (131) at (10.5, 2.375) {}; -\\node [] (132) at (10.5, 0.375) {}; -\\node [] (134) at (10.5, -0.125) {}; -\\node [] (135) at (10.5, -0.875) {}; -\\node [] (137) at (13.0, 2.375) {}; -\\node [] (138) at (13.0, -0.875) {}; -\\node [] (140) at (6.5, -1.875) {}; -\\node [] (141) at (6.5, -3.875) {}; -\\node [] (143) at (9.0, -1.875) {}; -\\node [] (144) at (9.0, -3.875) {}; -\\node [] (146) at (4.0, -1.875) {}; -\\node [] (147) at (4.0, -3.875) {}; -\\node [] (149) at (9.0, -4.375) {}; -\\node [] (150) at (9.0, -6.375) {}; -\\node [] (152) at (4.0, -4.375) {}; -\\node [] (153) at (4.0, -11.875) {}; -\\node [] (155) at (6.5, -4.375) {}; -\\node [] (156) at (6.5, -11.875) {}; +\\node [] (85) at (5.25, 11.625) {}; +\\node [] (86) at (5.25, 9.625) {}; +\\node [] (87) at (2.75, 9.125) {}; +\\node [] (88) at (2.75, 7.125) {}; +\\node [] (89) at (5.25, 9.125) {}; +\\node [] (90) at (5.25, 7.125) {}; +\\node [] (91) at (7.75, 11.625) {}; +\\node [] (92) at (7.75, 7.125) {}; +\\node [] (93) at (10.25, 11.625) {}; +\\node [] (94) at (10.25, 7.125) {}; +\\node [] (95) at (0.0, 3.625) {}; +\\node [] (96) at (0.0, 2.875) {}; +\\node [] (97) at (2.5, 3.625) {}; +\\node [] (98) at (2.5, 2.875) {}; +\\node [] (99) at (0.0, 2.375) {}; +\\node [] (100) at (0.0, 1.625) {}; +\\node [] (101) at (2.5, 2.375) {}; +\\node [] (102) at (2.5, 1.625) {}; +\\node [] (103) at (5.25, 3.625) {}; +\\node [] (104) at (5.25, 2.875) {}; +\\node [] (105) at (7.75, 3.625) {}; +\\node [] (106) at (7.75, 2.875) {}; +\\node [] (107) at (5.25, 2.375) {}; +\\node [] (108) at (5.25, 1.625) {}; +\\node [] (109) at (7.75, 2.375) {}; +\\node [] (110) at (7.75, 1.625) {}; +\\node [] (111) at (11.75, 6.125) {}; +\\node [] (112) at (11.75, 5.375) {}; +\\node [] (113) at (11.75, 4.875) {}; +\\node [] (114) at (11.75, 2.875) {}; +\\node [] (115) at (10.5, 2.375) {}; +\\node [] (116) at (10.5, 0.375) {}; +\\node [] (117) at (10.5, -0.125) {}; +\\node [] (118) at (10.5, -0.875) {}; +\\node [] (119) at (13.0, 2.375) {}; +\\node [] (120) at (13.0, -0.875) {}; +\\node [] (121) at (6.5, -1.875) {}; +\\node [] (122) at (6.5, -3.875) {}; +\\node [] (123) at (9.0, -1.875) {}; +\\node [] (124) at (9.0, -3.875) {}; +\\node [] (125) at (4.0, -1.875) {}; +\\node [] (126) at (4.0, -3.875) {}; +\\node [] (127) at (9.0, -4.375) {}; +\\node [] (128) at (9.0, -6.375) {}; +\\node [] (129) at (4.0, -4.375) {}; +\\node [] (130) at (4.0, -11.875) {}; +\\node [] (131) at (6.5, -4.375) {}; +\\node [] (132) at (6.5, -11.875) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); -\\draw [-, fill={rgb,255: red,255; green,249; blue,229}] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); -\\draw [-, fill={rgb,255: red,255; green,255; blue,255}] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); -\\draw [-, fill={rgb,255: red,224; green,224; blue,224}] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (83.center) to (84.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (86.center) to (87.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (89.center) to (90.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (92.center) to (93.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=0.5] (95.center) to (96.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,208; green,59; blue,45}, line width=0.5] (98.center) to (99.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (101.center) to (102.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (104.center) to (105.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (107.center) to (108.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (110.center) to (111.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (113.center) to (114.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (116.center) to (117.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (119.center) to (120.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (122.center) to (123.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (125.center) to (126.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (128.center) to (129.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (131.center) to (132.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (134.center) to (135.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5] (137.center) to (138.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (140.center) to (141.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=0.5] (143.center) to (144.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (146.center) to (147.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=0.5] (149.center) to (150.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=0.5] (152.center) to (153.center); -\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=0.5] (155.center) to (156.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (21.center) to (22.center) to (23.center) to (24.center) to (21.center); +\\draw [-, fill={rgb,255: red,255; green,249; blue,229}, line width=2pt] (26.center) to (27.center) to (28.center) to (29.center) to (26.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (31.center) to (32.center) to (33.center) to (34.center) to (31.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (35.center) to (36.center) to (37.center) to (38.center) to (35.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (40.center) to (41.center) to (42.center) to (43.center) to (40.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (44.center) to (45.center) to (46.center) to (47.center) to (44.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=2pt] (49.center) to (50.center) to (51.center) to (52.center) to (49.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (53.center) to (54.center) to (55.center) to (56.center) to (53.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (58.center) to (59.center) to (60.center) to (61.center) to (58.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (63.center) to (64.center) to (65.center) to (66.center) to (63.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (68.center) to (69.center) to (70.center) to (71.center) to (68.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (73.center) to (74.center) to (75.center) to (76.center) to (73.center); +\\draw [-, fill={rgb,255: red,224; green,224; blue,224}, line width=2pt] (78.center) to (79.center) to (80.center) to (81.center) to (78.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=3pt] (83.center) to (84.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=3pt] (85.center) to (86.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=3pt] (87.center) to (88.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=3pt] (89.center) to (90.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=3pt] (91.center) to (92.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,208; green,59; blue,45}, line width=3pt] (93.center) to (94.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (95.center) to (96.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (97.center) to (98.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (99.center) to (100.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (101.center) to (102.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (103.center) to (104.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (105.center) to (106.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (107.center) to (108.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (109.center) to (110.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (111.center) to (112.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (113.center) to (114.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (115.center) to (116.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (117.center) to (118.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=3pt] (119.center) to (120.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=3pt] (121.center) to (122.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=3pt] (123.center) to (124.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=3pt] (125.center) to (126.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,6; green,110; blue,226}, line width=3pt] (127.center) to (128.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,156; green,84; blue,14}, line width=3pt] (129.center) to (130.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,244; green,169; blue,64}, line width=3pt] (131.center) to (132.center); \\end{pgfonlayer} \\begin{pgfonlayer}{labellayer} \\node [style=none] (5) at (2.75, 11.875) {Alice}; @@ -571,31 +571,6 @@ \\node [style=none] (72) at (7.75, -4.125) {test}; \\node [style=none] (77) at (4.0, -4.125) {a}; \\node [style=none] (82) at (9.0, -6.625) {b}; -\\node [style=none, right] (85) at (2.85, 11.525) {n}; -\\node [style=none, right] (88) at (5.35, 11.525) {n}; -\\node [style=none, right] (91) at (2.85, 9.025) {n}; -\\node [style=none, right] (94) at (5.35, 9.025) {n}; -\\node [style=none, right] (97) at (7.85, 11.525) {n}; -\\node [style=none, right] (100) at (10.35, 11.525) {n}; -\\node [style=none, right] (103) at (0.1, 3.625) {n}; -\\node [style=none, right] (106) at (2.6, 3.625) {n}; -\\node [style=none, right] (109) at (0.1, 2.275) {n}; -\\node [style=none, right] (112) at (2.6, 2.275) {n}; -\\node [style=none, right] (115) at (5.35, 3.625) {n}; -\\node [style=none, right] (118) at (7.85, 3.625) {n}; -\\node [style=none, right] (121) at (5.35, 2.275) {n}; -\\node [style=none, right] (124) at (7.85, 2.275) {n}; -\\node [style=none, right] (127) at (11.85, 6.125) {n}; -\\node [style=none, right] (130) at (11.85, 4.775) {n}; -\\node [style=none, right] (133) at (10.6, 2.275) {s}; -\\node [style=none, right] (136) at (10.6, -0.225) {s}; -\\node [style=none, right] (139) at (13.1, 2.275) {s}; -\\node [style=none, right] (142) at (6.6, -1.975) {n}; -\\node [style=none, right] (145) at (9.1, -1.975) {n}; -\\node [style=none, right] (148) at (4.1, -1.975) {n}; -\\node [style=none, right] (151) at (9.1, -4.475) {n}; -\\node [style=none, right] (154) at (4.1, -4.475) {n}; -\\node [style=none, right] (157) at (6.6, -4.475) {n}; \\end{pgfonlayer} \\end{tikzpicture} @@ -619,7 +594,7 @@ def test_drawable_generation(diagram, drawable): @pytest.mark.parametrize('diagram, tikz', zip(diagrams, tikz_outputs)) def test_tikz_drawing(diagram, tikz, capsys): - diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=False, color_boxes=False, draw_type_labels=True) + diagram.draw(backend=TikzBackend(use_tikzstyles=False, wire_linewidth= 3, box_linewidth=2), color_wires=False, color_boxes=False, draw_type_labels=True) tikz_op, _ = capsys.readouterr() @@ -629,7 +604,7 @@ def test_tikz_drawing(diagram, tikz, capsys): @pytest.mark.parametrize('diagram, tikz', zip(diagrams, colored_tikz_outputs)) def test_tikz_colored_drawing(diagram, tikz, capsys): - diagram.draw(backend=TikzBackend(use_tikzstyles=False, wires_linewidth= 1.25 * 0.4 ), color_wires=True, color_boxes=True, draw_type_labels=True) + diagram.draw(backend=TikzBackend(use_tikzstyles=False, wire_linewidth=3, box_linewidth=2), use_tikzstyles=False, foliated=False, color_wires=True, color_boxes=True) tikz_op, _ = capsys.readouterr() From 93a84bb299e711c89968ab6d461e67cb7e485667 Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 21 Nov 2024 16:37:58 +0000 Subject: [PATCH 38/41] update test-drawing tests with linewidth changes --- tests/backend/test_drawing.py | 290 +++++++++++++++++++--------------- 1 file changed, 166 insertions(+), 124 deletions(-) diff --git a/tests/backend/test_drawing.py b/tests/backend/test_drawing.py index e2146245..7ed551e2 100644 --- a/tests/backend/test_drawing.py +++ b/tests/backend/test_drawing.py @@ -188,201 +188,236 @@ tikz_outputs = [ -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, -0.25) {}; \\node [] (2) at (3.0, -0.25) {}; \\node [] (3) at (3.0, 0.25) {}; \\node [] (4) at (-0.5, 0.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 0.0) {BX1}; \\node [] (6) at (1.25, 1.0) {}; \\node [] (7) at (1.25, 0.25) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 1.0) {s}; \\node [] (9) at (0.0, -0.25) {}; \\node [] (10) at (0.0, -1.0) {}; -\\node [style=none, fill=white, right] (11) at (0.1, -0.35) {s}; \\node [] (12) at (2.5, -0.25) {}; \\node [] (13) at (2.5, -1.0) {}; -\\node [style=none, fill=white, right] (14) at (2.6, -0.35) {s}; \\node [] (15) at (5.0, 1.0) {}; \\node [] (16) at (5.0, -1.0) {}; -\\node [style=none, fill=white, right] (17) at (5.1, 1.0) {s}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (16.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 0.0) {BX1}; +\\node [style=none, right] (8) at (1.35, 1.0) {s}; +\\node [style=none, right] (11) at (0.1, -0.35) {s}; +\\node [style=none, right] (14) at (2.6, -0.35) {s}; +\\node [style=none, right] (17) at (5.1, 1.0) {s}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.25) {}; \\node [] (2) at (3.0, 0.25) {}; \\node [] (3) at (3.25, 0.75) {}; \\node [] (4) at (-0.5, 0.75) {}; -\\node [style=none, fill=white] (5) at (1.25, 0.5) {BX1}; \\node [] (6) at (-0.5, -0.75) {}; \\node [] (7) at (3.25, -0.75) {}; \\node [] (8) at (3.0, -0.25) {}; \\node [] (9) at (-0.5, -0.25) {}; -\\node [style=none, fill=white] (10) at (1.25, -0.5) {BX1†}; \\node [] (11) at (1.25, 1.5) {}; \\node [] (12) at (1.25, 0.75) {}; -\\node [style=none, fill=white, right] (13) at (1.35, 1.5) {s}; \\node [] (14) at (0.0, 0.25) {}; \\node [] (15) at (0.0, -0.25) {}; -\\node [style=none, fill=white, right] (16) at (0.1, 0.15) {s}; \\node [] (17) at (2.5, 0.25) {}; \\node [] (18) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (19) at (2.6, 0.15) {s}; \\node [] (20) at (1.25, -0.75) {}; \\node [] (21) at (1.25, -1.5) {}; -\\node [style=none, fill=white, right] (22) at (1.35, -0.85) {s}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={white}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [in=90, out=-90] (11.center) to (12.center); -\\draw [in=90, out=-90] (14.center) to (15.center); -\\draw [in=90, out=-90] (17.center) to (18.center); -\\draw [in=90, out=-90] (20.center) to (21.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (11.center) to (12.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (14.center) to (15.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (17.center) to (18.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (20.center) to (21.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 0.5) {BX1}; +\\node [style=none] (10) at (1.25, -0.5) {BX1†}; +\\node [style=none, right] (13) at (1.35, 1.5) {s}; +\\node [style=none, right] (16) at (0.1, 0.15) {s}; +\\node [style=none, right] (19) at (2.6, 0.15) {s}; +\\node [style=none, right] (22) at (1.35, -0.85) {s}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.25) {}; \\node [] (2) at (3.0, 0.25) {}; \\node [] (3) at (3.0, 0.75) {}; \\node [] (4) at (-0.5, 0.75) {}; -\\node [style=none, fill=white] (5) at (1.25, 0.5) {BX1}; \\node [] (6) at (1.25, 1.5) {}; \\node [] (7) at (1.25, 0.75) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 1.5) {s}; \\node [] (9) at (2.5, 0.25) {}; \\node [] (10) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (11) at (2.6, 0.15) {s}; \\node [] (12) at (5.0, 1.5) {}; \\node [] (13) at (5.0, -0.25) {}; -\\node [style=none, fill=white, right] (14) at (5.1, 1.5) {s.r}; \\node [] (15) at (0.0, 0.25) {}; \\node [] (16) at (0.0, -1.5) {}; -\\node [style=none, fill=white, right] (17) at (0.1, 0.15) {s}; \\node [] (18) at (3.75, -0.5) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=180, out=-90, looseness=0.4118] (10.center) to (18.center); -\\draw [in=0, out=-90, looseness=0.4118] (13.center) to (18.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (16.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (10.center) to (18.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (13.center) to (18.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 0.5) {BX1}; +\\node [style=none, right] (8) at (1.35, 1.5) {s}; +\\node [style=none, right] (11) at (2.6, 0.15) {s}; +\\node [style=none, right] (14) at (5.1, 1.5) {s.r}; +\\node [style=none, right] (17) at (0.1, 0.15) {s}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.75) {}; \\node [] (2) at (3.0, 0.75) {}; \\node [] (3) at (3.0, 1.25) {}; \\node [] (4) at (-0.5, 1.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 1.0) {BX2}; \\node [] (6) at (1.25, 2.0) {}; \\node [] (7) at (1.25, 1.25) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 2.0) {s}; \\node [] (9) at (2.5, 0.75) {}; \\node [] (10) at (2.5, 0.25) {}; -\\node [style=none, fill=white, right] (11) at (2.6, 0.65) {s.r}; \\node [] (12) at (5.0, 2.0) {}; \\node [] (13) at (5.0, 0.25) {}; -\\node [style=none, fill=white, right] (14) at (5.1, 2.0) {s.r}; \\node [] (15) at (7.5, 2.0) {}; \\node [] (16) at (7.5, 0.25) {}; -\\node [style=none, fill=white, right] (17) at (7.6, 2.0) {s.r}; \\node [] (18) at (0.0, 0.75) {}; \\node [] (19) at (0.0, -0.75) {}; -\\node [style=none, fill=white, right] (20) at (0.1, 0.65) {s}; \\node [] (21) at (3.75, -0.25) {}; \\node [] (22) at (3.75, -0.75) {}; -\\node [style=none, fill=white, right] (23) at (3.85, -0.35) {s.r}; \\node [] (24) at (6.25, -0.25) {}; \\node [] (25) at (6.25, -2.0) {}; -\\node [style=none, fill=white, right] (26) at (6.35, -0.35) {s.r}; \\node [circle, fill=black, scale=0.365] (27) at (5.0, 0.0) {}; \\node [] (28) at (1.875, -1.0) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=90, out=-90] (18.center) to (19.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=180, looseness=0.4118] (27.center) to (21.center); -\\draw [in=90, out=0, looseness=0.4118] (27.center) to (24.center); -\\draw [in=180, out=-90, looseness=0.209] (10.center) to (27.center); -\\draw [in=90, out=-90] (13.center) to (27.center); -\\draw [in=0, out=-90, looseness=0.209] (16.center) to (27.center); -\\draw [in=180, out=-90, looseness=0.2775] (19.center) to (28.center); -\\draw [in=0, out=-90, looseness=0.2775] (22.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (18.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (24.center) to (25.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (27.center) to (21.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (27.center) to (24.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (10.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (13.center) to (27.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (16.center) to (27.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.2775] (19.center) to (28.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.2775] (22.center) to (28.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 1.0) {BX2}; +\\node [style=none, right] (8) at (1.35, 2.0) {s}; +\\node [style=none, right] (11) at (2.6, 0.65) {s.r}; +\\node [style=none, right] (14) at (5.1, 2.0) {s.r}; +\\node [style=none, right] (17) at (7.6, 2.0) {s.r}; +\\node [style=none, right] (20) at (0.1, 0.65) {s}; +\\node [style=none, right] (23) at (3.85, -0.35) {s.r}; +\\node [style=none, right] (26) at (6.35, -0.35) {s.r}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (0.75, 0.75) {}; \\node [] (2) at (1.75, 0.75) {}; \\node [] (3) at (2.0, 1.25) {}; \\node [] (4) at (0.75, 1.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 1.0) {BX3}; \\node [] (6) at (-0.5, -0.25) {}; \\node [] (7) at (3.0, -0.25) {}; \\node [] (8) at (3.25, 0.25) {}; \\node [] (9) at (-0.5, 0.25) {}; -\\node [style=none, fill=white] (10) at (1.25, 0.0) {BX1}; \\node [] (11) at (2.0, -1.25) {}; \\node [] (12) at (3.25, -1.25) {}; \\node [] (13) at (3.0, -0.75) {}; \\node [] (14) at (2.0, -0.75) {}; -\\node [style=none, fill=white] (15) at (2.5, -1.0) {BX3†}; \\node [] (16) at (-0.5, -1.25) {}; \\node [] (17) at (0.75, -1.25) {}; \\node [] (18) at (0.5, -0.75) {}; \\node [] (19) at (-0.5, -0.75) {}; -\\node [style=none, fill=white] (20) at (0.0, -1.0) {BX3†}; \\node [] (21) at (1.25, 0.75) {}; \\node [] (22) at (1.25, 0.25) {}; -\\node [style=none, fill=white, right] (23) at (1.35, 0.65) {s}; \\node [] (24) at (2.5, -0.25) {}; \\node [] (25) at (2.5, -0.75) {}; -\\node [style=none, fill=white, right] (26) at (2.6, -0.35) {s}; \\node [] (27) at (0.0, -0.25) {}; \\node [] (28) at (0.0, -0.75) {}; -\\node [style=none, fill=white, right] (29) at (0.1, -0.35) {s}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [-, fill={white}] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); -\\draw [-, fill={white}] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); -\\draw [-, fill={white}] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=-90] (27.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (6.center) to (7.center) to (8.center) to (9.center) to (6.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (11.center) to (12.center) to (13.center) to (14.center) to (11.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (16.center) to (17.center) to (18.center) to (19.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (24.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (27.center) to (28.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 1.0) {BX3}; +\\node [style=none] (10) at (1.25, 0.0) {BX1}; +\\node [style=none] (15) at (2.5, -1.0) {BX3†}; +\\node [style=none] (20) at (0.0, -1.0) {BX3†}; +\\node [style=none, right] (23) at (1.35, 0.65) {s}; +\\node [style=none, right] (26) at (2.6, -0.35) {s}; +\\node [style=none, right] (29) at (0.1, -0.35) {s}; \\end{pgfonlayer} \\end{tikzpicture} @@ -498,98 +533,105 @@ def test_tikz_drawing(diagram, tikz, capsys): assert tikz_op == tikz -expected_equation_tikz = """\\begin{tikzpicture}[baseline=(0.base)] +expected_equation_tikz = """% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.75) {}; \\node [] (2) at (3.0, 0.75) {}; \\node [] (3) at (3.25, 1.25) {}; \\node [] (4) at (-0.5, 1.25) {}; -\\node [style=none, fill=white] (5) at (1.25, 1.0) {BX2}; \\node [] (6) at (1.25, 2.0) {}; \\node [] (7) at (1.25, 1.25) {}; -\\node [style=none, fill=white, right] (8) at (1.35, 2.0) {s}; \\node [] (9) at (2.5, 0.75) {}; \\node [] (10) at (2.5, 0.25) {}; -\\node [style=none, fill=white, right] (11) at (2.6, 0.65) {s.r}; \\node [] (12) at (5.0, 2.0) {}; \\node [] (13) at (5.0, 0.25) {}; -\\node [style=none, fill=white, right] (14) at (5.1, 2.0) {s.r}; \\node [] (15) at (7.5, 2.0) {}; \\node [] (16) at (7.5, 0.25) {}; -\\node [style=none, fill=white, right] (17) at (7.6, 2.0) {s.r}; \\node [] (18) at (0.0, 0.75) {}; \\node [] (19) at (0.0, -0.75) {}; -\\node [style=none, fill=white, right] (20) at (0.1, 0.65) {s}; \\node [] (21) at (3.75, -0.25) {}; \\node [] (22) at (3.75, -0.75) {}; -\\node [style=none, fill=white, right] (23) at (3.85, -0.35) {s.r}; \\node [] (24) at (6.25, -0.25) {}; \\node [] (25) at (6.25, -2.0) {}; -\\node [style=none, fill=white, right] (26) at (6.35, -0.35) {s.r}; \\node [circle, fill=black, scale=0.365] (27) at (5.0, 0.0) {}; \\node [] (28) at (1.875, -1.0) {}; -\\node [style=none, fill=white] (29) at (8.6, 0) {=}; \\node [] (30) at (9.1, -1.25) {}; \\node [] (31) at (12.85, -1.25) {}; \\node [] (32) at (12.6, -0.75) {}; \\node [] (33) at (9.1, -0.75) {}; -\\node [style=none, fill=white] (34) at (10.85, -1.0) {BX2†}; \\node [] (35) at (13.35, 0.75) {}; \\node [] (36) at (13.35, 0.25) {}; -\\node [style=none, fill=white, right] (37) at (13.45, 0.65) {s.r}; \\node [] (38) at (15.85, 2.0) {}; \\node [] (39) at (15.85, 0.25) {}; -\\node [style=none, fill=white, right] (40) at (15.95, 2.0) {s.r}; \\node [] (41) at (9.6, 0.75) {}; \\node [] (42) at (9.6, -0.75) {}; -\\node [style=none, fill=white, right] (43) at (9.7, 0.65) {s}; \\node [] (44) at (12.1, -0.25) {}; \\node [] (45) at (12.1, -0.75) {}; -\\node [style=none, fill=white, right] (46) at (12.2, -0.35) {s.r}; \\node [] (47) at (10.85, -1.25) {}; \\node [] (48) at (10.85, -2.0) {}; -\\node [style=none, fill=white, right] (49) at (10.95, -1.35) {s}; \\node [] (50) at (14.6, -0.25) {}; \\node [] (51) at (14.6, -2.0) {}; -\\node [style=none, fill=white, right] (52) at (14.7, -0.35) {s.r}; \\node [] (53) at (17.1, -0.25) {}; \\node [] (54) at (17.1, -2.0) {}; -\\node [style=none, fill=white, right] (55) at (17.200000000000003, -0.35) {s.r}; \\node [] (56) at (12.1, 1.0) {}; \\node [circle, fill=black, scale=0.242] (57) at (14.6, 0.0) {}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=90, out=-90] (12.center) to (13.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=90, out=-90] (18.center) to (19.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=180, looseness=0.4118] (27.center) to (21.center); -\\draw [in=90, out=0, looseness=0.4118] (27.center) to (24.center); -\\draw [in=180, out=-90, looseness=0.209] (10.center) to (27.center); -\\draw [in=90, out=-90] (13.center) to (27.center); -\\draw [in=0, out=-90, looseness=0.209] (16.center) to (27.center); -\\draw [in=180, out=-90, looseness=0.2775] (19.center) to (28.center); -\\draw [in=0, out=-90, looseness=0.2775] (22.center) to (28.center); -\\draw [-, fill={white}] (30.center) to (31.center) to (32.center) to (33.center) to (30.center); -\\draw [in=90, out=-90] (35.center) to (36.center); -\\draw [in=90, out=-90] (38.center) to (39.center); -\\draw [in=90, out=-90] (41.center) to (42.center); -\\draw [in=90, out=-90] (44.center) to (45.center); -\\draw [in=90, out=-90] (47.center) to (48.center); -\\draw [in=90, out=-90] (50.center) to (51.center); -\\draw [in=90, out=-90] (53.center) to (54.center); -\\draw [in=90, out=180, looseness=0.209] (56.center) to (41.center); -\\draw [in=90, out=0, looseness=0.4118] (56.center) to (35.center); -\\draw [in=90, out=180, looseness=0.209] (57.center) to (44.center); -\\draw [in=90, out=-90] (57.center) to (50.center); -\\draw [in=90, out=0, looseness=0.209] (57.center) to (53.center); -\\draw [in=180, out=-90, looseness=0.4118] (36.center) to (57.center); -\\draw [in=0, out=-90, looseness=0.4118] (39.center) to (57.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (4.center) to (1.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (9.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (12.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (18.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (24.center) to (25.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (27.center) to (21.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (27.center) to (24.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (10.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (13.center) to (27.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (16.center) to (27.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.2775] (19.center) to (28.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.2775] (22.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (30.center) to (31.center) to (32.center) to (33.center) to (30.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (35.center) to (36.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (38.center) to (39.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (41.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (44.center) to (45.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (47.center) to (48.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (50.center) to (51.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (53.center) to (54.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (56.center) to (41.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (56.center) to (35.center); +\\draw [in=90, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (57.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (57.center) to (50.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.209] (57.center) to (53.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (36.center) to (57.center); +\\draw [in=0, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=0.4118] (39.center) to (57.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (5) at (1.25, 1.0) {BX2}; +\\node [style=none, right] (8) at (1.35, 2.0) {s}; +\\node [style=none, right] (11) at (2.6, 0.65) {s.r}; +\\node [style=none, right] (14) at (5.1, 2.0) {s.r}; +\\node [style=none, right] (17) at (7.6, 2.0) {s.r}; +\\node [style=none, right] (20) at (0.1, 0.65) {s}; +\\node [style=none, right] (23) at (3.85, -0.35) {s.r}; +\\node [style=none, right] (26) at (6.35, -0.35) {s.r}; +\\node [style=none] (29) at (8.6, 0) {=}; +\\node [style=none] (34) at (10.85, -1.0) {BX2†}; +\\node [style=none, right] (37) at (13.45, 0.65) {s.r}; +\\node [style=none, right] (40) at (15.95, 2.0) {s.r}; +\\node [style=none, right] (43) at (9.7, 0.65) {s}; +\\node [style=none, right] (46) at (12.2, -0.35) {s.r}; +\\node [style=none, right] (49) at (10.95, -1.35) {s}; +\\node [style=none, right] (52) at (14.7, -0.35) {s.r}; +\\node [style=none, right] (55) at (17.200000000000003, -0.35) {s.r}; \\end{pgfonlayer} \\end{tikzpicture} From 0f3c286cb18e9684f9bb4163658042b423e76e2b Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 21 Nov 2024 16:38:11 +0000 Subject: [PATCH 39/41] update circuit-drawing tests with linewidth changes --- tests/backend/test_circuit_drawing.py | 670 ++++++++++++++------------ 1 file changed, 356 insertions(+), 314 deletions(-) diff --git a/tests/backend/test_circuit_drawing.py b/tests/backend/test_circuit_drawing.py index 59c27778..c6720bef 100644 --- a/tests/backend/test_circuit_drawing.py +++ b/tests/backend/test_circuit_drawing.py @@ -34,26 +34,27 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): ] -tikz_outputs = ["""\\begin{tikzpicture}[baseline=(0.base)] +tikz_outputs = ["""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 1.75) {}; \\node [] (2) at (0.5, 1.75) {}; \\node [] (3) at (0.0, 2.25) {}; -\\node [style=none, fill=white] (4) at (0, 2.0) {0}; \\node [] (5) at (2.0, 1.75) {}; \\node [] (6) at (3.0, 1.75) {}; \\node [] (7) at (2.5, 2.25) {}; -\\node [style=none, fill=white] (8) at (2.5, 2.0) {0}; \\node [] (9) at (4.5, 1.75) {}; \\node [] (10) at (5.5, 1.75) {}; \\node [] (11) at (5.0, 2.25) {}; -\\node [style=none, fill=white] (12) at (5.0, 2.0) {0}; \\node [] (13) at (-0.5, 0.75) {}; \\node [] (14) at (0.5, 0.75) {}; \\node [] (15) at (0.5, 1.25) {}; \\node [] (16) at (-0.5, 1.25) {}; -\\node [style=none, fill=white] (17) at (0.0, 1.0) {H}; \\node [circle, black] (18) at (0.0, 0.0) {}; \\node [circle, white] (19) at (2.5, 0.0) {}; \\node [plus] (20) at (2.5, 0.0) {}; @@ -70,45 +71,56 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (31) at (2.5, -0.75) {}; \\node [] (32) at (0.0, 1.75) {}; \\node [] (33) at (0.0, 1.25) {}; -\\node [style=none, fill=white, right] (34) at (0.1, 1.65) {qubit}; \\node [] (35) at (0.0, 0.75) {}; -\\node [style=none, fill=white, right] (36) at (0.1, 0.65) {qubit}; \\node [] (37) at (2.5, 1.75) {}; -\\node [style=none, fill=white, right] (38) at (2.6, 1.65) {qubit}; -\\node [style=none, fill=white, right] (39) at (2.6, -0.35) {qubit}; \\node [] (40) at (5.0, 1.75) {}; -\\node [style=none, fill=white, right] (41) at (5.1, 1.65) {qubit}; \\node [] (42) at (0.0, -2.0) {}; -\\node [style=none, fill=white, right] (43) at (0.1, -0.35) {qubit}; \\node [] (44) at (2.5, -2.0) {}; -\\node [style=none, fill=white, right] (45) at (2.6, -1.35) {qubit}; \\node [] (46) at (5.0, -2.0) {}; -\\node [style=none, fill=white, right] (47) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (1.center); -\\draw [-, fill={white}] (5.center) to (6.center) to (7.center) to (5.center); -\\draw [-, fill={white}] (9.center) to (10.center) to (11.center) to (9.center); -\\draw [-, fill={white}] (13.center) to (14.center) to (15.center) to (16.center) to (13.center); -\\draw [in=90, out=-90] (21.center) to (22.center); -\\draw [in=90, out=-90] (23.center) to (24.center); -\\draw [in=180, out=0] (18.center) to (20.center); -\\draw [in=90, out=-90] (28.center) to (29.center); -\\draw [in=90, out=-90] (30.center) to (31.center); -\\draw [in=180, out=0] (25.center) to (27.center); -\\draw [in=90, out=-90] (32.center) to (33.center); -\\draw [in=90, out=-90] (35.center) to (24.center); -\\draw [in=90, out=-90] (37.center) to (22.center); -\\draw [in=90, out=-90] (21.center) to (31.center); -\\draw [in=90, out=-90] (40.center) to (29.center); -\\draw [in=90, out=-90] (23.center) to (42.center); -\\draw [in=90, out=-90] (30.center) to (44.center); -\\draw [in=90, out=-90] (28.center) to (46.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (5.center) to (6.center) to (7.center) to (5.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (9.center) to (10.center) to (11.center) to (9.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (13.center) to (14.center) to (15.center) to (16.center) to (13.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (23.center) to (24.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (18.center) to (20.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (28.center) to (29.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (30.center) to (31.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (25.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (32.center) to (33.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (35.center) to (24.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (37.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (31.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (40.center) to (29.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (23.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (30.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (28.center) to (46.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (4) at (0, 2.0) {0}; +\\node [style=none] (8) at (2.5, 2.0) {0}; +\\node [style=none] (12) at (5.0, 2.0) {0}; +\\node [style=none] (17) at (0.0, 1.0) {H}; +\\node [style=none, right] (34) at (0.1, 1.65) {qubit}; +\\node [style=none, right] (36) at (0.1, 0.65) {qubit}; +\\node [style=none, right] (38) at (2.6, 1.65) {qubit}; +\\node [style=none, right] (39) at (2.6, -0.35) {qubit}; +\\node [style=none, right] (41) at (5.1, 1.65) {qubit}; +\\node [style=none, right] (43) at (0.1, -0.35) {qubit}; +\\node [style=none, right] (45) at (2.6, -1.35) {qubit}; +\\node [style=none, right] (47) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [circle, black] (1) at (2.5, 2.0) {}; @@ -122,15 +134,12 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (9) at (3.0, 0.75) {}; \\node [] (10) at (3.0, 1.25) {}; \\node [] (11) at (2.0, 1.25) {}; -\\node [style=none, fill=white] (12) at (2.5, 1.0) {H}; \\node [] (13) at (2.0, 0.25) {}; \\node [] (14) at (3.0, 0.25) {}; \\node [] (15) at (2.5, -0.25) {}; -\\node [style=none, fill=white] (16) at (2.5, 0.0) {0}; \\node [] (17) at (4.5, 1.25) {}; \\node [] (18) at (5.5, 1.25) {}; \\node [] (19) at (5.0, 0.75) {}; -\\node [style=none, fill=white] (20) at (5.0, 1.0) {0}; \\node [circle, black] (21) at (0.0, -1.0) {}; \\node [circle, white] (22) at (7.5, -1.0) {}; \\node [plus] (23) at (7.5, -1.0) {}; @@ -142,66 +151,76 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (29) at (0.5, -2.25) {}; \\node [] (30) at (0.5, -1.75) {}; \\node [] (31) at (-0.5, -1.75) {}; -\\node [style=none, fill=white] (32) at (0.0, -2.0) {H}; \\node [] (33) at (-0.5, -2.75) {}; \\node [] (34) at (0.5, -2.75) {}; \\node [] (35) at (0.0, -3.25) {}; -\\node [style=none, fill=white] (36) at (0.0, -3.0) {0}; \\node [] (37) at (7.0, -1.75) {}; \\node [] (38) at (8.0, -1.75) {}; \\node [] (39) at (7.5, -2.25) {}; -\\node [style=none, fill=white] (40) at (7.5, -2.0) {0}; \\node [] (41) at (2.5, 3.0) {}; -\\node [style=none, fill=white, right] (42) at (2.6, 3.0) {qubit}; \\node [] (43) at (5.0, 3.0) {}; -\\node [style=none, fill=white, right] (44) at (5.1, 3.0) {qubit}; \\node [] (45) at (2.5, 1.25) {}; -\\node [style=none, fill=white, right] (46) at (2.6, 1.65) {qubit}; \\node [] (47) at (2.5, 0.75) {}; \\node [] (48) at (2.5, 0.25) {}; -\\node [style=none, fill=white, right] (49) at (2.6, 0.65) {qubit}; \\node [] (50) at (5.0, 1.25) {}; -\\node [style=none, fill=white, right] (51) at (5.1, 1.65) {qubit}; \\node [] (52) at (0.0, 3.0) {}; -\\node [style=none, fill=white, right] (53) at (0.1, 3.0) {qubit}; \\node [] (54) at (7.5, 3.0) {}; -\\node [style=none, fill=white, right] (55) at (7.6, 3.0) {qubit}; \\node [] (56) at (0.0, -1.75) {}; -\\node [style=none, fill=white, right] (57) at (0.1, -1.35) {qubit}; \\node [] (58) at (0.0, -2.25) {}; \\node [] (59) at (0.0, -2.75) {}; -\\node [style=none, fill=white, right] (60) at (0.1, -2.35) {qubit}; \\node [] (61) at (7.5, -1.75) {}; -\\node [style=none, fill=white, right] (62) at (7.6, -1.35) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [in=90, out=-90] (4.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=180, out=0] (1.center) to (3.center); -\\draw [-, fill={white}] (8.center) to (9.center) to (10.center) to (11.center) to (8.center); -\\draw [-, fill={white}] (13.center) to (14.center) to (15.center) to (13.center); -\\draw [-, fill={white}] (17.center) to (18.center) to (19.center) to (17.center); -\\draw [in=90, out=-90] (24.center) to (25.center); -\\draw [in=90, out=-90] (26.center) to (27.center); -\\draw [in=180, out=0] (21.center) to (23.center); -\\draw [-, fill={white}] (28.center) to (29.center) to (30.center) to (31.center) to (28.center); -\\draw [-, fill={white}] (33.center) to (34.center) to (35.center) to (33.center); -\\draw [-, fill={white}] (37.center) to (38.center) to (39.center) to (37.center); -\\draw [in=90, out=-90] (41.center) to (7.center); -\\draw [in=90, out=-90] (43.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (45.center); -\\draw [in=90, out=-90] (47.center) to (48.center); -\\draw [in=90, out=-90] (4.center) to (50.center); -\\draw [in=90, out=-90] (52.center) to (27.center); -\\draw [in=90, out=-90] (54.center) to (25.center); -\\draw [in=90, out=-90] (26.center) to (56.center); -\\draw [in=90, out=-90] (58.center) to (59.center); -\\draw [in=90, out=-90] (24.center) to (61.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (4.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (7.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (1.center) to (3.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (8.center) to (9.center) to (10.center) to (11.center) to (8.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (13.center) to (14.center) to (15.center) to (13.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (17.center) to (18.center) to (19.center) to (17.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (24.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (26.center) to (27.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (23.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (28.center) to (29.center) to (30.center) to (31.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (33.center) to (34.center) to (35.center) to (33.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (37.center) to (38.center) to (39.center) to (37.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (41.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (43.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (45.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (47.center) to (48.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (4.center) to (50.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (52.center) to (27.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (54.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (26.center) to (56.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (58.center) to (59.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (24.center) to (61.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (12) at (2.5, 1.0) {H}; +\\node [style=none] (16) at (2.5, 0.0) {0}; +\\node [style=none] (20) at (5.0, 1.0) {0}; +\\node [style=none] (32) at (0.0, -2.0) {H}; +\\node [style=none] (36) at (0.0, -3.0) {0}; +\\node [style=none] (40) at (7.5, -2.0) {0}; +\\node [style=none, right] (42) at (2.6, 3.0) {qubit}; +\\node [style=none, right] (44) at (5.1, 3.0) {qubit}; +\\node [style=none, right] (46) at (2.6, 1.65) {qubit}; +\\node [style=none, right] (49) at (2.6, 0.65) {qubit}; +\\node [style=none, right] (51) at (5.1, 1.65) {qubit}; +\\node [style=none, right] (53) at (0.1, 3.0) {qubit}; +\\node [style=none, right] (55) at (7.6, 3.0) {qubit}; +\\node [style=none, right] (57) at (0.1, -1.35) {qubit}; +\\node [style=none, right] (60) at (0.1, -2.35) {qubit}; +\\node [style=none, right] (62) at (7.6, -1.35) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [circle, black] (1) at (0.0, 5.5) {}; @@ -255,7 +274,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (49) at (3.0, -0.75) {}; \\node [] (50) at (3.0, -0.25) {}; \\node [] (51) at (2.0, -0.25) {}; -\\node [style=none, fill=white] (52) at (2.5, -0.5) {U}; \\node [] (53) at (5.0, -0.75) {}; \\node [] (54) at (5.0, -0.25) {}; \\node [] (55) at (3.0, -0.5) {}; @@ -264,7 +282,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (58) at (3.0, -1.75) {}; \\node [] (59) at (3.0, -1.25) {}; \\node [] (60) at (2.0, -1.25) {}; -\\node [style=none, fill=white] (61) at (2.5, -1.5) {U}; \\node [] (62) at (0.0, -1.75) {}; \\node [] (63) at (0.0, -1.25) {}; \\node [] (64) at (2.0, -1.5) {}; @@ -273,7 +290,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (67) at (0.5, -2.75) {}; \\node [] (68) at (0.5, -2.25) {}; \\node [] (69) at (-0.5, -2.25) {}; -\\node [style=none, fill=white] (70) at (0.0, -2.5) {U}; \\node [] (71) at (5.0, -2.75) {}; \\node [] (72) at (5.0, -2.25) {}; \\node [] (73) at (2.5, -2.75) {}; @@ -284,7 +300,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (78) at (5.5, -3.75) {}; \\node [] (79) at (5.5, -3.25) {}; \\node [] (80) at (4.5, -3.25) {}; -\\node [style=none, fill=white] (81) at (5.0, -3.5) {U}; \\node [] (82) at (0.0, -3.75) {}; \\node [] (83) at (0.0, -3.25) {}; \\node [] (84) at (2.5, -3.75) {}; @@ -295,7 +310,6 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (89) at (3.0, -4.75) {}; \\node [] (90) at (3.0, -4.25) {}; \\node [] (91) at (-0.5, -4.25) {}; -\\node [style=none, fill=white] (92) at (2.0, -4.5) {U2}; \\node [] (93) at (5.0, -4.75) {}; \\node [] (94) at (5.0, -4.25) {}; \\node [] (95) at (3.0, -4.5) {}; @@ -304,145 +318,157 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (98) at (5.5, -5.75) {}; \\node [] (99) at (5.5, -5.25) {}; \\node [] (100) at (2.0, -5.25) {}; -\\node [style=none, fill=white] (101) at (3.0, -5.5) {U2}; \\node [] (102) at (0.0, -5.75) {}; \\node [] (103) at (0.0, -5.25) {}; \\node [] (104) at (2.0, -5.5) {}; \\node [] (105) at (0.0, 6.5) {}; -\\node [style=none, fill=white, right] (106) at (0.1, 6.5) {qubit}; \\node [] (107) at (2.5, 6.5) {}; -\\node [style=none, fill=white, right] (108) at (2.6, 6.5) {qubit}; -\\node [style=none, fill=white, right] (109) at (0.1, 5.15) {qubit}; -\\node [style=none, fill=white, right] (110) at (2.6, 5.15) {qubit}; -\\node [style=none, fill=white, right] (111) at (2.6, 4.15) {qubit}; \\node [] (112) at (5.0, 6.5) {}; -\\node [style=none, fill=white, right] (113) at (5.1, 6.5) {qubit}; -\\node [style=none, fill=white, right] (114) at (2.6, 3.15) {qubit}; -\\node [style=none, fill=white, right] (115) at (5.1, 3.15) {qubit}; -\\node [style=none, fill=white, right] (116) at (0.1, 4.15) {qubit}; -\\node [style=none, fill=white, right] (117) at (2.6, 2.15) {qubit}; -\\node [style=none, fill=white, right] (118) at (5.1, 2.15) {qubit}; -\\node [style=none, fill=white, right] (119) at (0.1, 1.15) {qubit}; -\\node [style=none, fill=white, right] (120) at (2.6, 1.15) {qubit}; -\\node [style=none, fill=white, right] (121) at (5.1, 1.15) {qubit}; \\node [] (122) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (123) at (2.6, 0.15) {qubit}; -\\node [style=none, fill=white, right] (124) at (5.1, 0.15) {qubit}; -\\node [style=none, fill=white, right] (125) at (0.1, 0.15) {qubit}; \\node [] (126) at (2.5, -0.75) {}; \\node [] (127) at (2.5, -1.25) {}; -\\node [style=none, fill=white, right] (128) at (2.6, -0.85) {qubit}; \\node [] (129) at (0.0, -2.25) {}; -\\node [style=none, fill=white, right] (130) at (0.1, -1.85) {qubit}; \\node [] (131) at (2.5, -1.75) {}; -\\node [style=none, fill=white, right] (132) at (2.6, -1.85) {qubit}; -\\node [style=none, fill=white, right] (133) at (5.1, -0.85) {qubit}; \\node [] (134) at (0.0, -2.75) {}; -\\node [style=none, fill=white, right] (135) at (0.1, -2.85) {qubit}; -\\node [style=none, fill=white, right] (136) at (2.6, -2.85) {qubit}; \\node [] (137) at (5.0, -3.25) {}; -\\node [style=none, fill=white, right] (138) at (5.1, -2.85) {qubit}; \\node [] (139) at (0.0, -4.25) {}; -\\node [style=none, fill=white, right] (140) at (0.1, -3.85) {qubit}; \\node [] (141) at (2.5, -4.25) {}; -\\node [style=none, fill=white, right] (142) at (2.6, -3.85) {qubit}; \\node [] (143) at (5.0, -3.75) {}; -\\node [style=none, fill=white, right] (144) at (5.1, -3.85) {qubit}; \\node [] (145) at (0.0, -4.75) {}; -\\node [style=none, fill=white, right] (146) at (0.1, -4.85) {qubit}; \\node [] (147) at (2.5, -4.75) {}; \\node [] (148) at (2.5, -5.25) {}; -\\node [style=none, fill=white, right] (149) at (2.6, -4.85) {qubit}; \\node [] (150) at (5.0, -5.25) {}; -\\node [style=none, fill=white, right] (151) at (5.1, -4.85) {qubit}; \\node [] (152) at (0.0, -6.5) {}; -\\node [style=none, fill=white, right] (153) at (0.1, -5.85) {qubit}; \\node [] (154) at (2.5, -5.75) {}; \\node [] (155) at (2.5, -6.5) {}; -\\node [style=none, fill=white, right] (156) at (2.6, -5.85) {qubit}; \\node [] (157) at (5.0, -5.75) {}; \\node [] (158) at (5.0, -6.5) {}; -\\node [style=none, fill=white, right] (159) at (5.1, -5.85) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [in=90, out=-90] (4.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (7.center); -\\draw [in=180, out=0] (1.center) to (3.center); -\\draw [in=90, out=-90] (11.center) to (12.center); -\\draw [in=90, out=-90] (13.center) to (14.center); -\\draw [in=0, out=180] (8.center) to (10.center); -\\draw [in=90, out=-90] (18.center) to (19.center); -\\draw [in=90, out=-90] (20.center) to (21.center); -\\draw [in=180, out=0] (15.center) to (17.center); -\\draw [in=90, out=-90] (25.center) to (26.center); -\\draw [in=90, out=-90] (27.center) to (28.center); -\\draw [in=0, out=180] (22.center) to (24.center); -\\draw [in=90, out=-90] (32.center) to (33.center); -\\draw [in=90, out=-90] (34.center) to (35.center); -\\draw [in=90, out=-90] (36.center) to (37.center); -\\draw [in=180, out=0] (29.center) to (31.center); -\\draw [in=90, out=-90] (41.center) to (42.center); -\\draw [in=90, out=-90] (43.center) to (44.center); -\\draw [in=90, out=-90] (45.center) to (46.center); -\\draw [in=0, out=180] (38.center) to (40.center); -\\draw [-, fill={white}] (48.center) to (49.center) to (50.center) to (51.center) to (48.center); -\\draw [in=90, out=-90] (53.center) to (54.center); -\\draw [in=0, out=180] (47.center) to (55.center); -\\draw [-, fill={white}] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); -\\draw [in=90, out=-90] (62.center) to (63.center); -\\draw [in=180, out=0] (56.center) to (64.center); -\\draw [-, fill={white}] (66.center) to (67.center) to (68.center) to (69.center) to (66.center); -\\draw [in=90, out=-90] (71.center) to (72.center); -\\draw [in=90, out=-90] (73.center) to (74.center); -\\draw [in=0, out=180] (65.center) to (75.center); -\\draw [-, fill={white}] (77.center) to (78.center) to (79.center) to (80.center) to (77.center); -\\draw [in=90, out=-90] (82.center) to (83.center); -\\draw [in=90, out=-90] (84.center) to (85.center); -\\draw [in=180, out=0] (76.center) to (86.center); -\\draw [-, fill={white}] (88.center) to (89.center) to (90.center) to (91.center) to (88.center); -\\draw [in=90, out=-90] (93.center) to (94.center); -\\draw [in=0, out=180] (87.center) to (95.center); -\\draw [-, fill={white}] (97.center) to (98.center) to (99.center) to (100.center) to (97.center); -\\draw [in=90, out=-90] (102.center) to (103.center); -\\draw [in=180, out=0] (96.center) to (104.center); -\\draw [in=90, out=-90] (105.center) to (7.center); -\\draw [in=90, out=-90] (107.center) to (5.center); -\\draw [in=90, out=-90] (6.center) to (12.center); -\\draw [in=90, out=-90] (4.center) to (14.center); -\\draw [in=90, out=-90] (13.center) to (21.center); -\\draw [in=90, out=-90] (112.center) to (19.center); -\\draw [in=90, out=-90] (20.center) to (26.center); -\\draw [in=90, out=-90] (18.center) to (28.center); -\\draw [in=90, out=-90] (11.center) to (35.center); -\\draw [in=90, out=-90] (25.center) to (37.center); -\\draw [in=90, out=-90] (27.center) to (33.center); -\\draw [in=90, out=-90] (34.center) to (42.center); -\\draw [in=90, out=-90] (36.center) to (46.center); -\\draw [in=90, out=-90] (32.center) to (44.center); -\\draw [in=90, out=-90] (45.center) to (122.center); -\\draw [in=90, out=-90] (43.center) to (54.center); -\\draw [in=90, out=-90] (41.center) to (63.center); -\\draw [in=90, out=-90] (126.center) to (127.center); -\\draw [in=90, out=-90] (62.center) to (129.center); -\\draw [in=90, out=-90] (131.center) to (74.center); -\\draw [in=90, out=-90] (53.center) to (72.center); -\\draw [in=90, out=-90] (134.center) to (83.center); -\\draw [in=90, out=-90] (73.center) to (85.center); -\\draw [in=90, out=-90] (71.center) to (137.center); -\\draw [in=90, out=-90] (82.center) to (139.center); -\\draw [in=90, out=-90] (84.center) to (141.center); -\\draw [in=90, out=-90] (143.center) to (94.center); -\\draw [in=90, out=-90] (145.center) to (103.center); -\\draw [in=90, out=-90] (147.center) to (148.center); -\\draw [in=90, out=-90] (93.center) to (150.center); -\\draw [in=90, out=-90] (102.center) to (152.center); -\\draw [in=90, out=-90] (154.center) to (155.center); -\\draw [in=90, out=-90] (157.center) to (158.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (4.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (7.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (1.center) to (3.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (11.center) to (12.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (13.center) to (14.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (8.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (18.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (20.center) to (21.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (17.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (25.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (27.center) to (28.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (22.center) to (24.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (32.center) to (33.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (34.center) to (35.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (36.center) to (37.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (29.center) to (31.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (41.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (43.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (45.center) to (46.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (38.center) to (40.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (48.center) to (49.center) to (50.center) to (51.center) to (48.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (53.center) to (54.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (47.center) to (55.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (62.center) to (63.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (56.center) to (64.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (66.center) to (67.center) to (68.center) to (69.center) to (66.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (71.center) to (72.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (73.center) to (74.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (65.center) to (75.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (77.center) to (78.center) to (79.center) to (80.center) to (77.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (82.center) to (83.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (84.center) to (85.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (76.center) to (86.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (88.center) to (89.center) to (90.center) to (91.center) to (88.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (93.center) to (94.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (87.center) to (95.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (97.center) to (98.center) to (99.center) to (100.center) to (97.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (102.center) to (103.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (96.center) to (104.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (105.center) to (7.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (107.center) to (5.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (6.center) to (12.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (4.center) to (14.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (13.center) to (21.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (112.center) to (19.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (20.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (18.center) to (28.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (11.center) to (35.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (25.center) to (37.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (27.center) to (33.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (34.center) to (42.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (36.center) to (46.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (32.center) to (44.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (45.center) to (122.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (43.center) to (54.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (41.center) to (63.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (126.center) to (127.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (62.center) to (129.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (131.center) to (74.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (53.center) to (72.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (134.center) to (83.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (73.center) to (85.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (71.center) to (137.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (82.center) to (139.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (84.center) to (141.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (143.center) to (94.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (145.center) to (103.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (147.center) to (148.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (93.center) to (150.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (102.center) to (152.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (154.center) to (155.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (157.center) to (158.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (52) at (2.5, -0.5) {U}; +\\node [style=none] (61) at (2.5, -1.5) {U}; +\\node [style=none] (70) at (0.0, -2.5) {U}; +\\node [style=none] (81) at (5.0, -3.5) {U}; +\\node [style=none] (92) at (2.0, -4.5) {U2}; +\\node [style=none] (101) at (3.0, -5.5) {U2}; +\\node [style=none, right] (106) at (0.1, 6.5) {qubit}; +\\node [style=none, right] (108) at (2.6, 6.5) {qubit}; +\\node [style=none, right] (109) at (0.1, 5.15) {qubit}; +\\node [style=none, right] (110) at (2.6, 5.15) {qubit}; +\\node [style=none, right] (111) at (2.6, 4.15) {qubit}; +\\node [style=none, right] (113) at (5.1, 6.5) {qubit}; +\\node [style=none, right] (114) at (2.6, 3.15) {qubit}; +\\node [style=none, right] (115) at (5.1, 3.15) {qubit}; +\\node [style=none, right] (116) at (0.1, 4.15) {qubit}; +\\node [style=none, right] (117) at (2.6, 2.15) {qubit}; +\\node [style=none, right] (118) at (5.1, 2.15) {qubit}; +\\node [style=none, right] (119) at (0.1, 1.15) {qubit}; +\\node [style=none, right] (120) at (2.6, 1.15) {qubit}; +\\node [style=none, right] (121) at (5.1, 1.15) {qubit}; +\\node [style=none, right] (123) at (2.6, 0.15) {qubit}; +\\node [style=none, right] (124) at (5.1, 0.15) {qubit}; +\\node [style=none, right] (125) at (0.1, 0.15) {qubit}; +\\node [style=none, right] (128) at (2.6, -0.85) {qubit}; +\\node [style=none, right] (130) at (0.1, -1.85) {qubit}; +\\node [style=none, right] (132) at (2.6, -1.85) {qubit}; +\\node [style=none, right] (133) at (5.1, -0.85) {qubit}; +\\node [style=none, right] (135) at (0.1, -2.85) {qubit}; +\\node [style=none, right] (136) at (2.6, -2.85) {qubit}; +\\node [style=none, right] (138) at (5.1, -2.85) {qubit}; +\\node [style=none, right] (140) at (0.1, -3.85) {qubit}; +\\node [style=none, right] (142) at (2.6, -3.85) {qubit}; +\\node [style=none, right] (144) at (5.1, -3.85) {qubit}; +\\node [style=none, right] (146) at (0.1, -4.85) {qubit}; +\\node [style=none, right] (149) at (2.6, -4.85) {qubit}; +\\node [style=none, right] (151) at (5.1, -4.85) {qubit}; +\\node [style=none, right] (153) at (0.1, -5.85) {qubit}; +\\node [style=none, right] (156) at (2.6, -5.85) {qubit}; +\\node [style=none, right] (159) at (5.1, -5.85) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [circle, black] (1) at (0.0, 1.0) {}; @@ -476,77 +502,80 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (29) at (5.0, -1.25) {}; \\node [] (30) at (5.0, -0.75) {}; \\node [] (31) at (0.0, 2.0) {}; -\\node [style=none, fill=white, right] (32) at (0.1, 2.0) {qubit}; \\node [] (33) at (2.5, 2.0) {}; -\\node [style=none, fill=white, right] (34) at (2.6, 2.0) {qubit}; \\node [] (35) at (5.0, 2.0) {}; -\\node [style=none, fill=white, right] (36) at (5.1, 2.0) {qubit}; -\\node [style=none, fill=white, right] (37) at (0.1, 0.65) {qubit}; -\\node [style=none, fill=white, right] (38) at (2.6, 0.65) {qubit}; -\\node [style=none, fill=white, right] (39) at (5.1, 0.65) {qubit}; -\\node [style=none, fill=white, right] (40) at (0.1, -0.35) {qubit}; -\\node [style=none, fill=white, right] (41) at (2.6, -0.35) {qubit}; -\\node [style=none, fill=white, right] (42) at (5.1, -0.35) {qubit}; \\node [] (43) at (0.0, -2.0) {}; -\\node [style=none, fill=white, right] (44) at (0.1, -1.35) {qubit}; \\node [] (45) at (2.5, -2.0) {}; -\\node [style=none, fill=white, right] (46) at (2.6, -1.35) {qubit}; \\node [] (47) at (5.0, -2.0) {}; -\\node [style=none, fill=white, right] (48) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [in=90, out=-90] (5.center) to (6.center); -\\draw [in=90, out=-90] (7.center) to (8.center); -\\draw [in=180, out=0] (2.center) to (4.center); -\\draw [in=90, out=-90] (9.center) to (10.center); -\\draw [in=180, out=0] (1.center) to (2.center); -\\draw [in=90, out=-90] (15.center) to (16.center); -\\draw [in=90, out=-90] (17.center) to (18.center); -\\draw [in=0, out=180] (12.center) to (14.center); -\\draw [in=90, out=-90] (19.center) to (20.center); -\\draw [in=180, out=0] (11.center) to (14.center); -\\draw [in=90, out=-90] (25.center) to (26.center); -\\draw [in=90, out=-90] (27.center) to (28.center); -\\draw [in=0, out=180] (22.center) to (24.center); -\\draw [in=90, out=-90] (29.center) to (30.center); -\\draw [in=0, out=180] (21.center) to (22.center); -\\draw [in=90, out=-90] (31.center) to (10.center); -\\draw [in=90, out=-90] (33.center) to (8.center); -\\draw [in=90, out=-90] (35.center) to (6.center); -\\draw [in=90, out=-90] (9.center) to (20.center); -\\draw [in=90, out=-90] (7.center) to (16.center); -\\draw [in=90, out=-90] (5.center) to (18.center); -\\draw [in=90, out=-90] (19.center) to (26.center); -\\draw [in=90, out=-90] (15.center) to (28.center); -\\draw [in=90, out=-90] (17.center) to (30.center); -\\draw [in=90, out=-90] (25.center) to (43.center); -\\draw [in=90, out=-90] (27.center) to (45.center); -\\draw [in=90, out=-90] (29.center) to (47.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (5.center) to (6.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (7.center) to (8.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (2.center) to (4.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (9.center) to (10.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (1.center) to (2.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (17.center) to (18.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (12.center) to (14.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (19.center) to (20.center); +\\draw [in=180, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (11.center) to (14.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (25.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (27.center) to (28.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (22.center) to (24.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (29.center) to (30.center); +\\draw [in=0, out=180, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (21.center) to (22.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (31.center) to (10.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (33.center) to (8.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (35.center) to (6.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (9.center) to (20.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (7.center) to (16.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (5.center) to (18.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (19.center) to (26.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (15.center) to (28.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (17.center) to (30.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (25.center) to (43.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (27.center) to (45.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (29.center) to (47.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none, right] (32) at (0.1, 2.0) {qubit}; +\\node [style=none, right] (34) at (2.6, 2.0) {qubit}; +\\node [style=none, right] (36) at (5.1, 2.0) {qubit}; +\\node [style=none, right] (37) at (0.1, 0.65) {qubit}; +\\node [style=none, right] (38) at (2.6, 0.65) {qubit}; +\\node [style=none, right] (39) at (5.1, 0.65) {qubit}; +\\node [style=none, right] (40) at (0.1, -0.35) {qubit}; +\\node [style=none, right] (41) at (2.6, -0.35) {qubit}; +\\node [style=none, right] (42) at (5.1, -0.35) {qubit}; +\\node [style=none, right] (44) at (0.1, -1.35) {qubit}; +\\node [style=none, right] (46) at (2.6, -1.35) {qubit}; +\\node [style=none, right] (48) at (5.1, -1.35) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 0.25) {}; \\node [] (2) at (0.5, 0.25) {}; \\node [] (3) at (0.0, 0.75) {}; -\\node [style=none, fill=white] (4) at (0.0, 0.5) {0}; \\node [] (5) at (2.0, 0.25) {}; \\node [] (6) at (3.0, 0.25) {}; \\node [] (7) at (2.5, 0.75) {}; -\\node [style=none, fill=white] (8) at (2.5, 0.5) {1}; \\node [] (9) at (4.5, 0.25) {}; \\node [] (10) at (5.5, 0.25) {}; \\node [] (11) at (5.5, 0.75) {}; \\node [] (12) at (4.5, 0.75) {}; -\\node [style=none, fill=white] (13) at (5.0, 0.5) {MixedState}; \\node [] (14) at (7.0, 0.25) {}; \\node [] (15) at (8.0, 0.25) {}; \\node [] (16) at (8.0, 0.75) {}; \\node [] (17) at (7.0, 0.75) {}; -\\node [style=none, fill=white] (18) at (7.5, 0.5) {Encode}; \\node [] (19) at (-0.5, -0.75) {}; \\node [] (20) at (0.5, -0.75) {}; \\node [] (21) at (0.5, -0.25) {}; @@ -559,11 +588,9 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (28) at (2.0, -0.25) {}; \\node [] (29) at (3.0, -0.25) {}; \\node [] (30) at (2.5, -0.75) {}; -\\node [style=none, fill=white] (31) at (2.5, -0.5) {0}; \\node [] (32) at (4.5, -0.25) {}; \\node [] (33) at (5.5, -0.25) {}; \\node [] (34) at (5.0, -0.75) {}; -\\node [style=none, fill=white] (35) at (5.0, -0.5) {1}; \\node [] (36) at (7.0, -0.25) {}; \\node [] (37) at (8.0, -0.25) {}; \\node [] (38) at (7.1, -0.35) {}; @@ -572,194 +599,209 @@ def __init__(self, name: str, dom, cod, data=None, is_mixed=True, **params): \\node [] (41) at (7.8, -0.45) {}; \\node [] (42) at (7.5, 1.5) {}; \\node [] (43) at (7.5, 0.75) {}; -\\node [style=none, fill=white, right] (44) at (7.6, 1.5) {bit}; \\node [] (45) at (0.0, 0.25) {}; \\node [] (46) at (0.0, -0.25) {}; -\\node [style=none, fill=white, right] (47) at (0.1, 0.15) {qubit}; \\node [] (48) at (2.5, 0.25) {}; \\node [] (49) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (50) at (2.6, 0.15) {qubit}; \\node [] (51) at (5.0, 0.25) {}; \\node [] (52) at (5.0, -0.25) {}; -\\node [style=none, fill=white, right] (53) at (5.1, 0.15) {qubit}; \\node [] (54) at (7.5, 0.25) {}; \\node [] (55) at (7.5, -0.25) {}; -\\node [style=none, fill=white, right] (56) at (7.6, 0.15) {qubit}; \\node [] (57) at (0.0, -0.75) {}; \\node [] (58) at (0.0, -1.5) {}; -\\node [style=none, fill=white, right] (59) at (0.1, -0.85) {bit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (1.center); -\\draw [-, fill={white}] (5.center) to (6.center) to (7.center) to (5.center); -\\draw [-, fill={white}] (9.center) to (10.center) to (11.center) to (12.center) to (9.center); -\\draw [-, fill={white}] (14.center) to (15.center) to (16.center) to (17.center) to (14.center); -\\draw [-, fill={white}] (19.center) to (20.center) to (21.center) to (22.center) to (19.center); -\\draw [in=180, out=-90, looseness=1.26] (23.center) to (24.center); -\\draw [in=90, out=0, looseness=1.26] (24.center) to (25.center); -\\draw [in=90, out=-90, ->looseness=0.4118] (26.center) to (27.center); -\\draw [-, fill={white}] (28.center) to (29.center) to (30.center) to (28.center); -\\draw [-, fill={white}] (32.center) to (33.center) to (34.center) to (32.center); -\\draw [in=90, out=-90] (36.center) to (37.center); -\\draw [in=90, out=-90] (38.center) to (39.center); -\\draw [in=90, out=-90] (40.center) to (41.center); -\\draw [in=90, out=-90] (42.center) to (43.center); -\\draw [in=90, out=-90] (45.center) to (46.center); -\\draw [in=90, out=-90] (48.center) to (49.center); -\\draw [in=90, out=-90] (51.center) to (52.center); -\\draw [in=90, out=-90] (54.center) to (55.center); -\\draw [in=90, out=-90] (57.center) to (58.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (5.center) to (6.center) to (7.center) to (5.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (9.center) to (10.center) to (11.center) to (12.center) to (9.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (14.center) to (15.center) to (16.center) to (17.center) to (14.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (19.center) to (20.center) to (21.center) to (22.center) to (19.center); +\\draw [in=180, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=1.26] (23.center) to (24.center); +\\draw [in=90, out=0, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, looseness=1.26] (24.center) to (25.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt, ->looseness=0.4118] (26.center) to (27.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (28.center) to (29.center) to (30.center) to (28.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (32.center) to (33.center) to (34.center) to (32.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (36.center) to (37.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (38.center) to (39.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (40.center) to (41.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (42.center) to (43.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (45.center) to (46.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (48.center) to (49.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (51.center) to (52.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (54.center) to (55.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (57.center) to (58.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (4) at (0.0, 0.5) {0}; +\\node [style=none] (8) at (2.5, 0.5) {1}; +\\node [style=none] (13) at (5.0, 0.5) {MixedState}; +\\node [style=none] (18) at (7.5, 0.5) {Encode}; +\\node [style=none] (31) at (2.5, -0.5) {0}; +\\node [style=none] (35) at (5.0, -0.5) {1}; +\\node [style=none, right] (44) at (7.6, 1.5) {bit}; +\\node [style=none, right] (47) at (0.1, 0.15) {qubit}; +\\node [style=none, right] (50) at (2.6, 0.15) {qubit}; +\\node [style=none, right] (53) at (5.1, 0.15) {qubit}; +\\node [style=none, right] (56) at (7.6, 0.15) {qubit}; +\\node [style=none, right] (59) at (0.1, -0.85) {bit}; \\end{pgfonlayer} \\end{tikzpicture} """, -"""\\begin{tikzpicture}[baseline=(0.base)] +"""% When embedding into a *.tex file, uncomment and include the following lines: +% \\pgfdeclarelayer{nodelayer} +% \\pgfdeclarelayer{edgelayer} +% \\pgfdeclarelayer{labellayer} +% \\pgfsetlayers{nodelayer, edgelayer, labellayer} +\\begin{tikzpicture}[baseline=(0.base)] \\begin{pgfonlayer}{nodelayer} \\node (0) at (0, 0) {}; \\node [] (1) at (-0.5, 1.25) {}; \\node [] (2) at (0.5, 1.25) {}; \\node [] (3) at (0.0, 1.75) {}; -\\node [style=none, fill=white] (4) at (0.0, 1.5) {0}; \\node [] (5) at (2.0, 1.25) {}; \\node [] (6) at (3.0, 1.25) {}; \\node [] (7) at (2.5, 1.75) {}; -\\node [style=none, fill=white] (8) at (2.5, 1.5) {0}; \\node [] (9) at (7.0, 1.25) {}; \\node [] (10) at (8.0, 1.25) {}; \\node [] (11) at (7.5, 1.75) {}; -\\node [style=none, fill=white] (12) at (7.5, 1.5) {0}; \\node [] (13) at (9.5, 1.25) {}; \\node [] (14) at (10.5, 1.25) {}; \\node [] (15) at (10.0, 1.75) {}; -\\node [style=none, fill=white] (16) at (10.0, 1.5) {0}; \\node [] (17) at (-0.5, 0.25) {}; \\node [] (18) at (0.5, 0.25) {}; \\node [] (19) at (0.5, 0.75) {}; \\node [] (20) at (-0.5, 0.75) {}; -\\node [style=none, fill=white] (21) at (0.0, 0.5) {S}; \\node [] (22) at (2.0, 0.25) {}; \\node [] (23) at (3.0, 0.25) {}; \\node [] (24) at (3.0, 0.75) {}; \\node [] (25) at (2.0, 0.75) {}; -\\node [style=none, fill=white] (26) at (2.5, 0.5) {X}; \\node [] (27) at (7.0, 0.25) {}; \\node [] (28) at (8.0, 0.25) {}; \\node [] (29) at (8.0, 0.75) {}; \\node [] (30) at (7.0, 0.75) {}; -\\node [style=none, fill=white] (31) at (7.5, 0.5) {Y}; \\node [] (32) at (9.5, 0.25) {}; \\node [] (33) at (10.5, 0.25) {}; \\node [] (34) at (10.5, 0.75) {}; \\node [] (35) at (9.5, 0.75) {}; -\\node [style=none, fill=white] (36) at (10.0, 0.5) {Z}; \\node [] (37) at (-0.5, -0.75) {}; \\node [] (38) at (0.5, -0.75) {}; \\node [] (39) at (0.5, -0.25) {}; \\node [] (40) at (-0.5, -0.25) {}; -\\node [style=none, fill=white] (41) at (0.0, -0.5) {Rx(0.3)}; \\node [] (42) at (2.0, -0.75) {}; \\node [] (43) at (3.0, -0.75) {}; \\node [] (44) at (3.0, -0.25) {}; \\node [] (45) at (2.0, -0.25) {}; -\\node [style=none, fill=white] (46) at (2.5, -0.5) {Ry(0.2)}; \\node [] (47) at (4.5, 1.25) {}; \\node [] (48) at (5.5, 1.25) {}; \\node [] (49) at (5.5, 1.75) {}; \\node [] (50) at (4.5, 1.75) {}; -\\node [style=none, fill=white] (51) at (5.0, 1.5) {0.500}; \\node [] (52) at (7.0, -0.75) {}; \\node [] (53) at (8.0, -0.75) {}; \\node [] (54) at (8.0, -0.25) {}; \\node [] (55) at (7.0, -0.25) {}; -\\node [style=none, fill=white] (56) at (7.5, -0.5) {Rz(0.1)}; \\node [] (57) at (9.5, -0.75) {}; \\node [] (58) at (10.5, -0.75) {}; \\node [] (59) at (10.5, -0.25) {}; \\node [] (60) at (9.5, -0.25) {}; -\\node [style=none, fill=white] (61) at (10.0, -0.5) {H}; \\node [] (62) at (-0.5, -1.25) {}; \\node [] (63) at (0.5, -1.25) {}; \\node [] (64) at (0.0, -1.75) {}; -\\node [style=none, fill=white] (65) at (0.0, -1.5) {0}; \\node [] (66) at (2.0, -1.25) {}; \\node [] (67) at (3.0, -1.25) {}; \\node [] (68) at (2.5, -1.75) {}; -\\node [style=none, fill=white] (69) at (2.5, -1.5) {0}; \\node [] (70) at (7.0, -1.25) {}; \\node [] (71) at (8.0, -1.25) {}; \\node [] (72) at (7.5, -1.75) {}; -\\node [style=none, fill=white] (73) at (7.5, -1.5) {0}; \\node [] (74) at (9.5, -1.25) {}; \\node [] (75) at (10.5, -1.25) {}; \\node [] (76) at (10.0, -1.75) {}; -\\node [style=none, fill=white] (77) at (10.0, -1.5) {0}; \\node [] (78) at (0.0, 1.25) {}; \\node [] (79) at (0.0, 0.75) {}; -\\node [style=none, fill=white, right] (80) at (0.1, 1.15) {qubit}; \\node [] (81) at (2.5, 1.25) {}; \\node [] (82) at (2.5, 0.75) {}; -\\node [style=none, fill=white, right] (83) at (2.6, 1.15) {qubit}; \\node [] (84) at (7.5, 1.25) {}; \\node [] (85) at (7.5, 0.75) {}; -\\node [style=none, fill=white, right] (86) at (7.6, 1.15) {qubit}; \\node [] (87) at (10.0, 1.25) {}; \\node [] (88) at (10.0, 0.75) {}; -\\node [style=none, fill=white, right] (89) at (10.1, 1.15) {qubit}; \\node [] (90) at (0.0, 0.25) {}; \\node [] (91) at (0.0, -0.25) {}; -\\node [style=none, fill=white, right] (92) at (0.1, 0.15) {qubit}; \\node [] (93) at (2.5, 0.25) {}; \\node [] (94) at (2.5, -0.25) {}; -\\node [style=none, fill=white, right] (95) at (2.6, 0.15) {qubit}; \\node [] (96) at (7.5, 0.25) {}; \\node [] (97) at (7.5, -0.25) {}; -\\node [style=none, fill=white, right] (98) at (7.6, 0.15) {qubit}; \\node [] (99) at (10.0, 0.25) {}; \\node [] (100) at (10.0, -0.25) {}; -\\node [style=none, fill=white, right] (101) at (10.1, 0.15) {qubit}; \\node [] (102) at (0.0, -0.75) {}; \\node [] (103) at (0.0, -1.25) {}; -\\node [style=none, fill=white, right] (104) at (0.1, -0.85) {qubit}; \\node [] (105) at (2.5, -0.75) {}; \\node [] (106) at (2.5, -1.25) {}; -\\node [style=none, fill=white, right] (107) at (2.6, -0.85) {qubit}; \\node [] (108) at (7.5, -0.75) {}; \\node [] (109) at (7.5, -1.25) {}; -\\node [style=none, fill=white, right] (110) at (7.6, -0.85) {qubit}; \\node [] (111) at (10.0, -0.75) {}; \\node [] (112) at (10.0, -1.25) {}; -\\node [style=none, fill=white, right] (113) at (10.1, -0.85) {qubit}; \\end{pgfonlayer} \\begin{pgfonlayer}{edgelayer} -\\draw [-, fill={white}] (1.center) to (2.center) to (3.center) to (1.center); -\\draw [-, fill={white}] (5.center) to (6.center) to (7.center) to (5.center); -\\draw [-, fill={white}] (9.center) to (10.center) to (11.center) to (9.center); -\\draw [-, fill={white}] (13.center) to (14.center) to (15.center) to (13.center); -\\draw [-, fill={white}] (17.center) to (18.center) to (19.center) to (20.center) to (17.center); -\\draw [-, fill={white}] (22.center) to (23.center) to (24.center) to (25.center) to (22.center); -\\draw [-, fill={white}] (27.center) to (28.center) to (29.center) to (30.center) to (27.center); -\\draw [-, fill={white}] (32.center) to (33.center) to (34.center) to (35.center) to (32.center); -\\draw [-, fill={white}] (37.center) to (38.center) to (39.center) to (40.center) to (37.center); -\\draw [-, fill={white}] (42.center) to (43.center) to (44.center) to (45.center) to (42.center); -\\draw [-, fill={white}] (47.center) to (48.center) to (49.center) to (50.center) to (47.center); -\\draw [-, fill={white}] (52.center) to (53.center) to (54.center) to (55.center) to (52.center); -\\draw [-, fill={white}] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); -\\draw [-, fill={white}] (62.center) to (63.center) to (64.center) to (62.center); -\\draw [-, fill={white}] (66.center) to (67.center) to (68.center) to (66.center); -\\draw [-, fill={white}] (70.center) to (71.center) to (72.center) to (70.center); -\\draw [-, fill={white}] (74.center) to (75.center) to (76.center) to (74.center); -\\draw [in=90, out=-90] (78.center) to (79.center); -\\draw [in=90, out=-90] (81.center) to (82.center); -\\draw [in=90, out=-90] (84.center) to (85.center); -\\draw [in=90, out=-90] (87.center) to (88.center); -\\draw [in=90, out=-90] (90.center) to (91.center); -\\draw [in=90, out=-90] (93.center) to (94.center); -\\draw [in=90, out=-90] (96.center) to (97.center); -\\draw [in=90, out=-90] (99.center) to (100.center); -\\draw [in=90, out=-90] (102.center) to (103.center); -\\draw [in=90, out=-90] (105.center) to (106.center); -\\draw [in=90, out=-90] (108.center) to (109.center); -\\draw [in=90, out=-90] (111.center) to (112.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (1.center) to (2.center) to (3.center) to (1.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (5.center) to (6.center) to (7.center) to (5.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (9.center) to (10.center) to (11.center) to (9.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (13.center) to (14.center) to (15.center) to (13.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (17.center) to (18.center) to (19.center) to (20.center) to (17.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (22.center) to (23.center) to (24.center) to (25.center) to (22.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (27.center) to (28.center) to (29.center) to (30.center) to (27.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (32.center) to (33.center) to (34.center) to (35.center) to (32.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (37.center) to (38.center) to (39.center) to (40.center) to (37.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (42.center) to (43.center) to (44.center) to (45.center) to (42.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (47.center) to (48.center) to (49.center) to (50.center) to (47.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (52.center) to (53.center) to (54.center) to (55.center) to (52.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (57.center) to (58.center) to (59.center) to (60.center) to (57.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (62.center) to (63.center) to (64.center) to (62.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (66.center) to (67.center) to (68.center) to (66.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (70.center) to (71.center) to (72.center) to (70.center); +\\draw [-, fill={rgb,255: red,255; green,255; blue,255}, line width=0.4pt] (74.center) to (75.center) to (76.center) to (74.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (78.center) to (79.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (81.center) to (82.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (84.center) to (85.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (87.center) to (88.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (90.center) to (91.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (93.center) to (94.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (96.center) to (97.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (99.center) to (100.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (102.center) to (103.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (105.center) to (106.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (108.center) to (109.center); +\\draw [in=90, out=-90, -, draw={rgb,255: red,0; green,0; blue,0}, line width=0.5pt] (111.center) to (112.center); +\\end{pgfonlayer} +\\begin{pgfonlayer}{labellayer} +\\node [style=none] (4) at (0.0, 1.5) {0}; +\\node [style=none] (8) at (2.5, 1.5) {0}; +\\node [style=none] (12) at (7.5, 1.5) {0}; +\\node [style=none] (16) at (10.0, 1.5) {0}; +\\node [style=none] (21) at (0.0, 0.5) {S}; +\\node [style=none] (26) at (2.5, 0.5) {X}; +\\node [style=none] (31) at (7.5, 0.5) {Y}; +\\node [style=none] (36) at (10.0, 0.5) {Z}; +\\node [style=none] (41) at (0.0, -0.5) {Rx(0.3)}; +\\node [style=none] (46) at (2.5, -0.5) {Ry(0.2)}; +\\node [style=none] (51) at (5.0, 1.5) {0.500}; +\\node [style=none] (56) at (7.5, -0.5) {Rz(0.1)}; +\\node [style=none] (61) at (10.0, -0.5) {H}; +\\node [style=none] (65) at (0.0, -1.5) {0}; +\\node [style=none] (69) at (2.5, -1.5) {0}; +\\node [style=none] (73) at (7.5, -1.5) {0}; +\\node [style=none] (77) at (10.0, -1.5) {0}; +\\node [style=none, right] (80) at (0.1, 1.15) {qubit}; +\\node [style=none, right] (83) at (2.6, 1.15) {qubit}; +\\node [style=none, right] (86) at (7.6, 1.15) {qubit}; +\\node [style=none, right] (89) at (10.1, 1.15) {qubit}; +\\node [style=none, right] (92) at (0.1, 0.15) {qubit}; +\\node [style=none, right] (95) at (2.6, 0.15) {qubit}; +\\node [style=none, right] (98) at (7.6, 0.15) {qubit}; +\\node [style=none, right] (101) at (10.1, 0.15) {qubit}; +\\node [style=none, right] (104) at (0.1, -0.85) {qubit}; +\\node [style=none, right] (107) at (2.6, -0.85) {qubit}; +\\node [style=none, right] (110) at (7.6, -0.85) {qubit}; +\\node [style=none, right] (113) at (10.1, -0.85) {qubit}; \\end{pgfonlayer} \\end{tikzpicture} From 448107b2ef9a87c6171e104f17aeb0ab9bb022ec Mon Sep 17 00:00:00 2001 From: ragunathc Date: Thu, 21 Nov 2024 16:45:31 +0000 Subject: [PATCH 40/41] make mypy happy --- lambeq/backend/drawing/drawing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index 12075273..a121024d 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -48,8 +48,8 @@ ) from lambeq.backend.drawing.text_printer import PregroupTextPrinter from lambeq.backend.drawing.tikz_backend import ( - TikzBackend, WIRE_LINEWIDTH as TIKZ_WIRE_LINEWIDTH, - BOX_LINEWIDTH as TIKZ_BOX_LINEWIDTH + BOX_LINEWIDTH as TIKZ_BOX_LINEWIDTH, TikzBackend, + WIRE_LINEWIDTH as TIKZ_WIRE_LINEWIDTH ) from lambeq.backend.grammar import Box, Diagram From 9f3a9a84418396c1ead880943c27c77a3e544bf3 Mon Sep 17 00:00:00 2001 From: "Neil John D. Ortega" Date: Fri, 22 Nov 2024 11:01:34 +0000 Subject: [PATCH 41/41] Add `box_linewidth` as param for `MatBackend` * Tidy up call --- lambeq/backend/drawing/drawable.py | 51 +++++++++++++------------- lambeq/backend/drawing/drawing.py | 8 ++-- lambeq/backend/drawing/tikz_backend.py | 10 ++--- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lambeq/backend/drawing/drawable.py b/lambeq/backend/drawing/drawable.py index 513bab48..ad792a1b 100644 --- a/lambeq/backend/drawing/drawable.py +++ b/lambeq/backend/drawing/drawable.py @@ -95,7 +95,7 @@ class WireEndpoint: x: float y: float - noun_id: int = 0 # New attribute for wire noun + noun_id: int = 0 # New attribute for wire noun parent: Optional['BoxNode'] = None @property @@ -778,8 +778,7 @@ class DrawableDiagramWithFrames(DrawableDiagram): frame, carrying all information necessary to render it. """ - # add counter for Nouns - noun_id_counter = 1 + noun_id_counter: int = 1 def _make_space(self, scan: list[int], @@ -844,13 +843,13 @@ def _make_space(self, return x, y def _add_box_with_nouns( - self, - scan: list[int], - box: grammar.Box, - off: int, - x_pos: float, - y_pos: float, - input_nouns: list[int] + self, + scan: list[int], + box: grammar.Box, + off: int, + x_pos: float, + y_pos: float, + input_nouns: list[int] ) -> tuple[list[int], int, list[int]]: """Add a box to the graph, creating necessary wire endpoints. @@ -862,6 +861,7 @@ def _add_box_with_nouns( The index of the newly added `BoxNode` input_nouns : list[int] The new order of input_nouns after adding the box + """ node = BoxNode(box, x_pos, y_pos) @@ -880,10 +880,10 @@ def _add_box_with_nouns( for i, obj in enumerate(box.dom): idx = off + i nbr_idx = scan[off + i] - noun_id = (input_nouns[idx] if input_nouns - and idx < len(input_nouns) - else self.get_noun_id() - ) # generate new noun id if needed + noun_id = ( + input_nouns[idx] if (input_nouns and idx < len(input_nouns)) + else self.get_noun_id() + ) # generate new noun_id if needed wire_end = WireEndpoint(WireEndpointType.DOM, obj=obj, @@ -896,32 +896,31 @@ def _add_box_with_nouns( self._add_wire(nbr_idx, wire_idx) scan_insert = [] - # if Swap, exchange the noun_ids if isinstance(box, grammar.Swap): + # If Swap, exchange the noun_ids if input_nouns and len(box.dom) > 1: dom_idx_1 = off dom_idx_2 = off + 1 input_nouns[dom_idx_1], input_nouns[dom_idx_2] = ( - input_nouns[dom_idx_2], input_nouns[dom_idx_1]) - # if Spider, expand or shrink the noun_ids based on type + input_nouns[dom_idx_2], input_nouns[dom_idx_1] + ) elif isinstance(node.obj, grammar.Spider): + # If Spider, expand or shrink the noun_ids based on type if len(box.dom) == 1 and len(box.cod) > 1: dom_noun = (input_nouns[off] if input_nouns and off < len(input_nouns) - else self.get_noun_id() - ) + else self.get_noun_id()) expanded_colors = [dom_noun] * len(box.cod) input_nouns = (input_nouns[:off] + expanded_colors + input_nouns[off + len(box.dom):]) elif len(box.dom) > 1 and len(box.cod) == 1: cod_noun = (input_nouns[off] if input_nouns and off < len(input_nouns) - else self.get_noun_id() - ) + else self.get_noun_id()) input_nouns = (input_nouns[:off] + [cod_noun] + input_nouns[off + len(box.dom):]) - num_output = off+len(box.cod) + num_output = off + len(box.cod) for i in range(num_output): if i < len(input_nouns): pass @@ -929,9 +928,9 @@ def _add_box_with_nouns( # If we run out of input nouns, generate new ones new_color = self.get_noun_id() input_nouns.append(new_color) + # Create a node representing each element in the box's codomain for i, obj in enumerate(box.cod): - # If the box is a quantum gate, retain x coordinate of wires if box.category == quantum and len(box.dom) == len(box.cod): nbr_idx = scan[off + i] @@ -1066,14 +1065,14 @@ def calculate_bounds(self) -> tuple[float, float, float, float]: return min(all_xs), min(all_ys), max(all_xs), max(all_ys) def get_noun_id(self) -> int: - """Generate a new numerical ID for the noun box/wire. + """Get the latest available numerical ID for the noun wire. Returns ------- noun_id : int - returns a unique identifier for the noun wire/box - """ + The latest noun wire ID. + """ # Increment and return the next available ID noun_id = self.noun_id_counter self.noun_id_counter += 1 diff --git a/lambeq/backend/drawing/drawing.py b/lambeq/backend/drawing/drawing.py index a121024d..39f9218a 100644 --- a/lambeq/backend/drawing/drawing.py +++ b/lambeq/backend/drawing/drawing.py @@ -44,7 +44,8 @@ WIRE_COLORS) from lambeq.backend.drawing.helpers import drawn_as_spider, needs_asymmetry from lambeq.backend.drawing.mat_backend import ( - MatBackend, WIRE_LINEWIDTH as MAT_WIRE_LINEWIDTH + BOX_LINEWIDTH as MAT_BOX_LINEWIDTH, MatBackend, + WIRE_LINEWIDTH as MAT_WIRE_LINEWIDTH ) from lambeq.backend.drawing.text_printer import PregroupTextPrinter from lambeq.backend.drawing.tikz_backend import ( @@ -135,15 +136,16 @@ def draw(diagram: Diagram, **params) -> None: elif params.get('to_tikz', False): backend = TikzBackend( use_tikzstyles=params.get('use_tikzstyles', None), + box_linewidth=params.get('box_linewidth', TIKZ_BOX_LINEWIDTH), wire_linewidth=params.get('wire_linewidth', TIKZ_WIRE_LINEWIDTH), - box_linewidth=params.get('box_linewidth', TIKZ_BOX_LINEWIDTH) ) else: backend = MatBackend( figsize=params.get('figsize', None), + box_linewidth=params.get('box_linewidth', MAT_BOX_LINEWIDTH), wire_linewidth=params.get('wire_linewidth', - MAT_WIRE_LINEWIDTH) + MAT_WIRE_LINEWIDTH), ) min_size = 0.01 diff --git a/lambeq/backend/drawing/tikz_backend.py b/lambeq/backend/drawing/tikz_backend.py index f6d54d96..2eb5477d 100644 --- a/lambeq/backend/drawing/tikz_backend.py +++ b/lambeq/backend/drawing/tikz_backend.py @@ -23,9 +23,9 @@ from math import sqrt from lambeq.backend.drawing.drawable import DrawableDiagram -from lambeq.backend.drawing.drawing_backend import (COLORS, DrawingBackend, - WIRE_COLORS_NAMES - ) +from lambeq.backend.drawing.drawing_backend import ( + COLORS, DrawingBackend, WIRE_COLORS_NAMES +) from lambeq.backend.drawing.helpers import drawn_as_spider from lambeq.backend.grammar import Spider @@ -38,8 +38,8 @@ class TikzBackend(DrawingBackend): """ Tikz drawing backend. """ def __init__(self, use_tikzstyles: bool = False, - wire_linewidth: float = WIRE_LINEWIDTH, - box_linewidth: float = BOX_LINEWIDTH): + box_linewidth: float = BOX_LINEWIDTH, + wire_linewidth: float = WIRE_LINEWIDTH): self.use_tikzstyles = use_tikzstyles self.node_styles: list[str] = [] self.edge_styles: list[str] = []