API

simphony

A Simulator for Photonic circuits

simphony.formatters

This module contains two types of classes: ModelFormatters and CircuitFormatters. These classes are used to serialize / unseralize models and circuits.

Specifically, instances of these classes should be used in the to_file and from_file methods on Model and Circuit.

class simphony.formatters.CircuitFormatter

Bases: object

Base circuit formatter class that is extended to provide functionality for converting a circuit to a string and vice-versa.

format(circuit: Circuit, freqs: numpy.array) str

Returns a string representation of the circuit.

Parameters

circuit – The circuit to get a string representation for.

parse(string: str) Circuit

Returns a circuit from the given string.

Parameters

string – The string to parse.

class simphony.formatters.CircuitJSONFormatter

Bases: object

This class handles converting a circuit to JSON and vice-versa.

class simphony.formatters.CircuitSiEPICFormatter(pdk=None)

Bases: simphony.formatters.CircuitFormatter

This class saves/loads circuits in the SiEPIC SPICE format.

format(circuit: Circuit, freqs: numpy.array) str

Returns a string representation of the circuit.

Parameters

circuit – The circuit to get a string representation for.

parse(string: str) Circuit

Returns a circuit from the given string.

Parameters

string – The string to parse.

class simphony.formatters.JSONDecoder

Bases: json.decoder.JSONDecoder

JSON Decoder class that handles complex object types.

decode(s, _w=<built-in method match of re.Pattern object>)

Return the Python representation of s (a str instance containing a JSON document).

raw_decode(s, idx=0)

Decode a JSON document from s (a str beginning with a JSON document) and return a 2-tuple of the Python representation and the index in s where the document ended.

This can be used to decode a JSON document from a string that may have extraneous data at the end.

class simphony.formatters.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.encoder.JSONEncoder

JSON Encoder class that handles np.ndarray and complex object types.

default(object)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
encode(o)

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
iterencode(o, _one_shot=False)

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
class simphony.formatters.ModelFormatter

Bases: object

Base model formatter class that is extended to provide functionality for converting a component (model instance) to a string and vice-versa.

format(component: Model, freqs: numpy.array) str

Returns a string representation of the component’s scattering parameters.

Parameters
  • component – The component to format.

  • freqs – The frequencies to get scattering parameters for.

parse(string: str) Model

Returns a component from the given string.

Parameters

string – The string to parse.

class simphony.formatters.ModelJSONFormatter

Bases: simphony.formatters.ModelFormatter

The ModelJSONFormatter class formats the model data in a JSON format.

format(component: Model, freqs: numpy.array) str

Returns a string representation of the component’s scattering parameters.

Parameters
  • component – The component to format.

  • freqs – The frequencies to get scattering parameters for.

parse(string: str) Model

Returns a component from the given string.

Parameters

string – The string to parse.

simphony.layout

This module contains the Circuit object. The Circuit object acts as a sorted set that contains components. As components connect/disconnect to each other, they will make sure that they belong to the same Circuit instance.

class simphony.layout.Circuit(component: Model)

Bases: list

The Circuit class keeps an ordered list of components.

The components themselves manage which circuits they belong to as they are connected and disconnected from one another.

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.CircuitFormatter] = None) simphony.layout.Circuit

Creates a circuit from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

get_pin_index(pin: Pin) int

Gets the pin index for the specified pin in the scattering parameters.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

insert(index, object, /)

Insert object before index.

property pins: List[Pin]

Returns the pins for the circuit.

pop(index=-1, /)

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value, /)

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()

Reverse IN PLACE.

s_parameters(freqs: np.array) np.ndarray

Returns the scattering parameters for the circuit.

sort(*, key=None, reverse=False)

Stable sort IN PLACE.

to_file(filename: str, freqs: np.array, *, formatter: Optional[simphony.formatters.CircuitFormatter] = None) None

Writes a string representation of this circuit to a file.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_subcircuit(name: str = '', **kwargs) Subcircuit

Converts this circuit into a subcircuit component for easy re-use in another circuit.

simphony.models

This module contains the Model and Subcircuit classes. The Model class is the base class for all models. The Subcircuit class is where the subnetwork growth algorithm takes place.

Instances of models are components. As components are connected to each other, they form a circuit. There are three ways to connect components:

  1. comp1_or_pin.connect(comp2_or_pin)

  2. comp1.multiconnect(comp_or_pin, comp_or_pin, ...)

  3. comp1.interface(comp2)

class simphony.models.Model(name: str = '', *, freq_range: Optional[Tuple[Optional[float], Optional[float]]] = None, pins: Optional[List[simphony.pins.Pin]] = None)

Bases: object

The basic element type describing the model for a component with scattering parameters.

Any class that inherits from Model or its subclasses must declare either the pin_count or pins attribute. See Attributes for more info.

freq_range

A tuple of the valid frequency bounds for the element in the order (lower, upper). Defaults to (-infty, infty).

Type

ClassVar[Tuple[Optional[float], Optional[float]]]

pin_count

The number of pins for the device. Must be set if pins is not.

Type

ClassVar[Optional[int]]

pins

A tuple of all the default pin names of the device. Must be set if pin_count is not.

Type

simphony.pins.PinList

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

class simphony.models.Subcircuit(circuit: simphony.layout.Circuit, name: str = '', *, permanent: bool = True, **kwargs)

Bases: simphony.models.Model

The Subcircuit model exposes the Model API for a group of connected components.

Any unconnected pins from the underlying components are re-exposed. This requires that unconnected pins have unique names.

classmethod clear_scache() None

Clears the scattering parameters cache.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Returns the Monte Carlo scattering parameters for the subcircuit.

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate Monte Carlo s-matrices.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns the scattering parameters for the subcircuit.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

simphony.pins

This module contains the logic for managing pins and their connections. When connections are made, the pins handle letting the components know which in turn makes sure all components belong to the same Circuit instance.

class simphony.pins.Pin(component: Model, name: str)

Bases: object

This class represents an individual pin on a component.

As pins are connected and disconnected from each other, the components keep track of which circuit they belong to.

connect(pin_or_component: Union[Pin, Model]) None

Connects this pin to the pin/component that is passed in.

If a component instance is passed in, this pin will connect to the first unconnected pin of the component.

disconnect() None

Disconnects this pin to whatever it is connected to.

rename(name: str) None

Renames the pin.

class simphony.pins.PinList(component_or_pins: Union[list, Model], length: int = 0)

Bases: list

Keeps track and manages the pins in a component.

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

insert(index, object, /)

Insert object before index.

pop(index=-1, /)

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value, /)

Remove first occurrence of value.

Raises ValueError if the value is not present.

rename(*names: str) None

Renames the pins for this pinlist.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

reverse()

Reverse IN PLACE.

sort(*, key=None, reverse=False)

Stable sort IN PLACE.

simphony.simulation

This module contains the simulation context as well as simulation devices to be used within the context. Devices include theoretical sources and detectors.

class simphony.simulation.Detector(*args, conversion_gain=1, noise=0, **kwargs)

Bases: simphony.simulation.SimulationModel

The base class for all detectors.

When a detector is connected to the circuit, it defines how many outputs are returned from calling the Simulation.sample method. This detector only adds one output.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

class simphony.simulation.DifferentialDetector(*args, monitor_conversion_gain=1, monitor_noise=0, rf_conversion_gain=1, rf_noise=0, **kwargs)

Bases: simphony.simulation.Detector

A differential detector takes two connections and provides three outputs to the Simulation.sample method.

The outputs are [connection1, connection1 - connection2, connection2]. The first and third outputs are the monitor outputs and the second output is the RF output.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

class simphony.simulation.Laser(*args, coupling_loss=0, freq=None, phase=0, power=0, wl=1.55e-06, **kwargs)

Bases: simphony.simulation.Source

A Simphony model for a laser source.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

freqsweep(start: float, end: float, num: int = 500) simphony.simulation.Laser

Sets the frequencies to sweep during simulation.

Parameters
  • start – The frequency to start at.

  • end – The frequency to end at.

  • num – The number of frequencies to sweep.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

powersweep(start: float, end: float, num: int = 500) simphony.simulation.Laser

Sets the powers to sweep during simulation.

Parameters
  • start – The power to start at.

  • end – The power to end at.

  • num – The number of powers to sweep.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

wlsweep(start: float, end: float, num: int = 500) simphony.simulation.Laser

Sets the wavelengths to sweep during simulation.

Parameters
  • start – The wavelength to start at.

  • end – The wavelength to end at.

  • num – The number of wavelengths to sweep.

class simphony.simulation.Simulation(*, fs: float = 1000000000.0, seed: Optional[int] = None)

Bases: object

This class instantiates a simulation context.

Any simulation devices that are instantiated within the context block are managed by the instance of this class.

classmethod get_context() simphony.simulation.Simulation

Gets the current simulation context.

monte_carlo(flag: bool) None

Sets whether or not to use the Monte Carlo scattering parameters.

Parameters

flag – When True, Monte Carlo scattering parameters will be used. When False, they will not be used.

s_parameters(freqs: numpy.array) numpy.ndarray

Gets the scattering parameters for the specified frequencies.

Parameters

freqs – The list of frequencies to run simulations for.

sample(num_samples: int = 1) numpy.ndarray

Samples the outputs of the circuit. If more than one sample is requested, noise will be injected into the system. If only one sample is requested, the returned value will be purely theoretical.

Parameters

num_samples – The number of samples to take. If only one sample is taken, it will be the theoretical value of the circuit. If more than one sample is taken, they will vary based on simulated noise.

classmethod set_context(_context: simphony.simulation.Simulation) None

Sets the current simulation context.

Parameters

_context – The current Simulation instance.

class simphony.simulation.SimulationModel(*args, **kwargs)

Bases: simphony.models.Model

A Simphony model that is aware of the current Simulation context.

Models that extend this one should automatically connect to the context upon instantiation.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

class simphony.simulation.Source(*args, **kwargs)

Bases: simphony.simulation.SimulationModel

A simphony model for a source.

It automatically connects to the current simulation context upon instantiation.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

simphony.simulators

This module contains the simulator components. Simulators must be connected to components before simulating. This can be done using the same connection methods that exist on a component.

class simphony.simulators.MonteCarloSweepSimulator(start: float = 1.5e-06, stop: float = 1.6e-06, num: int = 2000)

Bases: simphony.simulators.SweepSimulator

Wrapper simulator to make it easier to simulate over a range of frequencies while performing Monte Carlo experimentation.

classmethod clear_scache() None

Clears the scattering parameters cache.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

simulate(runs: int = 10, **kwargs) Tuple[numpy.array, numpy.array]

Runs the Monte Carlo sweep simulation for the circuit.

Parameters
  • dB – Returns the power ratios in deciBels when True.

  • mode – Whether to return frequencies or wavelengths for the corresponding power ratios. Defaults to whatever values were passed in upon instantiation.

  • runs – The number of Monte Carlo iterations to run (default 10).

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

class simphony.simulators.Simulator(name: str = '', *, freq_range: Optional[Tuple[Optional[float], Optional[float]]] = None, pins: Optional[List[simphony.pins.Pin]] = None)

Bases: simphony.models.Model

Simulator model that can be used to instantiate a simulator.

The first pin of the simulator should be attached to the input of the circuit that you want to simulate. The second pin should be attached to the output.

classmethod clear_scache() None

Clears the scattering parameters cache.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

simulate(*, dB: bool = False, freq: float = 0, freqs: Optional[numpy.array] = None, s_parameters_method: str = 's_parameters') Tuple[numpy.array, numpy.array]

Simulates the circuit.

Returns the power ratio at each specified frequency.

Parameters
  • dB – Returns the power ratios in deciBels when True.

  • freq – The single frequency to run the simulation for. Must be set if freqs is not.

  • freqs – The list of frequencies to run simulations for. Must be set if freq is not.

  • s_parameters_method – The method name to call to get the scattering parameters.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

class simphony.simulators.SweepSimulator(start: float = 1.5e-06, stop: float = 1.6e-06, num: int = 2000)

Bases: simphony.simulators.Simulator

Wrapper simulator to make it easier to simulate over a range of frequencies.

classmethod clear_scache() None

Clears the scattering parameters cache.

connect(component_or_pin: Union[simphony.models.Model, simphony.pins.Pin]) simphony.models.Model

Connects the next available (unconnected) pin from this component to the component/pin passed in as the argument.

If a component is passed in, the first available pin from this component is connected to the first available pin from the other component.

disconnect() None

Disconnects this component from all other components.

static from_file(filename: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a file using the specified formatter.

Parameters
  • filename – The filename to read from.

  • formatter – The formatter instance to use.

static from_string(string: str, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) simphony.models.Model

Creates a component from a string using the specified formatter.

Parameters
  • string – The string to load the component from.

  • formatter – The formatter instance to use.

interface(component: simphony.models.Model) simphony.models.Model

Interfaces this component to the component passed in by connecting pins with the same names.

Only pins that have been renamed will be connected.

monte_carlo_s_parameters(freqs: numpy.array) numpy.ndarray

Implements the monte carlo routine for the given Model.

If no monte carlo routine is defined, the default behavior returns the result of a call to s_parameters().

Parameters

freqs (np.array) – The frequency range to generate monte carlo s-parameters over.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by monte_carlo_s_parameters would be (1, 4, 4).

Return type

np.ndarray

multiconnect(*connections: Optional[Union[simphony.models.Model, simphony.pins.Pin]]) simphony.models.Model

Connects this component to the specified connections by looping through each connection and connecting it with the corresponding pin.

The first connection is connected to the first pin, the second connection to the second pin, etc. If the connection is set to None, that pin is skipped.

See the connect method for more information if the connection is a component or a pin.

regenerate_monte_carlo_parameters() None

Regenerates parameters used to generate monte carlo s-matrices.

If a monte carlo method is not implemented for a given model, this method does nothing. However, it can optionally be implemented so that parameters are regenerated once per circuit simulation. This ensures correlation between all components of the same type that reference this model in a circuit. For example, the effective index of a waveguide should not be different for each waveguide in a small circuit; they will be more or less consistent within a single small circuit.

The MonteCarloSweepSimulation calls this function once per run over the circuit.

Notes

This function should not accept any parameters, but may act on instance or class attributes.

rename_pins(*names: str) None

Renames the pins for this component.

The first pin is renamed to the first value passed in, the second pin is renamed to the second value, etc.

s_parameters(freqs: numpy.array) numpy.ndarray

Returns scattering parameters for the element with its given parameters as declared in the optional __init__().

Parameters

freqs (np.array) – The frequency range to get scattering parameters for.

Returns

s – The scattering parameters corresponding to the frequency range. Its shape should be (the number of frequency points x ports x ports). If the scattering parameters are requested for only a single frequency, for example, and the device has 4 ports, the shape returned by s_parameters would be (1, 4, 4).

Return type

np.ndarray

Raises

NotImplementedError – Raised if the subclassing element doesn’t implement this function.

simulate(mode: Optional[str] = None, **kwargs) Tuple[numpy.array, numpy.array]

Runs the sweep simulation for the circuit.

Parameters
  • dB – Returns the power ratios in deciBels when True.

  • mode – Whether to return frequencies or wavelengths for the corresponding power ratios. Defaults to whatever values were passed in upon instantiation. Either ‘freq’ or ‘wl’.

to_file(filename: str, freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) None

Writes this component’s scattering parameters to the specified file using the specified formatter.

Parameters
  • filename – The name of the file to write to.

  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

to_string(freqs: numpy.array, *, formatter: Optional[simphony.formatters.ModelFormatter] = None) str

Returns this component’s scattering parameters as a formatted string.

Parameters
  • freqs – The list of frequencies to save data for.

  • formatter – The formatter instance to use.

simphony.tools

This package contains handy functions useful across simphony submodules and to the average user.

simphony.tools.freq2wl(freq)

Convenience function for converting from frequency to wavelength.

Parameters

freq (float) – The frequency in SI units (Hz).

Returns

wl – The wavelength in SI units (m).

Return type

float

simphony.tools.interpolate(resampled, sampled, s_parameters)

Returns the result of a cubic interpolation for a given frequency range.

Parameters
  • output_freq (np.ndarray) – The desired frequency range for a given input to be interpolated to.

  • input_freq (np.ndarray) – A frequency array, indexed matching the given s_parameters.

  • s_parameters (np.array) – S-parameters for each frequency given in input_freq.

Returns

result – The values of the interpolated function (fitted to the input s-parameters) evaluated at the output_freq frequencies.

Return type

np.array

simphony.tools.str2float(num)

Converts a number represented as a string to a float. Can include suffixes (such as ‘u’ for micro, ‘k’ for kilo, etc.).

Parameters

num (str) – A string representing a number, optionally with a suffix.

Returns

The string converted back to its floating point representation.

Return type

float

Raises

ValueError – If the argument is malformed or the suffix is not recognized.

Examples

>>> str2float('14.5c')
0.145

Values without suffixes get converted to floats normally.

>>> str2float('2.53')
2.53

If an unrecognized suffix is present, a ValueError is raised.

>>> str2float('17.3o')
ValueError: Suffix 'o' in '17.3o' not recognized.
([-+]?[0-9]+[.]?[0-9]*((?:[eE][-+]?[0-9]+)|[a-zA-Z])?)

Some floats are represented in exponential notation instead of suffixes, and we can handle those, too:

>>> str2float('15.2e-6')
1.52e-7
>>> str2float('0.4E6')
400000.0
simphony.tools.wl2freq(wl)

Convenience function for converting from wavelength to frequency.

Parameters

wl (float) – The wavelength in SI units (m).

Returns

freq – The frequency in SI units (Hz).

Return type

float