Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCVL-119 simplify component rendering #453

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion perceval/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
get_pauli_eigenvectors)
from .tomography_exp_configurer import processor_circuit_configurator
from .comp_utils import decompose_perms
from .port import Port, Herald, PortLocation, get_basic_state_from_ports
from .port import APort, Port, Herald, PortLocation, get_basic_state_from_ports
from .unitary_components import BSConvention, BS, PS, WP, HWP, QWP, PR, Unitary, PERM, PBS, Barrier
from .non_unitary_components import TD, LC
from .component_catalog import Catalog
Expand Down
3 changes: 0 additions & 3 deletions perceval/components/unitary_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,6 @@ def __init__(self, perm):
u[v, i] = 1
super().__init__(U=u)

def get_variables(self):
return {'PERM': ''}

def describe(self):
return f"PERM({self.perm_vector})"

Expand Down
4 changes: 3 additions & 1 deletion perceval/rendering/_processor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from perceval.components import PERM, AProcessor
from perceval.components import PERM, AProcessor, Barrier


class ComponentHeraldInfo:
Expand Down Expand Up @@ -82,6 +82,8 @@ def collect_herald_info(processor: AProcessor, recursive: bool):
mode = component.perm_vector[mode - m0] + m0
else:
mode = component.perm_vector.index(mode - m0) + m0
elif isinstance(component, Barrier):
pass # Heralds can go through barriers too
else:
h_info = herald_info.setdefault(
component, ComponentHeraldInfo())
Expand Down
14 changes: 4 additions & 10 deletions perceval/rendering/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ def add_mpath(self,
stroke_linejoin: str = "miter",
stroke_dasharray=None):
"""Draw a path

:param fill:
:param points:
:param stroke:
:param stroke_width:
:return:
"""
assert not self._drawn, "calling add_mpath on drawn canvas"
norm_points = []
Expand Down Expand Up @@ -236,7 +230,7 @@ def add_circle(self,
self.position = (points[0] + r, points[1] + r)
self.position = (points[0] - r, points[1] - r)
self.position = points
return (self.position[0], self._inverse_Y * self.position[1])
return self.position[0], self._inverse_Y * self.position[1]

def add_text(self, points: tuple[float, float],
text: str, size: float,
Expand All @@ -252,10 +246,10 @@ def add_text(self, points: tuple[float, float],
else:
self.position = (points[0]-size*len(text)/2, points[1]+size)
self.position = (points[0]+size*len(text)/2, points[1]+size)
return (f_points[0], self._inverse_Y * f_points[1])
return f_points[0], self._inverse_Y * f_points[1]

def add_shape(self, shape_fn, circuit, content, mode_style, **opt):
shape_fn(circuit, self, content, mode_style, **opt)
def add_shape(self, shape_fn, circuit, mode_style):
shape_fn(circuit, self, mode_style)

def set_background_color(self, background_color):
"""
Expand Down
2 changes: 1 addition & 1 deletion perceval/rendering/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .phys_skin import PhysSkin
from .symb_skin import SymbSkin
from .debug_skin import DebugSkin
from .renderer import create_renderer
from .create_renderer import create_renderer


class DisplayConfig:
Expand Down
11 changes: 7 additions & 4 deletions perceval/rendering/circuit/abstract_skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
from enum import Enum
from multipledispatch import dispatch

from perceval.components import ACircuit, AProcessor, PERM
from perceval.components.abstract_component import AComponent
from perceval.components.non_unitary_components import TD
from perceval.components import ACircuit, AProcessor, PERM, AComponent, TD
from perceval.utils import format_parameters


class ModeStyle(Enum):
Expand All @@ -60,9 +59,10 @@ def __init__(self, stroke_style, style_subcircuit, compact_display: bool = False
self._compact = compact_display
self.style = {ModeStyle.PHOTONIC: stroke_style,
ModeStyle.HERALD: {"stroke": None, "stroke_width": 1}
# ModeStyle.HERALD: {"stroke": "yellow", "stroke_width": 1} # Use this for debug
}
self.style_subcircuit = style_subcircuit
self.precision: float = 1e-6
self.nsimplify: bool = True

@dispatch((ACircuit, TD), bool)
def get_size(self, c: ACircuit, recursive: bool = False) -> tuple[int, int]:
Expand Down Expand Up @@ -119,3 +119,6 @@ def get_width(self, c) -> int:
@abstractmethod
def get_shape(self, c) -> callable:
"""Returns the shape function of component c"""

def _get_display_content(self, circuit: ACircuit) -> str:
return format_parameters(circuit.get_variables(), self.precision, self.nsimplify)
Loading