Skip to content

Commit

Permalink
Remove drawing from primitiveblock
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikandreasseitz committed Oct 2, 2023
1 parent 0d87bda commit 746aa0d
Showing 1 changed file with 0 additions and 83 deletions.
83 changes: 0 additions & 83 deletions qadence/blocks/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from abc import abstractmethod
from typing import Any, Iterable, Tuple

import numpy as np
import sympy
import torch
from rich.console import Console, RenderableType
Expand Down Expand Up @@ -58,15 +57,6 @@ def __iter__(self) -> Iterable:
def depth(self) -> int:
return 1

def __grid__(self, depth: int) -> Tuple[Tuple[int, ...], Any]:
from qadence.draw import Box, MultiWireBox, Text

wires = self.qubit_support
box = (
Box(Text(self.name)) if len(wires) == 1 else MultiWireBox(Text(self.name), wires=wires)
)
return self.qubit_support, box

def __ascii__(self, console: Console) -> RenderableType:
return Panel(self._block_title, expand=False)

Expand Down Expand Up @@ -138,22 +128,6 @@ def _block_title(self) -> str:

return s + rf" \[params: {params_str}]"

def __grid__(self, depth: int) -> Tuple[Tuple[int, ...], Any]:
from qadence.draw import Box, Text

(p,) = self.parameters.expressions()
if self.trainable:
fill = (0.89, 0.91, 0.82, 1.0)
border = (0.49, 0.64, 0.15, 1.0)
else:
fill = (0.8, 0.8, 0.8, 1.0)
border = (0.3, 0.3, 0.3, 1.0)

s = format_parameter(p)

box = Box(Text(f"{self.name}({s})"), border_color=border, fill_color=fill)
return self.qubit_support, box

@property
def trainable(self) -> bool:
for expr in self.parameters.expressions():
Expand Down Expand Up @@ -291,24 +265,6 @@ def scale(self) -> sympy.Expr:
(scale,) = self.parameters.expressions()
return scale

def __grid__(self, depth: int) -> Tuple[Tuple[int, ...], Any]:
from qadence.draw import Box, TagBox, Text

_, box = self.block.__grid__(depth)

p = self.parameters.parameter

# don't render scaling if its equal to one
if p.is_number and np.isclose(evaluate(p), 1):
return self.qubit_support, box

s = format_parameter(p)
if isinstance(box, Box) and isinstance(box.renderable, Text):
box.renderable.text += f" * {s}"
else:
box = TagBox(box, Text(f"* {s}"))
return self.qubit_support, box

def __rich_tree__(self, tree: Tree = None) -> Tree:
if tree is None:
tree = Tree(self._block_title)
Expand Down Expand Up @@ -406,25 +362,6 @@ def _block_title(self) -> str:
s = f"{self.name}({c},{t})"
return s if self.tag is None else (s + rf" \[tag: {self.tag}]")

def __grid__(self, depth: int) -> Tuple[Tuple[int, ...], Any]:
from qadence.draw import Control, ControlBox, IconBox

(control, target) = self.qubit_support
support = tuple(range(min(self.qubit_support), max(self.qubit_support) + 1))

c = Control()
t = self.blocks[0].__grid__(depth)[1]
t.border_color = c.border_color
t.fill_color = (0.98, 0.93, 0.86, 1.0)
if control < target:
top = IconBox(c)
bottom = IconBox(t)
else:
bottom = IconBox(c)
top = IconBox(t)
box = ControlBox(abs(control - target) + 1, top, bottom)
return (support, box)

def __ascii__(self, console: Console) -> RenderableType:
raise NotImplementedError

Expand Down Expand Up @@ -468,26 +405,6 @@ def __init__(self, control: tuple[int, ...], target_block: ParametricBlock) -> N
def eigenvalues_generator(self) -> torch.Tensor:
return torch.empty(0)

def __grid__(self, depth: int) -> Tuple[Tuple[int, ...], Any]:
from qadence.draw import Control, ControlBox, IconBox

(*control, target) = self.qubit_support
support = tuple(range(min(self.qubit_support), max(self.qubit_support) + 1))

c = Control()
t = self.blocks[0].__grid__(depth)[1]
t.border_color = c.border_color
t.fill_color = (0.98, 0.93, 0.86, 1.0)
# TODO; Multiple qubit
if control[0] < target:
top = IconBox(c)
bottom = IconBox(t)
else:
bottom = IconBox(c)
top = IconBox(t)
box = ControlBox(abs(control[0] - target) + 1, top, bottom)
return (support, box)

def __ascii__(self, console: Console) -> RenderableType:
raise NotImplementedError

Expand Down

0 comments on commit 746aa0d

Please sign in to comment.