Skip to content

Commit

Permalink
Introduced angle variables and expressions. Still WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
sg495 committed Apr 21, 2022
1 parent 795ed2e commit 06c0178
Show file tree
Hide file tree
Showing 9 changed files with 23,270 additions and 22,291 deletions.
6,834 changes: 3,428 additions & 3,406 deletions notebooks/1. Qubit Topologies.ipynb

Large diffs are not rendered by default.

269 changes: 251 additions & 18 deletions notebooks/2. Circuits of Phase Gadgets.ipynb

Large diffs are not rendered by default.

16,015 changes: 8,055 additions & 7,960 deletions notebooks/3. CX Circuits.ipynb

Large diffs are not rendered by default.

20,568 changes: 10,374 additions & 10,194 deletions notebooks/4. Phase Circuit Optimization.ipynb

Large diffs are not rendered by default.

1,206 changes: 609 additions & 597 deletions notebooks/5. Phase Circuit Simplification.ipynb

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions pauliopt/phase/optimized_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from collections import deque
from math import ceil, log10
from typing import (Deque, Dict, List, Optional, Protocol,
from typing import (Callable, Deque, Dict, List, Optional, Protocol,
runtime_checkable, Set, Tuple, TypedDict, Union)
import numpy as np # type: ignore
from pauliopt.phase.phase_circuits import PhaseCircuit, PhaseCircuitView
from pauliopt.phase.cx_circuits import CXCircuitLayer, CXCircuit, CXCircuitView
from pauliopt.topologies import Topology
from pauliopt.utils import (TempSchedule, StandardTempSchedule,
from pauliopt.utils import (AngleVar, TempSchedule, StandardTempSchedule,
StandardTempSchedules, SVGBuilder)

@runtime_checkable
Expand Down Expand Up @@ -124,13 +124,15 @@ class OptimizedPhaseCircuit:
_gadget_cx_count_cache: Dict[int, Dict[Tuple[int, ...], int]]
_rng_seed: Optional[int]
_rng: np.random.Generator
_fresh_angle_vars: Union[None, Callable[[int], AngleVar]]

def __init__(self, phase_block: Union[PhaseCircuit, PhaseCircuitView],
topology: Topology,
cx_block: Union[int, CXCircuit, CXCircuitView],
*,
circuit_rep: int = 1,
rng_seed: Optional[int] = None):
rng_seed: Optional[int] = None,
fresh_angle_vars: Union[None, str, Callable[[int], AngleVar]] = None):
if not isinstance(phase_block, PhaseCircuit):
raise TypeError(f"Expected PhaseCircuit, found {type(phase_block)}.")
if not isinstance(topology, Topology):
Expand Down Expand Up @@ -159,6 +161,10 @@ def __init__(self, phase_block: Union[PhaseCircuit, PhaseCircuitView],
self._init_cx_count, self._init_cx_blocks_count = self._compute_cx_count()
self._cx_count = self._init_cx_count
self._cx_blocks_count = self._init_cx_blocks_count
if isinstance(fresh_angle_vars, str):
self._fresh_angle_vars = lambda i: AngleVar(f"{fresh_angle_vars}[{i}]", f"{fresh_angle_vars}_{i}")
else:
self._fresh_angle_vars = fresh_angle_vars

@property
def topology(self) -> Topology:
Expand Down Expand Up @@ -518,7 +524,10 @@ def _to_svg(self, *,
base_x = base_x + (max_lvl+1) * row_width//3
levels = [0 for _ in range(num_qubits)]
max_lvl = 0
for gadget in gadgets:
for i, gadget in enumerate(gadgets):
angle = gadget.angle
if isinstance(angle, AngleVar) and self._fresh_angle_vars is not None:
angle = self._fresh_angle_vars(i)
fill = zcolor if gadget.basis == "Z" else xcolor
other_fill = xcolor if gadget.basis == "Z" else zcolor
qubit_span = range(min(gadget.qubits), max(gadget.qubits)+1)
Expand All @@ -538,12 +547,12 @@ def _to_svg(self, *,
builder.line((x+delta_fst, text_y), (x+delta_snd, text_y))
builder.circle((x+delta_fst, text_y), r, other_fill)
builder.circle((x+delta_snd, text_y), r, fill)
builder.text((x+delta_snd+2*r, text_y), str(gadget.angle), font_size=font_size)
builder.text((x+delta_snd+2*r, text_y), str(angle), font_size=font_size)
else:
for q in gadget.qubits:
y = pad_y + (q+1)*line_height
builder.circle((x, y), r, fill)
builder.text((x+r, y-line_height//3), str(gadget.angle), font_size=font_size)
builder.text((x+r, y-line_height//3), str(angle), font_size=font_size)
base_x = base_x + (max_lvl+1) * row_width
levels = [0 for _ in range(num_qubits)]
max_lvl = 0
Expand Down
Loading

0 comments on commit 06c0178

Please sign in to comment.