Exemplo n.º 1
0
class PixelParametrization(optplan.Parametrization):
    """Defines a `DirectParam`.

    Attributes:
        type: Must be "parametrization.pixel".
        init_method: Initialization condition.
        simulation_space: Simulation space to use parametrization in.
    """
    type = schema_utils.polymorphic_model_type("parametrization.direct")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    init_method = optplan.ReferenceType(Initializer)
Exemplo n.º 2
0
class Overlap(optplan.Function):
    """Defines an overlap integral.

    Attributes:
        type: Must be "function.overlap".
        simulation: Simulation from which electric fields are obtained.
        overlap: Overlap type to use.
    """
    type = schema_utils.polymorphic_model_type("function.overlap")
    simulation = optplan.ReferenceType(optplan.Function)
    overlap = optplan.ReferenceType(optplan.EmOverlap)
Exemplo n.º 3
0
class PhaseAbsolute(optplan.Function):
    """Defines a function that returns the absolute phase of the field.

    Attributes:
        type: Must be "function.phase_absolute".
        simulation: Simulation from which electric fields are obtained.
    """
    type = schema_utils.polymorphic_model_type("function.phase_absolute")
    simulation = optplan.ReferenceType(optplan.Function)
    region = optplan.ReferenceType(optplan.EmRegion)
    path = optplan.ReferenceType(optplan.EmRegion)
Exemplo n.º 4
0
class ScipyOptimizerMonitorList(schema_utils.Model):
    """Defines an optimizer carried out by `ScipyOptimizer`.

    Attributes:
        callback_monitors: monitors evaluated every iteration
        start_monitors: monitors evaluated at the transformation start
        end_monitors: monitors evaluated at the transformation end

    """
    callback_monitors = types.ListType(optplan.ReferenceType(optplan.Monitor))
    start_monitors = types.ListType(optplan.ReferenceType(optplan.Monitor))
    end_monitors = types.ListType(optplan.ReferenceType(optplan.Monitor))
Exemplo n.º 5
0
class ParamEps(EpsilonSpec):
    """Defines a permittivity distribution based on a parametriation.

    Attributes:
        type: Must be "parametrization".
        parametrization: Name of the parametrization.
        simulation_space: Name of the simulation space.
        wavelength: Wavelength.
    """
    type = schema_utils.polymorphic_model_type("parametrization")
    parametrization = optplan.ReferenceType(optplan.Parametrization)
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    wavelength = types.FloatType()
Exemplo n.º 6
0
class Epsilon(optplan.Function):
    """Defines a Epsilon Grid.

    Attributes:
        type: Must be "function.epsilon".
        name: Name of epsilon.
        simulation_space: Simulation space name.
        wavelength: Wavelength at which to calculate epsilon.
    """
    type = schema_utils.polymorphic_model_type("function.epsilon")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    wavelength = types.FloatType()
    structure = optplan.ReferenceType(optplan.Parametrization)
Exemplo n.º 7
0
class WaveguidePhase(optplan.Function):
    """Defines a function that returns the phase difference between a waveguide mode
    and the source.

    Attributes:
        type: Must be "function.phase_absolute".
        simulation: Simulation from which electric fields are obtained.
        overlap: Overlap type to use.
        path: path from the source to the measurement waveguide mode region
    """
    type = schema_utils.polymorphic_model_type("function.waveguide_phase")
    simulation = optplan.ReferenceType(optplan.Function)
    overlap_in = optplan.ReferenceType(optplan.EmOverlap)
    overlap_out = optplan.ReferenceType(optplan.EmOverlap)
    path = optplan.ReferenceType(optplan.EmRegion)
Exemplo n.º 8
0
class StoredEnergy(optplan.Function):
    """Defines an integral for calculating the stored energy in a resonator.

    Attributes:
        type: Must be "function.stored_energy".
        simulation: Simulation from which electric fields are obtained.
        center: Centre of integration region
        extents: Width and height of integration region.
        epsilon: Permittivity.
    """
    type = schema_utils.polymorphic_model_type("function.stored_energy")
    simulation = optplan.ReferenceType(optplan.Function)
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    center = optplan.vec3d()
    extents = optplan.vec3d()
    epsilon = optplan.ReferenceType(optplan.Function)
Exemplo n.º 9
0
class JoinedMonitorDescription(schema_utils.Model):
    """Stores joiner id's and their corresponding monitor information.

    Attributes:
        joiner_id: String that is used to join monitors across transformations.
        monitor_names: List of monitor objects corresponding to the joiner_id.
        monitor_type: String describing the type of data contained in the monitor.
        scalar_operation: String specifying how to process scalar monitor data.
        vector_operation: String specifying how to process planar monitor data.
    """
    joiner_id = types.StringType()
    monitor_names = types.ListType(optplan.ReferenceType(optplan.Monitor))
    monitor_type = types.StringType(choices=("scalar", "planar", "volume"))
    scalar_operation = types.StringType(choices=("magnitude_squared",
                                                 "magnitude", "phase", "real",
                                                 "imag"))
    vector_operation = types.StringType(choices=("magnitude", "x", "y", "z"))

    def __init__(self, *args, **kwargs) -> None:
        """Creates a new `JoinedMonitorDescription`.

        This allows `JoinedMonitorDescription` to be created in these additional
        ways:
        1) If `joiner_id` is not specified, the first entry in `monitor_names`
           is used.
        2) `monitor_name` can be specified as a single string, which will be
           converted to a list and put into `monitor_names`.
        """
        if "monitor_name" in kwargs:
            kwargs["monitor_names"] = [kwargs["monitor_name"]]
            del kwargs["monitor_name"]
        super().__init__(*args, **kwargs)
        if not self.joiner_id:
            self.joiner_id = self.monitor_names[0]
Exemplo n.º 10
0
class Log10(optplan.Function):
    """Defines Log base 10 value of a function.

    Attributes:
        type: Must be "log".
        function: The function to take absolute value of.
    """
    type = schema_utils.polymorphic_model_type("function.log10")
    function = optplan.ReferenceType(optplan.Function)
Exemplo n.º 11
0
class IndicatorPlus(optplan.Function):
    """Defines a penalty function to check if a function is above some value

    penalty = (obj>alpha)*(obj - alpha)**power
    """
    type = schema_utils.polymorphic_model_type("function.indicator_plus")
    function = optplan.ReferenceType(optplan.Function)
    alpha = types.FloatType()
    power = types.IntType()
Exemplo n.º 12
0
class BicubicLevelSetParametrization(optplan.Parametrization):
    """Defines `BicubicLevelsetParametrization`.

    Attributes:
        simulation_space: Name of simulation space to reference to generate
            the coarse grid.
        undersample: How much the coarse grid undersamples the rough grid.
        reflection_symmetry: List of booleans corresponding whether the
            structure should be symmetric about the x- and y- axes.
        init_method: Specifications on how to initialize the parametrization.
    """
    type = schema_utils.polymorphic_model_type(
        "parametrization.bicubic_levelset")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    undersample = types.FloatType()
    init_method = optplan.ReferenceType(Initializer)
    reflection_symmetry = types.ListType(types.BooleanType())
    periods = types.ListType(types.IntType())
Exemplo n.º 13
0
class Abs(optplan.Function):
    """Defines absolute value of a function.

    Attributes:
        type: Must be "abs".
        function: The function to take absolute value of.
    """
    type = schema_utils.polymorphic_model_type("function.abs")
    function = optplan.ReferenceType(optplan.Function)
Exemplo n.º 14
0
class PenaltyTransformation(optplan.TransformationBase):
    """Defines an optimizer carried out by `PenaltyOptimizer`.

    Attributes:
        type: Must be "penalty_optimizer".
        optimizer: Name of optimizer.
        objective: Name of objective function.
        constraints_eq: List of names of equality constraint functions.
        constraints_ineq: List of names of inequality constraint functions.
        monitor_lists: List of names of monitors to trigger at certain events.
        optimization_options: Options to use for the optimization.
    """
    type = schema_utils.polymorphic_model_type("penalty_optimizer")
    optimizer = types.StringType()
    objective = optplan.ReferenceType(optplan.Function)
    constraints_eq = types.ListType(optplan.ReferenceType(optplan.Function))
    constraints_ineq = types.ListType(optplan.ReferenceType(optplan.Function))
    monitor_lists = types.ModelType(ScipyOptimizerMonitorList)
    optimization_options = types.ModelType(PenaltyOptimizerOptions)
Exemplo n.º 15
0
class CompositeParametrization(optplan.Parametrization):
    """Defines a composite parametrization.

    Attributes:
        param_list: List of parametrizations in the composite. Note that the
            ordering of the parametrizations should be match the ordering
            of selection matrices in the simulation space.
    """
    type = schema_utils.polymorphic_model_type("parametrization.composite")
    param_list = types.ListType(optplan.ReferenceType(optplan.Parametrization))
Exemplo n.º 16
0
class GratingParametrization(optplan.Parametrization):
    """Defines a `GratingParam`.

    The grating is by default initialized to have no structure.

    Attributes:
        type: Must be "parametrization.grating_edge".
        simulation_space: Simulation space to use parametrization in.
    """
    type = schema_utils.polymorphic_model_type("parametrization.grating")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
Exemplo n.º 17
0
class FdfdSimulation(optplan.Function):
    """Defines a FDFD simulation.

    Attributes:
        type: Must be "function.fdfd_simulation".
        name: Name of simulation.
        simulation_space: Simulation space name.
        source: Source name.
        wavelength: Wavelength at which to simulate.
        solver: Name of solver to use.
        bloch_vector: bloch optplan.vector at which to simulate.
    """
    type = schema_utils.polymorphic_model_type("function.fdfd_simulation")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    epsilon = optplan.ReferenceType(optplan.Function)
    source = optplan.ReferenceType(optplan.EmSource)
    wavelength = types.FloatType()
    solver = types.StringType(choices=("maxwell_bicgstab", "maxwell_cg",
                                       "local_direct"))
    bloch_vector = types.ListType(types.FloatType())
Exemplo n.º 18
0
class Power(optplan.Function):
    """Defines the power of a function.

    Attributes:
        type: Must be "power".
        function: Function to take power of.
        exp: Power.
    """
    type = schema_utils.polymorphic_model_type("function.power")
    function = optplan.ReferenceType(optplan.Function)
    exp = types.FloatType()
Exemplo n.º 19
0
class SimpleMonitor(optplan.Monitor):
    """Defines a monitor.

    A monitor takes the output of a scalar function.

    Attributes:
        type: Must be "monitor.scalar".
        function: Name of function to monitor.
    """
    type = schema_utils.polymorphic_model_type("monitor.simple")
    function = optplan.ReferenceType(optplan.Function)
Exemplo n.º 20
0
class GratingFeatureConstraint(optplan.Function):
    """Defines a feature constraint on `GratingParametrization`.

    Args:
        simulation_space: Used to extract the number of pixels in the design
            region.
        min_feature_size: Minimum feature size in nm.
    """
    type = schema_utils.polymorphic_model_type(
        "function.grating_feature_constraint")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    min_feature_size = types.FloatType()
Exemplo n.º 21
0
class WaveguideInitializer2(Initializer):
    """Initializes parametrization using with a rectangular epsilon shape.

    The two levels of the step function can optionally have uniformly random
    initialization.

    Attributes:
        lower_min: minimum value of the lower (background) permittivity
        lower_max: maximum value of the lower (background) permittivity
        upper_min: minimum value of the upper (waveguide) permittivity
        upper_max: maximum value of the upper (waveguide) permittivity
        region: optplan.Region object specifying the upper permittivity (waveguide) region
        sim_space: simulation object to use to generate the waveguide region
    """
    type = schema_utils.polymorphic_model_type("initializer.waveguide_2")
    lower_min = types.FloatType()
    lower_max = types.FloatType()
    upper_min = types.FloatType()
    upper_max = types.FloatType()
    sim_space = optplan.ReferenceType(optplan.SimulationSpace)
    region = optplan.ReferenceType(optplan.EmRegion)
Exemplo n.º 22
0
class DiffEpsilon(optplan.Function):
    """Defines a function that finds the L1 norm between two permittivities.

    Specifially, the function is defined as `sum(|epsilon - epsilon_ref|)`.

    Attributes:
        type: Must be "function.diff_epsilon".
        epsilon: Permittivity.
        epsilon_ref: Base permittivity to compare to.
    """
    type = schema_utils.polymorphic_model_type("function.diff_epsilon")
    epsilon = optplan.ReferenceType(optplan.Function)
    epsilon_ref = types.PolyModelType(EpsilonSpec)
Exemplo n.º 23
0
class PowerComp(optplan.Function):
    """Defines a penalty function to check if a function is in a certain range.

    penalty = R(f-(value-range/2))**exp+R((value-range/2)-f),
    where R is a ramp function.

    Attributes:
        type: Must be "function.power_comp".
    """
    type = schema_utils.polymorphic_model_type("function.power_comp")
    function = optplan.ReferenceType(optplan.Function)
    value = types.FloatType()
    range = types.FloatType()
    exp = types.FloatType()
Exemplo n.º 24
0
class GratingFeatureConstraint(optplan.Function):
    """Defines a feature constraint on `GratingParametrization`.

    Args:
        simulation_space: Used to extract the number of pixels in the design
            region.
        min_feature_size: Minimum feature size in nm.
        boundary_constraint_scale: See `spins.invdes.problem.GratingConstraint`
            for details.
    """
    type = schema_utils.polymorphic_model_type(
        "function.grating_feature_constraint")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    min_feature_size = types.FloatType()
    boundary_constraint_scale = types.FloatType(default=2.0)
Exemplo n.º 25
0
class GratingParametrization(optplan.Parametrization):
    """Defines a `GratingParam`.

    The grating is by default initialized to have no structure.

    Attributes:
        type: Must be "parametrization.grating_edge".
        simulation_space: Simulation space to use parametrization in.
        inverted: If `True`, defines a grating where each pair of edges
            correspond to a "hole". See
            `spins.invdes.parametrization.GratingParam` for details.
    """
    type = schema_utils.polymorphic_model_type("parametrization.grating")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    inverted = types.BooleanType(default=False)
Exemplo n.º 26
0
class ContToDiscThresholding(optplan.TransformationBase):
    """Defines a transformation that takes a continuous parametrization and
    thresholds it at a value.

    Attributes:
        type: Must be "cont_to_disc_thresholding".
        value: Threshold value.

    Note that this requests requires the parametrization to have the same
    parametrization  vector size, e.g. cubic to bicubic or hermiteparam
    to hermitelevelset.
    """
    type = schema_utils.polymorphic_model_type("cont_to_disc_thresholding")
    continuous_parametrization = optplan.ReferenceType(optplan.Parametrization)
    threshold = types.FloatType()
Exemplo n.º 27
0
class GratingEdgeFitTransformation(optplan.TransformationBase):
    """Defines the discretization procedure for gratings.

    Specifically, this will convert any epsilon description into a
    `GratingEdgeParametrization`.

    Attributes:
        parametrization: Parametrization to match structure to.
        min_feature: Minimum feature size in terms of number of pixels. Can be
            fractional.
    """
    type = schema_utils.polymorphic_model_type(
        "grating_edge_fit_transformation")
    parametrization = optplan.ReferenceType(optplan.Parametrization)
    min_feature = types.FloatType()
Exemplo n.º 28
0
class PowerTransmission(optplan.Function):
    """Defines a function that measures amount of power passing through plane.

    The amount of power is computed by summing the Poynting vector across
    the desired plane.

    Attributes:
        field: The simulation field to use.
        center: Center of plane to compute power.
        extents: Extents of the plane over which to compute power.
        normal: Normal direction of the plane. This determines the sign of the
            power flowing through the plane.
    """
    type = optplan.define_schema_type("function.poynting.plane_power")
    field = optplan.ReferenceType(optplan.FdfdSimulation)
    center = optplan.vec3d()
    extents = optplan.vec3d()
    normal = optplan.vec3d()
Exemplo n.º 29
0
class Product(optplan.Function):
    """Defines a product function.

    Attributes:
        type: Must be "function.product".
        functions: Functions there are multipied.
    """
    type = schema_utils.polymorphic_model_type("function.product")
    functions = types.ListType(optplan.ReferenceType(optplan.Function))

    def __mul__(self, obj):
        if isinstance(obj, Product):
            return Product(functions=self.functions + obj.functions)
        if isinstance(obj, optplan.Function):
            return Product(functions=self.functions + [obj])
        if isinstance(obj, (numbers.Number, optplan.ComplexNumber)):
            return Product(functions=self.functions + [make_constant(obj)])
        raise TypeError(
            "Attempting to multiply a node with type {} to type `Product`.".
            format(type(obj)))
Exemplo n.º 30
0
class MonitorDescription(schema_utils.Model):
    """Stores individual monitors and their relevant processing information.

    Attributes:
        monitor: Monitor object.
        joiner_id: String that is used to join monitors across transformations.
        monitor_type: String describing the type of data contained in the monitor.
        scalar_operation: String specifying how to process scalar monitor data.
        vector_operation: String specifying how to process planar monitor data.
    
    If both scalar_operation and vector_operation are specified, the vector_operation
        is performed first and then the scalar operation is performed.
    """
    monitor = optplan.ReferenceType(optplan.Monitor)
    joiner_id = types.StringType()
    monitor_type = types.StringType(choices=("scalar", "planar", "volume"))
    scalar_operation = types.StringType(choices=("magnitude_squared",
                                                 "magnitude", "phase", "real",
                                                 "imag"))
    vector_operation = types.StringType(choices=("magnitude", "x", "y", "z"))