Public API: opics package

components types

components.componentModel([f, nports, s, ...])

Defines the base component model class used to create new components for a library.

opics.components module

class opics.components.componentModel(f=None, nports=2, s=None, data_folder=None, filename=None, sparam_attr=None, **kwargs)[source]

Bases: object

Defines the base component model class used to create new components for a library.

Parameters
  • f (numpy.ndarray) – Frequency datapoints.

  • nports (int) – Number of ports in the component. Defaults to 2.

  • s (numpy.ndarray, optional) – S-parameter data. Defaults to None.

  • data_folder (pathlib.Path) – The location of the data folder containing s-parameter data files and the XML look-up-table.

  • filename (str) – Name of the XML look-up-table file.

  • sparam_attr (str, optional) – Look-up-table attribute Defaults to None.

get_data(ports=None, xscale='freq', yscale='log')[source]

Get the S-parameters data for specific [input,output] port combinations, to be used for plotting functionalities. (WARNING: unused, to be used in plot_sparameters)

Parameters
  • ports (Optional[List[List[int]]]) – List of lists that contains the desired S-parameters, e.g., [[1,1],[1,2],[2,1],[2,2]]. Defaults to None.

  • xscale (str) – Plotting x axis label. Defaults to “freq”.

  • yscale (str) – Plotting Y axis label. Defaults to “log”.

Returns

Dictionary containing the plotting information to be used, including S-parameters data and plotting labels.

Return type

temp_data

interpolate_sparameters(target_f, source_f, source_s)[source]

Cubic interpolation of the component sparameter data to match the desired simulation frequency range.

Parameters
  • target_f (ndarray) – The target frequency range onto which the s-parameters will be interpereted on.

  • source_f (ndarray) – The source frequency range that the component data has stored.

  • source_s (ndarray) – The source s-parameters that the component data has stored.

Returns

Interpolated s-parameters value over the target frequency range.

Return type

sparameters

load_sparameters(data_folder, filename)[source]

Loads sparameters either from an npz file or from a raw sparam file using a look-up table.

Parameters
  • data_folder (PosixPath) – Directory path of the data folder containing s-parameter data files and a look up table.

  • filename (str) – Name of the XML look-up-table file.

Returns

Array of the component’s s-parameters.

Return type

sparameters

plot_sparameters(ports=None, show_freq=True, scale='log', interactive=False)[source]

Plot the component’s S-parameters.

Parameters
  • ports (Optional[List[List[int]]]) – List of lists that contains the desired S-parameters, e.g., [[1,1],[1,2],[2,1],[2,2]]. Defaults to None.

  • show_freq (bool) – Flag to determine whether to plot with respect to frequency or wavelength. Defaults to True.

  • scale (str) – Plotting y axis scale, options available: [“log”, “abs”, “abs_sq”]. Defaults to “log”.

  • interactive (bool) – Make the plots interactive or not.

set_port_reference(port_number, port_name)[source]

Allows for custom naming of component ports

Parameters
  • port_number (int) – Port number.

  • port_name (str) – Custom port name.

Return type

None

write_sparameters(dirpath, filename, f_data, s_data)[source]

Export the simulated s-parameters to a file.

Parameters
  • dirpath (PosixPath) – Directory path.

  • filename (str) – Name of the file.

  • f_data (ndarray) – Frequency data.

  • s_data (ndarray) – S-parameter data.

Return type

None

opics.network module

class opics.network.Network(network_id=None, f=None, mp_config={'close_pool': False, 'enabled': False, 'proc_count': 0})[source]

Bases: object

Defines a circuit or a network.

Parameters
  • network_id (Optional[str]) – Define the network name.

  • f (Optional[ndarray]) – Frequency data points.

  • mp_config (Dict) –

    Enable/Disable multiprocessing (disabled by default); Expects the following information:

    1. ”enabled” : bool - enable/disable multiprocessing,

    2. ”proc_count”: int - process count

    3. ”close_pool”: bool - Should the solver terminate all the processes after the simulation is finished.

add_component(component, params={}, component_id=None)[source]

Adds component to a network.

Parameters
  • component (componentModel) – An instance of componentModel class.

  • params (Dict) – Component parameter values.

  • component_id (Optional[str]) – Custom component id tag.

connect(component_A_id, port_A, component_B_id, port_B)[source]

Connects two components together.

Parameters
  • component_A_id (Union[str, componentModel]) – A component ID or an instance of componentModel class.

  • port_A (int) – Port number of component_A

  • component_B_id (Union[str, componentModel]) – A component ID or an instance of componentModel class.

  • port_B (int) – Port number of component_B

disable_mp()[source]

Disables OPICS multiprocessing

enable_mp(process_count=0, close_pool=True)[source]

Enables OPICS multiprocessing

Parameters
  • process_count (int) – Number of processes to start. Leave the default value if not sure (let the system decide). Otherwise, use multiprocessing.cpu_count() to know the maximum number of processes that can be run safely.

  • close_pool (bool) – Whether to terminate all the processes after the simulation is done.

global_to_local_ports(net_id, nets)[source]

Maps the net_id to components and their local port numbers.

Parameters
Return type

List[int]

initiate_global_netlist()[source]

Initiates a global netlist with negative indices, overwrite indices that are used in the circuit with positive values.

simulate_network()[source]

Triggers the simulation

Return type

componentModel

opics.network.bulk_add_component(network, components_data)[source]

Allows for bulk adding of components

Parameters
  • network (Network) – Network to add components to.

  • components_data (List[Dict]) – A list of dictionaries including component class reference, parameter data, and component id

opics.network.inst_components(component_data)[source]

Given a component class, component parameter data, and component id, returns an instance of the component class.

Parameters

component_data (dict) –

{“component”: component_class, “params”: component_parameters, “component_id”, custom_component_id}

Example: {“component”: ebeam.Waveguide, “params”:{“f”: circuit.f, “length”: 10e-6}, “component_id”: “test_waveguide”}

opics.network.solve_tasks(data)[source]

Simulates a connection, either shared by two different components or by the same component.

Parameters

data (List) – A list with the following elements: [components_connected, net_to_port_data, components_nets].

opics.sparam_ops module

Functions operating on s-parameter matrices

opics.sparam_ops.connect_s(A, port_idx_A, B, port_idx_B, create_composite_matrix=True)[source]

connect two n-port networks’ s-matrices together.

specifically, connect port port_idx_A on network A to port port_idx_B on network B. The resultant network has nports = (A.rank + B.rank-2). This function operates on, and returns s-matrices. The function connect() operates on Network types.

Parameters
  • A (numpy.ndarray) – S-parameter matrix of A, shape is fxnxn

  • port_idx_A (int) – port index on A (port indices start from 0)

  • B (numpy.ndarray) – S-parameter matrix of B, shape is fxnxn

  • port_idx_B (int) – port index on B

Returns

C – new S-parameter matrix

Return type

numpy.ndarray

Notes

internally, this function creates a larger composite network and calls the innerconnect_s() function. see that function for more details about the implementation

See also

connect

operates on Network types

innerconnect_s

function which implements the connection connection algorithm

opics.sparam_ops.innerconnect_s(A, port_idx_A, port_idx_B)[source]

connect two ports of a single n-port network’s s-matrix.

Specifically, connect port port_idx_A to port port_idx_B on A. This results in a (n-2)-port network. This function operates on, and returns s-matrices. The function innerconnect() operates on Network types.

Parameters
  • A (numpy.ndarray) – S-parameter matrix of A, shape is fxnxn

  • port_idx_A (int) – port index on A (port indices start from 0)

  • port_idx_B (int) – port index on A

Returns

C – new S-parameter matrix

Return type

numpy.ndarray

Notes

The algorithm used to calculate the resultant network is called a ‘sub-network growth’, can be found in [#]_. The original paper describing the algorithm is given in [#]_.

References

  • Compton, R.C.; , “Perspectives in microwave circuit analysis,”

Circuits and Systems, 1989., Proceedings of the 32nd Midwest Symposium on , vol., no., pp.716-718 vol.2, 14-16 Aug 1989. http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=101955&isnumber=3167

  • Filipsson, Gunnar;

“A New General Computer Algorithm for S-Matrix Calculation of Interconnected Multiports,” Microwave Conference, 1981. 11th European , vol., no., pp.700-704, 7-11 Sept. 1981. http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4131699&isnumber=4131585

opics.sparam_ops.v_broadcast_sim(A, port_idx_A, port_idx_B)[source]
Return type

ndarray

opics.utils module

opics.utils.LUT_processor(filedir, lutfilename, lutdata, nports, sparam_attr, verbose=False)[source]

process look up table data

Return type

Tuple[Tuple[ndarray, ndarray], str]

opics.utils.LUT_reader(filedir, lutfilename, lutdata)[source]

Reads look up table data.

Parameters
  • filedir (PosixPath) – Directory of the XML look-up-table file.

  • lutfilename (str) – Look-up-table filename.

  • lutdata (List[List[str]]) – Look-up-table arguments.

opics.utils.NetlistProcessor(spice_filepath, Network, libraries, c_, circuitData, verbose=True)[source]

Processes a spice netlist to setup and simulate a circuit.

Parameters
  • spice_filepath – Path to the spice netlist file.

  • Network

opics.utils.fromSI(value)[source]

converts from SI unit values to metric

Parameters

value (str) – a value in SI units, e.g. 1.3u

Returns

the value in metric units.

Return type

float

class opics.utils.netlistParser(mainfile_path)[source]

Bases: object

A netlist parser to read spi files generated by SiEPIC tools

readfile()[source]
Return type

Dict[str, Any]

opics.utils.universal_sparam_filereader(nports, sfilename, sfiledir, format_type='auto')[source]

Function to automatically detect the sparameter file format and use appropriate method to delimit and format sparam data

This function is a unified version of sparameter reader function defined in https://github.com/BYUCamachoLab/simphony

Parameters
Return type

Tuple[ndarray, ndarray]