A scripted element is a custom element that can be defined with analytic or imported s-parameter representations via Lumerical’s script language or MATLAB. They provide users with flexibility in defining the functionalities of circuit elements. Once created, they can be added to the element library as a Custom Element.
For INTERCONNECT 6.5+, the Scripted Element supports for both Sample Mode and Block Mode elements; the same set of scripts can be used to define both modes.
Scripted Element is added with the "version" property under the "Design kit" category, and this property can be used to version control scripted elements especially in Compact Model Libraries (CML) to distinguish the same model in different versions. Once the CML is published and installed in Design Kits, the (Scripted Element) version will no longer be editable for the end users.
This page describes how to create Scripted Elements, which provide users with flexibility in defining the functionalities of circuit elements.
A scripted element has 4 main components:
- a Property Editor
- a list of Ports
- a list of Results
- a setup Scripts (Setup, Ready, Go, Wrap-up)
To create a compound element, right-click on the view port and select "Create scripted element". Once the new "empty" scripted element is created, users can choose to change the icon of the new element by selecting "Set icon" (this is optional). With the scripted element selected, click on the the Edit button to open the edit window. In the edit window there will be 4 tabs corresponding to the 4 components of a scripted element.
Property Editor
The property editor includes a list of properties for the scripted element. By default, this list only contains the standard General properties. This default list can be modified and new custom properties can be introduced. Please refer to the addproperty script command page for the details of user defined properties.
Ports
This is a list of ports which allow the scripted element to transfer data to and from other elements. Here, we add two ports to the scripted element:
Results
The results list includes all the output results for the scripted element. Once the simulation has been ran, only the parameters that are both defined in the results section and set in the scripts (via setresult) can be accessed externally. Note that it is not necessary for scripted elements to have results.
Scripts
The scripts define the properties and functionalities of the scripted element.
- The scripts only have access to the scripted element's own properties (ie. those defined in the Property Editor). It does not have access to workspace variables (ie. those defined in the script prompt or in a script file). In addition, any variables defined in the scripts cannot be obtained from the script prompt or from a script file.
- The scripts can be debugged by pressing the TEST button. If there are no syntax errors or break commands in the script, you will see the line <script complete> in the script output. If there is a syntax error, the location of the error will be given in the script output. An example of an error message is: syntax error: prompt line: 38.
SETUP
- The setup script can be used to set the properties of the scripted element. Often, this is done through the setsparameter script command (which sets the s-parameters between the output and input port of the scripted element).
- The setup script is ran once at the initialization stage.
READY
- The ready script defines the criteria necessary to propagate the data.
- It is not necessary to define the ready stage.
GO
- The go script defines what data to send to the output ports.
- It is not necessary to define the go stage.
WRAP-UP
- The wrap-up script can be used to post-process the data at the end of the simulation.
- The wrap-up script is ran once at the wrap-up stage.
- It is not necessary to define the wrap-up stage.
Examples
There are four example files provided:
Example 1: The file scripted_elements.icp contains three examples about
- Optical Constant Gain
- Frequency Dependent Transmission
- Frequency Dependent Propagation
Example 2: The file digital_scripted_struct.icp contains two examples of a scripted digital inverter element, one for Sample Mode and the other for Block Mode.
Example 3: The file electrical_scripted_struct.icp contains two examples of an electrical gain element, one for Sample Mode and the other for Block Mode.
Example 4: The file optical_mm_scripted_struct.icp contains two examples of an optical gain element, one for Sample Mode and the other for Block Mode.
For details about each example, click on the corresponding tab below.
=======================================================
============================================
In scripted_elements.icp, there are three scripted element examples:
- Optical Constant Gain
- Frequency Dependent Transmission
- Frequency Dependent Propagation
The script commands used in these files are based on port frame push and pop, please see the following script commands pages for the implementation details of the script commands:
pushportdata, popportframe, pushportframe, getmonitorframe, getmonitorwaveform, lookupreadtable, lookupreadvalue, lookupreadnportsparameter
============================================
============================================
The file digital_scripted_struct.icp contains two examples of a scripted digital inverter element, one for Sample Mode and the other for Block Mode.
Sample Mode
The figure below shows the Sample Mode inverter system in the example file. The output of the Pseudo-Random Bit Sequence (PRBS) is in sample mode.
The "Scripted Inverter" has the following script in the "Go" window under the "Simulation" tab.
signalIn = popportframe( "input" ); if( signalIn.valid ) { logmessage( toscript( signalIn ) ); bitrate = signalIn.data.bandwidth.bitrate; mxX( nCount ) = signalIn.data.time; mxY( nCount ) = signalIn.data.value; if( signalIn.data.value > 0 ) { signalIn.data.value = 0; } else { signalIn.data.value = 1; } nCount = nCount + 1; } pushportframe( "output", signalIn );
It reads in the data from the buffer at the input port, inverts the signal and pushes the data to the output port.
The "Scripted Analyzer" is scripted the same way as the "Logic Analyzer" and has the following script in the "Wrap-up" window under the "Simulation" tab.
signalIn = getmonitorwaveform( "input" ); logmessage( toscript( signalIn, false ) ); setresult( "waveform", signalIn.time, signalIn.value, "time (s)", "amplitude (a.u.)" ); setresult( "bitrate", signalIn.bitrate, "bitrate (bits/s)" );
It collects all the data at the input port, set the data to a result dataset so that it could be visualized.
Please check the links for the details of the script commands popportframe, logmessage, pushportframe, getmonitorwaveform and setresult.
Block Mode
The figure below shows the Block Mode inverter system in the example file. The output of the PRBS is in block mode.
The "Scripted Inverter" has the following script in the "Go" window under the "Simulation" tab.
signalIn = popportframe( "input" ); if( signalIn.valid ) { logmessage( toscript( signalIn ) ); bitrate = signalIn.data.bandwidth.bitrate; for( i=1:length(signalIn.data.value) ) { if( signalIn.data.value( i ) > 0 ) { signalIn.data.value( i ) = 0; } else { signalIn.data.value( i ) = 1; } } } pushportframe( "output", signalIn );
It reads in the data from the buffer at the input port as a block, inverts the signal and pushes the data block to the output port.
The "Scripted Analyzer" is scripted the same way as the "Logic Analyzer" and has the following script in the "Wrap-up" window under the "Simulation" tab. The definition is the same as in the Sample Mode.
signalIn = getmonitorwaveform( "input", "time", 3 ); logmessage(toscript(signalIn,false)); setresult( "waveform", signalIn.time, signalIn.value, "time (s)", "amplitude (a.u.)" ); setresult( "bitrate", signalIn.bitrate, "bitrate (bits/s)" );
It collects all the data at the input port, set the data to a result dataset so that it could be visualized.
Please check the links for the details of the script commands popportframe, logmessage, pushportframe, getmonitorwaveform and setresult.
============================================
============================================
The file electrical_scripted_struct.icp contains two examples of an electrical gain element, one for Sample Mode and the other for Block Mode.
Sample Mode
The figure below shows the Sample Mode electrical amplifier system in the example file. The output of the Ramp source is in sample mode.
The "Scripted Gain" has the following script in the "Go" window under the "Simulation" tab.
signalIn = popportframe( "input" ); logmessage( toscript( signalIn ) ); if( signalIn.valid ) { logmessage( toscript( signalIn ) ); mxX( nCount ) = signalIn.data.time; mxY( nCount ) = signalIn.data.value; signalIn.data.value = signalIn.data.value * 10; nCount = nCount + 1; } pushportframe( "output", signalIn );
It reads in the electrical data from the buffer at the input port, enlarges the amplitude of the signals by 10 times and pushes the data to the output port.
The "Scripted Analyzer" is scripted the same way as the "Oscilloscope" and has the following script in the "Wrap-up" window under the "Simulation" tab.
signalIn = getmonitorwaveform( "input" ); logmessage( toscript( signalIn,false ) ); setresult( "waveform", signalIn.value.time, signalIn.value.amplitude, "time ( s )", "amplitude ( a.u. )" ); signalIn = getmonitorwaveform( "input", "frequency" ); logmessage( toscript( signalIn,false ) ); setresult( "spectrum", signalIn.value.frequency, signalIn.value.amplitude, "frequency ( Hz )", "amplitude ( a.u. )" );
It collects all the data at the input port, and sets the data to a result dataset so that it could be visualized.
Please check the links for the details of the script commands popportframe, logmessage, pushportframe, getmonitorwaveform and setresult.
Block Mode
The figure below shows the Block Mode electrical amplifier system in the example file. The output of the Ramp source is in block mode.
The "Scripted Gain" has the following script in the "Go" window under the "Simulation" tab.
signalIn = popportframe( "input" ); if( signalIn.valid ) { logmessage(toscript(signalIn)); for( i=1:length( signalIn.data.value ) ) { signalIn.data.value( i ) = 10 * signalIn.data.value( i ); } } pushportframe( "output", signalIn );
It reads in the electrical data from the buffer at the input port as a block, enlarges the amplitude of the signals by 10 times and pushes the data block to the output port.
The "Scripted Analyzer" is scripted the same way as the "Oscilloscope" and has the following script in the "Wrap-up" window under the "Simulation" tab.The definition is the same as in the Sample Mode.
signalIn = getmonitorwaveform( "input", "time", 3 ); logmessage( toscript( signalIn, false ) ); setresult( "waveform", signalIn.value.time, signalIn.value.amplitude, "time (s)", "amplitude (a.u.)" ); signalIn = getmonitorwaveform( "input", "frequency", 3 ); logmessage( toscript( signalIn, false ) ); setresult( "spectrum", signalIn.value.frequency, signalIn.value.amplitude, "frequency (Hz)", "amplitude (a.u.)" );
It collects all the data at the input port, and sets the data to a result dataset so that it could be visualized.
Please check the links for the details of the script commands popportframe, logmessage, pushportframe, getmonitorwaveform and setresult.
============================================
============================================
The file optical_mm_scripted_struct.icp contains two examples of an optical gain element, one for Sample Mode and the other for Block Mode.
Sample Mode
The figure below shows the Sample Mode gain element system in the example file. The output of the Optical Impulse source is in sample mode.
The "Scripted Gain" has the following script in the "Go" window under the "Simulation" tab.
signalIn = popportframe( "input" ); if( signalIn.valid ) { logmessage( toscript( signalIn ) ); nModes = length( signalIn.data.signal ); for( i = 1:nModes ) { nChannels = length( signalIn.data.signal{i}.channel ); for( j = 1:nChannels ) { signalIn.data.signal{i}.channel{j}.value = signalIn.data.signal{i}.channel{j}.value * 10.0; } } } pushportframe( "output", signalIn );
It reads in the optical data from the buffer at the input port, enlarges the amplitude of the signals by 10 times and pushes the data to the output port.
The "Scripted Analyzer" is scripted the same way as the "Optical Oscilloscope" and has the following script in the "Wrap-up" window under the "Simulation" tab.
signalIn = getmonitorwaveform( "input" ); logmessage( toscript( signalIn, false ) ); setresult( "mode 1", signalIn.signal{1}.channel{1}.value.time, signalIn.signal{1}.channel{1}.value.amplitude, "time (s)", "amplitude (a.u.)" ); setresult( "mode 2", signalIn.signal{2}.channel{1}.value.time, signalIn.signal{2}.channel{1}.value.amplitude, "time (s)", "amplitude (a.u.)" );
It collects all the optical data for different modes at the input port, and sets the data to a result dataset so that it could be visualized.
Please check the links for the details of the script commands popportframe, logmessage, pushportframe, getmonitorwaveform and setresult.
Block Mode
The figure below shows the Block Mode gain element system in the example file. The output of the Optical Impulse source is in block mode.
The "Scripted Gain" has the following script in the "Go" window under the "Simulation" tab.
signalIn = popportframe( "input" ); if( signalIn.valid ) { logmessage( toscript( signalIn ) ); for( i = 1:length( signalIn.data.signal ) ) { nChannels = length( signalIn.data.signal{i}.channel ); for( j = 1:nChannels ) { for( k=1:length( signalIn.data.signal{i}.channel{j}.value ) ) { signalIn.data.signal{i}.channel{j}.value(k) = 10.0 * signalIn.data.signal{i}.channel{j}.value(k); } } } } pushportframe( "output", signalIn );
It reads in the optical data from the buffer at the input port, enlarges the amplitude of the signals by 10 times and pushes the data to the output port.
The "Scripted Analyzer" is scripted the same way as the "Optical Oscilloscope" and has the following script in the "Wrap-up" window under the "Simulation" tab.
signalIn = getmonitorwaveform( "input" ); logmessage( toscript( signalIn, false ) ); setresult( "mode 1", signalIn.signal{1}.channel{1}.value.time, signalIn.signal{1}.channel{1}.value.amplitude, "time (s)", "amplitude (a.u.)" ); setresult( "mode 2", signalIn.signal{2}.channel{1}.value.time, signalIn.signal{2}.channel{1}.value.amplitude, "time (s)", "amplitude (a.u.)" );
It collects all the optical data for different modes at the input port, and sets the data to a result dataset so that it could be visualized.
Please check the links for the details of the script commands popportframe, logmessage, pushportframe, getmonitorwaveform and setresult.
============================================
============================================