Skip to content

Commit

Permalink
Merge pull request #497 from Jan-David-Black/496
Browse files Browse the repository at this point in the history
Realize #496
  • Loading branch information
joamatab committed Jun 29, 2022
2 parents b1532fd + dc22d75 commit acf3d5b
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions gdsfactory/components/pack_doe.py
@@ -1,5 +1,5 @@
import itertools as it
from typing import Any, Dict, List
from typing import Any, Dict, List, Tuple

import gdsfactory as gf
from gdsfactory.cell import cell
Expand All @@ -9,6 +9,40 @@
from gdsfactory.types import CellSpec, ComponentSpec, Optional


def generate_doe(
doe: ComponentSpec,
settings: Dict[str, List[Any]],
do_permutations: bool = False,
function: Optional[CellSpec] = None,
) -> Tuple[List[Component], List[Dict]]:
"""generates a component DOE (Design of Experiment),
which can then be packed, or used elsewhere.
Args:
doe: function to return Components.
settings: component settings.
do_permutations: for each setting.
function: for the component (add padding, grating couplers ...)
"""
if do_permutations:
settings_list = [dict(zip(settings, t)) for t in it.product(*settings.values())]
else:
settings_list = [dict(zip(settings, t)) for t in zip(*settings.values())]

if function:
function = gf.get_cell(function)
if not callable(function):
raise ValueError(f"Error {function!r} needs to be callable.")
component_list = [
function(gf.get_component(doe, **settings)) for settings in settings_list
]
else:
component_list = [
gf.get_component(doe, **settings) for settings in settings_list
]
return component_list, settings_list


@cell
def pack_doe(
doe: ComponentSpec,
Expand Down Expand Up @@ -42,22 +76,9 @@ def pack_doe(
h_mirror: horizontal mirror in y axis (x, 1) (1, 0). This is the most common.
v_mirror: vertical mirror using x axis (1, y) (0, y)
"""
if do_permutations:
settings_list = [dict(zip(settings, t)) for t in it.product(*settings.values())]
else:
settings_list = [dict(zip(settings, t)) for t in zip(*settings.values())]

if function:
function = gf.get_cell(function)
if not callable(function):
raise ValueError(f"Error {function!r} needs to be callable.")
component_list = [
function(gf.get_component(doe, **settings)) for settings in settings_list
]
else:
component_list = [
gf.get_component(doe, **settings) for settings in settings_list
]
component_list, settings_list = generate_doe(
doe, settings, do_permutations, function
)

c = pack(component_list=component_list, **kwargs)

Expand Down

0 comments on commit acf3d5b

Please sign in to comment.