From 69e81db550d4ae2d4601e6d4f8ed5d226a210f60 Mon Sep 17 00:00:00 2001 From: daquintero Date: Wed, 8 May 2024 17:20:40 +0200 Subject: [PATCH] Sounds like inminent upgrade is required --- docs/autoapi/piel/visual/style/index.rst | 26 ++++++++++++ docs/examples/03a_sax_cocotb_cosimulation.py | 2 +- .../03b_optical_function_verification.py | 33 ++++++++++++++- piel/models/logic/photonic/__init__.py | 1 + piel/models/logic/photonic/switch_lattice.py | 42 +++++++++++++++++++ 5 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 docs/autoapi/piel/visual/style/index.rst create mode 100644 piel/models/logic/photonic/switch_lattice.py diff --git a/docs/autoapi/piel/visual/style/index.rst b/docs/autoapi/piel/visual/style/index.rst new file mode 100644 index 00000000..93a04a61 --- /dev/null +++ b/docs/autoapi/piel/visual/style/index.rst @@ -0,0 +1,26 @@ +:py:mod:`piel.visual.style` +=========================== + +.. py:module:: piel.visual.style + + +Module Contents +--------------- + + +Functions +~~~~~~~~~ + +.. autoapisummary:: + + piel.visual.style.activate_piel_styles + + + +.. py:function:: activate_piel_styles() + + Activates the piel fast rc params. + + :returns: None + + diff --git a/docs/examples/03a_sax_cocotb_cosimulation.py b/docs/examples/03a_sax_cocotb_cosimulation.py index 8700cb03..f004ff45 100644 --- a/docs/examples/03a_sax_cocotb_cosimulation.py +++ b/docs/examples/03a_sax_cocotb_cosimulation.py @@ -414,7 +414,7 @@ # # So this tells us all the models that are recursively composed, but not inherently provided by our defaults library. These are the models we can explore. -recursive_composed_required_models_0 = sax.get_required_circuit_models( +recursive_composed_required_models_0 = piel.tools.sax.get_required_circuit_models( mixed_switch_lattice_circuit_netlist[recursive_composed_required_models[0]], models=piel.models.frequency.get_default_models(), ) diff --git a/docs/examples/03b_optical_function_verification.py b/docs/examples/03b_optical_function_verification.py index b9f11c9b..5f027f5d 100644 --- a/docs/examples/03b_optical_function_verification.py +++ b/docs/examples/03b_optical_function_verification.py @@ -25,7 +25,9 @@ import functools from itertools import product import gdsfactory as gf +import jax import jax.numpy as jnp +import numpy as np import pandas as pd from piel import straight_heater_metal_simple import piel @@ -33,7 +35,8 @@ import sax import random -random.seed(0) +jax.random.key(0) +np.random.seed(0) # - # ## Circuit Construction @@ -251,6 +254,32 @@ # True # ``` -# One thing I have noticed is that depending on the random configuration of the runner, sometimes the cross and bar states invert on which phase they map. I need to see how to fix that within the computation, if it is even possible. +# WARNING: One thing I have noticed is that depending on the random configuration of the runner, sometimes the cross and bar states invert on which phase they map. I need to see how to fix that within the computation, if it is even possible. + +# ## Further Analytical Modelling +# +# Let's consider how a switching network behaves symbolically. Say we have two switches in a chain, illustrated by this format: + +chain_mode_3 = np.array([['X', 0,], + [0, 'X']]) +chain_mode_3_switch_position_list = piel.models.logic.photonic.compose_switch_position_list( + network=chain_mode_3 +) +chain_mode_3, chain_mode_3_switch_position_list + + +# Let's consider the "X" state can only have two possible states, cross and bar which are represented by the angle applied, (0 -> 0, bar) and (1 -> $\pi$, cross). +# +# If we have a fock state `[[1], [0], [0]]` inputted onto the switch lattice, we want it to route out the photon accordingly at the bottom mode index 2, third waveguide. Accordingly, the top-most switch needs to cross and the bottom most needs to bar in order to achieve this function. +# +# +# We can try a little analytical simulator accordingly. Each "switch" state gets replaced by a 2x2 transmission matrix for each specific state, and concatenated to build the correponding state of the system. + +def a( + switch_network: list[list] + states: tuple = (0,1) +): + + diff --git a/piel/models/logic/photonic/__init__.py b/piel/models/logic/photonic/__init__.py index e69de29b..af0b8dec 100644 --- a/piel/models/logic/photonic/__init__.py +++ b/piel/models/logic/photonic/__init__.py @@ -0,0 +1 @@ +from .switch_lattice import compose_switch_position_list diff --git a/piel/models/logic/photonic/switch_lattice.py b/piel/models/logic/photonic/switch_lattice.py new file mode 100644 index 00000000..f1a5d4db --- /dev/null +++ b/piel/models/logic/photonic/switch_lattice.py @@ -0,0 +1,42 @@ +import functools +from itertools import product +import numpy as np +import pathlib +from typing import Optional, Callable + + +def compose_switch_position_list( + network: np.array, + gap_elements: list = None, + cross_elements: list = None, + *args, + **kwargs +): + """ + This function returns a list of the switch positions in the network, the corresponding instance, and the 2D position in the network. + + Args: + network (np.array): The network array. + gap_elements (list, optional): The gap elements in the network. Defaults to None. + cross_elements (list, optional): The cross elements in the network. Defaults to None. + + Returns: + switch_position_list (list): A list of tuples of the form (switch_instance, (row, col)). + """ + if cross_elements is None: + cross_elements = ["-"] + if gap_elements is None: + gap_elements = ["0"] + + # Temporary fix for the case where the gap_elements and cross_elements are lists + cross_elements = cross_elements[0] + gap_elements = gap_elements[0] + + switch_position_list = [ + (value, (row, col)) + for row, row_values in enumerate(network) + for col, value in enumerate(row_values) + if (value != gap_elements) + if (value != cross_elements) + ] + return switch_position_list