0% found this document useful (0 votes)
231 views50 pages

ADS and Python Integration Using Datalink

Uploaded by

BUNNGA SARITH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
231 views50 pages

ADS and Python Integration Using Datalink

Uploaded by

BUNNGA SARITH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 50

Advanced Design

System 2020

ADS and Python Integration


Using Datalink

PDF Generated on
Apr 07, 2019
Notices
© Keysight Technologies Incorporated, 2002-2019

1400 Fountaingrove Pkwy., Santa Rosa, CA 95403-1738, United States All rights reserved.

No part of this documentation may be reproduced in any form or by any means (including electronic storage
and retrieval or translation into a foreign language) without prior agreement and written consent from
Keysight Technologies, Inc. as governed by United States and international copyright laws.

Restricted Rights Legend


If software is for use in the performance of a U.S. Government prime contract or subcontract, Software is
delivered and licensed as "Commercial computer software" as defined in DFAR 252.227-7014 (June 1995),
or as a "commercial item" as defined in FAR 2.101(a) or as "Restricted computer software" as defined in
FAR 52.227-19 (June 1987) or any equivalent agency regulation or contract clause.

Use, duplication or disclosure of Software is subject to Keysight Technologies' standard commercial license
terms, and non-DOD Departments and Agencies of the U.S. Government will receive no greater than
Restricted Rights as defined in FAR 52.227-19(c)(1-2) (June 1987). U.S. Government users will receive no
greater than Limited Rights as defined in FAR 52.227-14 (June 1987) or DFAR 252.227-7015 (b)(2)
(November 1995), as applicable in any technical data.

Portions of this software are licensed by third parties including open source terms and conditions.

For detail information on third party licenses, see Notice.


ADS and Python Integration Using Datalink

Contents
ADS and Python Integration Using Datalink ................................................................................... 5
Contents.........................................................................................................................................6
Installing Datalink Add-on............................................................................................................... 7
Installing Datalink Add-on.............................................................................................................7
Install Datalink Add-on ............................................................................................................... 7
Configure User-Defined Script Location .................................................................................... 7
Uninstall Datalink Add-on .......................................................................................................... 7
Using Datalink.................................................................................................................................. 9
Using Datalink................................................................................................................................9
Adding Datalink Function in ADS ............................................................................................... 9
Sending Data From ADS to Python ............................................................................................ 9
Accessing ADS Data in Python ................................................................................................... 9
Accessing Python Data in ADS ................................................................................................. 10
Single Step ADS-Python Data Transfer.................................................................................... 10
Datalink Function Reference ......................................................................................................... 11
Datalink Function Reference .......................................................................................................11
Setup and Utility Functions ...................................................................................................... 11
Datalink Functions .................................................................................................................... 11
VISA Functions.......................................................................................................................... 11
LoadPull Functions ................................................................................................................... 12
Application Wrapper Functions ................................................................................................ 12
Datalink Functions .......................................................................................................................13
Datalink Functions .................................................................................................................... 13
dl_python() ................................................................................................................................ 14
dl_to_python() ........................................................................................................................... 18
dl_from_python()....................................................................................................................... 20
dl_python_bg() .......................................................................................................................... 22
dl_clean_dir() ............................................................................................................................ 27
VISA Functions.............................................................................................................................28
VISA Functions.......................................................................................................................... 28
dl_visa_list() .............................................................................................................................. 29

3
ADS and Python Integration Using Datalink

dl_visa_select().......................................................................................................................... 30
dl_visa_ping() ............................................................................................................................ 31
dl_visa_query() .......................................................................................................................... 32
dl_visa_query_data() ................................................................................................................. 33
dl_visa_write() ........................................................................................................................... 35
dl_string_to_data() .................................................................................................................... 36
LoadPull Functions ......................................................................................................................37
LoadPull Functions ................................................................................................................... 37
dl_create_contours() ................................................................................................................. 38
dl_assign_new_contour_levels()............................................................................................... 39
dl_deembed_s2p_from_z()........................................................................................................ 40
Application Wrapper Functions ...................................................................................................41
Application Wrapper Functions ................................................................................................ 41
dl_contour_py() ......................................................................................................................... 42
Datalink Examples ......................................................................................................................... 44
Datalink Examples .......................................................................................................................44
Example - Basic Datalink Operation............................................................................................45
Example - Basic Datalink Operation......................................................................................... 45
Example - 3D Surface Plot of an S-Parameter............................................................................47
Example - 3D Surface Plot of an S-Parameter......................................................................... 47

4
ADS and Python Integration Using Datalink

ADS and Python Integration Using Datalink


Keysight EEsof provides a way to access the data processing capabilities of Python from within ADS
using the Datalink feature. Datalink allows users to post-process simulation data using Python.
This is accomplished using functions which can be invoked from ADS Data Display, along with a
corresponding set of Python functions which facilitate easy data transfer in and out. A visual
overview of the ADS-Python datalink is shown below:

The following features are supported:


Send ADS-generated data to Python script
Read Python generated data in ADS
Call a Python Script from ADS, with optional data send and data read

In addition, ADS functions are provided which utilize the Python interface to:
Communicate with instruments through VISA
Generate advanced plots
Generate advanced contours
Import arbitrary delimited data into ADS

To install files that are required for the Datalink functionality you need to download a separate Datalink
installer datalink_20xx.exe (for Windows only). For Linux, the Datalink installer is bundled with ADS
installer.
It is recommended to download both the general ADS installer, ads20xx_shp.exe, and the
datalink installer, datalink_20xx.exe, into the same directory. After the download, run the ADS
installer. This process will automatically install the Datalink functionality.
On Windows platform, if you have already installed ADS and find Datalink functionality missing,
then you need to download and install Datalink. For instructions, see Installing Datalink Add-on.

5
ADS and Python Integration Using Datalink

Contents
Installing Datalink Add-on
Using Datalink
Datalink Function Reference
Datalink Examples

Related Topics:
Workflow: How to Use Datalink with ADS

6
ADS and Python Integration Using Datalink

Installing Datalink Add-on

Installing Datalink Add-on


This section describes information on installing and Uninstalling Datalink Add-on for Advanced
Design System (ADS) on Windows. For Linux, the Datalink installer is bundled with ADS installer.

Install Datalink Add-on

To install files that are required for the Datalink functionality you need to download a separate Datalink
installer datalink_20xx.exe (for Windows only). For Linux, the Datalink installer is bundled with ADS
installer.
It is recommended to download both the general ADS installer, ads20xx_shp.exe, and the
datalink installer, datalink_20xx.exe, into the same directory. After the download, run the ADS
installer. This process will automatically install the Datalink functionality.
On Windows platform, if you have already installed ADS and find Datalink functionality missing,
then you need to download and install Datalink. For instructions, see Installing Datalink Add-on.

1. Download the installation file, datalink_20xx.exe, from the Keysight EEsof EDA website to any
folder, for example C:\Temp.
2. Install the Add-on.
a. Double-click the installation file.
b. Follow the wizard.
Datalink is installed and configured.

Configure User-Defined Script Location


By default, Datalink looks for the Python scripts under the <Workspace_DIR> directory. There are
cases where the required script is present in a different location.
1. Edit the hpeesofdss.cfg file present in <HPEESOF_DIR>/config directory.
2. Update DATALINK_PYTHON_SCRIPT_DIR variable and specify a semicolon-delimited list of custom
locations.
3. Restart ADS.

Even if the script is called from a different location, the data generated is stored in the current
workspace.

Uninstall Datalink Add-on


Datalink Add-on can be uninstalled using any of the options:
Uninstall ADS, the Datalink add-on is also uninstalled.
or

7
ADS and Python Integration Using Datalink

Click Start > Control Panel > Program and Features, select DATALINK for Advanced Design System
20xx and click Uninstall/Change. This will uninstall only the Datalink Add-on.

8
ADS and Python Integration Using Datalink

Using Datalink

Using Datalink
Adding Datalink Function in ADS
Sending Data From ADS to Python
Accessing ADS Data in Python
Accessing Python Data in ADS
Single Step ADS-Python Data Transfer

Adding Datalink Function in ADS


1. Do one of the following:
In Data Display, click the Equation button from the palette or choose Insert > Equation.
For more information on adding equations in Data Display, see Equations.
In the Schematic window, click MeasEqn (Measurement Equations) component and place it on the
schematic.
For more information on adding measurement equations, see Measurement Equations.
The use of Datalink functions within a measurement equations will increase simulation time.

2. Enter the DataLink function.

Sending Data From ADS to Python


Use the to_python() function to send the ADS data to Python.
1. Create Datalink equation. See Adding Datalink Function in Data Display.
2. Create an equation to call dl_to_python() function and pass the Dataset name and variable.
For example, OutFile=dl_to_python(V,current.i)
Following files are created in the <Workspace_DIR>/data/python directory:
Data file, ADS2Pyth_oneway.d.
Pointer file, ads.dat, for Python to access the data.

Accessing ADS Data in Python


You can create a Python script to access the data from ADS.
1. Click Tools > Spyder to launch the Spyder App.
2. Create a new Python script under the <Workspace_DIR>/data/python directory.
Following is an example script,

9
ADS and Python Integration Using Datalink

import ads # import the datalink Python library


d,s=ads.get # import ADS data (d) and strings (s)
a=d*2 # perform some processing on ADS data
ads.send(a) # write the the processed data to the specified
file

3. Click Run.
The output file is created with the name specified in the script.

Spyder application menu bar becomes inactive when the window is maximized using View > Full
Screen or by pressing F11 (shortcut key to maximize the screen). As a workaround Press F11 again to
make it as the default screen. The menu bar is now active and works fine.

Accessing Python Data in ADS


Use the from_python() function to get the processed data from Python to ADS.
1. Create Datalink equation. See Adding Datalink Function in Data Display.
2. Create an equation to call dl_from_python() function and pass the Python script name, Dataset
name, and variable.
For example, MyData=dl_from_python("MyData.csv")
3. Display the data using the List option in Data Display.
For example,

Single Step ADS-Python Data Transfer


You can transfer data from ADS to Python, process it, and return it back to ADS using the following
method.
1. Create Datalink equation. See Adding Datalink Function in Data Display.
2. Create an equation to call dl_dython() function and pass the Python script name, Dataset name, and
variable.
For example, Data=dl_python("Myscrypt_IO.py",V,current.i)
3. Display the data using the List option in Data Display.
For example,

See Also

Workflow: How to Use Datalink with ADS

10
ADS and Python Integration Using Datalink

Datalink Function Reference

Datalink Function Reference


Setup and Utility Functions
Datalink Functions
VISA Functions
LoadPull Functions
Application Wrapper Functions

Setup and Utility Functions


Name Description Input Output

dl_datalink() Get the list of datalink functions. None String which lists datalink
functions

dl_datalink_test() Check if datalink is properly installed. None Test results string

dl_get_py_executable() Return the Python path configured for None Path to Python exe
datalink.

Datalink Functions
Name Description

dl_python() Invoke a Python script from ADS. Using this function you can export data, find Python script,
run the script, and import the data.

dl_python_bg() Invoke a Python script from ADS in the background mode. Use this function to export data
from ADS, find the Python script, and run the script.

dl_to_python() Export ADS data and create a Python pointer.

dl_from_python() Import a CSV data file from Python to ADS.

VISA Functions
Name Description

dl_visa_list() Get a list of instruments on VISA line.

dl_visa_select() Selecta VISA instrument.

dl_visa_ping() Check if the instrument is responding.

11
ADS and Python Integration Using Datalink

Name Description

dl_visa_query() Query a VISA instrument.

dl_visa_query_data() Query ASCII or Binary Data.

dl_visa_write() Write a series of VISA commands.

dl_string_to_data() Convert a delimited string to data.

LoadPull Functions
Name Description

dl_create_contours() Create ADS contours from Python data.

dl_assign_new_contour_leve Assigns new arbitrary contour levels to an existing set of contours.


ls()

dl_deembed_s2p_from_z() De-embed s2p data from LoadPull contours.

Application Wrapper Functions


Name Description

dl_contour_py() Use Python to create contours.

12
ADS and Python Integration Using Datalink

Datalink Functions

Datalink Functions
dl_python() — Invoke a Python script from ADS. Use this function to export data
from ADS, find and run a Python script, and import the data back in ADS. Additional
dl_to_python() — Export ADS data and create a Python pointer. Resources
dl_from_python() — Import a CSV data file from Python to ADS.
dl_python_bg() — Invoke a Python script from ADS in the background mode.
Use this function to export data from ADS, find the Python script, and run the What's
script. New
dl_clean_dir() — Removes all the temporary .csv files created by datalink.

Articles

Knowledge
Center

Technical
Support
Contact

Training

Videos

13
ADS and Python Integration Using Datalink

dl_python()

dl_python()
Invoke a Python script from ADS. Use this function to export data from ADS, find and run a Python
script, and import the data back in ADS.

If you want to run the script in the background, use dl_python_bg().

Syntax

dl_python(script_name, <options>, <data>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Default Type Required

script_name Name of the python script to run. Script name or full file None String Yes
path. If the input is a filename and it does not exist in
the current directory, the following directories are
searched:
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPTS_DIR
if /data/python doesn't exist, the function creates it.

14
ADS and Python Integration Using Datalink

Name Description Default Type Required

<options> The following options can be put in a single string and None String No
must be the first input to the python() function directly
after the Python script name
"rowformat”: always write 1D variables as a single
row regardless of size.
“columnformat”: always write 1D variables as a
single column regardless of size.
The rowformat or columnformat
option does not apply if data is
passed using “list(<tablename>)”.
“keepfiles”: do not delete any data files
fromdirectoryincluding ADS2Pyth_datecode.csv,
Pyth2ADS_datecode.csv, ADS2Pyth_oneway.d,
ADS2Pyth_oneway.s.
"ignoreconsole": the python script typically prints
only a file path to the console (this is thecsvfile for
the return data). If the script prints other things,
ADS assumes that its likely an error so it returns the
full console output instead of the python data. This
option overrides that, it searches the python output
for a valid file path (Pyth2ADS_Datecode.csv) and
returns the data from that file regardless of
whatever else is printed to the console.
“scriptdir”: don’t execute, instead return the
directory location of the python script.
"datadir": don’t execute, instead return the
directory location of the data.
“pydir”: don’t execute, instead return the directory
location of the python executable.
“__dir”: don’t execute, instead return script dir, data
dir, and python dir.

15
ADS and Python Integration Using Datalink

Name Description Default Type Required

<data> Up to 50 ADS vars, separated by commas. None String No


If the data is ADS variables, the function creates
two csv files in /data/python called
ADS2Pyth_oneway.d, ADS2Pyth_oneway.s. It
removes any files with the name
ADS2Pyth_datecode.csv and
Pyth2ADS_datecode.csv which were likely left
in the directory due to a prior incomplete
datalink invocation. It also creates a pointer file,
ads.dat, which resides in the directory of the
Python script so that the python script can point
back to the location of the data. The pointer
contains the location of the Workspace_DIR/
data/python directory.
supported data: swept_mdim, swept_matrix,
1D_arr, single_value…(real, complex, string)
arrays can be irregular
for 1D arrays, if less than 1000 data points,
write to a single row
for more than 1000 data points, write to a
single column
for Multidimensional variables, write a single
zero after the variable
After the function completes,
ADS2Pyth_datecode.csv is copied to
ADS2Pyth_oneway.d and string inputs are
saved to ADS2Pyth_oneway.s. Then,
ADS2Pyth_datecode.csv and
Pyth2ADS_datecode.csv are deleted.
“list(tablename)”: Instead of exporting individual
variables, export an entire DDS table listing,
creating one file in /data/python:
ADS2Pyth_oneway.d. This input must come
directly after the python script name.
tablename must be a valid title of a table in
data display
only one table per call, cannot be combined
with ADS variables to output
All other subsequent ADS variables or
listings passed in are ignored.
In Python, the D variable will contain the
data, the S variable will contain var names
the file generated is the same as right
clicking on a table and selecting “export”

Output
If the Python script returned only the path of a data file: Pyth2ADS_Datecode.csv, the function reads
the data in the file and return it as a multi-dimensional variable indexed as [Row,Col].
For numerical data, complex data is always returned. To convert it to real or integer numbers, use the
AEL functions real() or integer() functions on the result.
<inf> and <NaN>numpyvalues ARE supported in ADS2017 but not ADS2016
Irregular return data is supported (rows with different # of columns)
If the data is not numerical, strings are instead returned as [Row,Col]
If the Python script returned anything besides a single file path, the Python console output is returned
to ADS as a string. (This can be overridden with the “ignoreconsole” flag).

16
ADS and Python Integration Using Datalink

If the python script ran but returned nothing, it returns a message string: “no data returned”
If “dir” options were passed in, return directory location string(s)

In case of an error:
if python script is not found, returns a list of all directories searched.
if “list()” option invoked without a valid list, returns an error.

Example

rtn=dl_python("multiply_by_three.py",V,current.i)

The content of the script:

multiply_by_three.py

import ads # import ads library


d,s=ads.get() # get data from ADS
A=d*3 # multiply by 3
ads.send(A) # send data to ADS

17
ADS and Python Integration Using Datalink

dl_to_python()

dl_to_python()
Export ADS data and create a Python pointer.

Syntax

dl_to_python(<location>,<options>,<data>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Default Type Required

<location> Valid path string to an existing directory: None String No


Pointer file (ads.dat) created in file path
location which points to /data/python
python script name:
checks the following file locations for script:
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPT_DIR
Pointer file (ads.dat) created in file path
location which points to /data/python

<options> “columnformat”: always write 1D variables as a None String No


single column regardless of size.
“rowformat”: always write 1D variables as a single
row regardless of size.
The rowformat or columnformat
option does not apply if data is
passed using “list(<tablename>)”.

18
ADS and Python Integration Using Datalink

Name Description Default Type Required

<data> Up to 50 ADS variables, separated by commas: None String No


supported data types: swept_mdim,
swept_matrix, matrix, 1D_array, single_value
the format of data type can be real, integer,
complex, or string
for 1D arrays, if less than 1000 data
points, write to a single row.
for more than 1000 data points, write to
a single column.
for Multidimensional variables, write a
single zero after the variable
Multi-dimensional variables can be
irregular
creates/overwrites 2csvfiles in /data/python
(ADS2Pyth_oneway.d,.s)
if /data/python doesn't exist, the
function creates it
“list(tablename)”: instead of exporting individual
variables, export an entire DDS table listing,
creating one file: ADS2Pyth_oneway.d. Only a
single table is allowed.
table name must be a valid title of a table in
DDS.
only one table allowed per call, cannot be
combined with ADS variables to output.
If this input is combined with more data
vars, it will export a text string not a table.

Output

Data File location, pointer location as a string

In case of an error:
if python script not found, data is put in the default directory and an error message is displayed
If invalid directory is provided for location, data is put in default directory (invalid path treated as string
to export to python)
if “list()” option invoked without a valid list, returns an error message

Example

OutFile=dl_to_python(V,current.i)

19
ADS and Python Integration Using Datalink

dl_from_python()

dl_from_python()
Import a CSV data file from Python to ADS.

Syntax

dl_from_python(Dir_or_PyScript_or_Fname, <options>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Defa Typ Requir


ult e ed

Dir_or_PyScrip Represents how to get the data. This should be either a directory, a Non Stri No
t_or_Fname python script name, or a filename / filepath. e ng
full file path and file name: returns data from the file
file path only: returns data from most recent
Pyth2ADS_datecode.csv in the specified directory
filename.csv: checks the following locations for file and return
data from the file
current dir
_wrk/data/python
_wrk/data; _wrk
$DATALINK_PYTHON_SCRIPT_DIR
python script: checks the following locations for the script
and returns data from most recent Pyth2ADS_datecode.csv in
that location
curr_dir
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPT_DIR

<options> The following inputs are valid for this variable (must come after Non Stri No
filename_or_loc) e ng
showloc: returns path location of python script or csv file

If the string is a directory path, the function will search that location for files that were exported by
Python.These files are named Pyth2ADS_YMDHMS.csv. The function will find the last data export and
return that data to ADS.
If the string is a Python script, the function will search the directory where the script is located. If the
Python script is not specified with a full path, the function will search for the script in the following
order: workspace\data\python, workspace\data, workspace(_wrk), then

20
ADS and Python Integration Using Datalink

$HPEESOF_DIR\config\hpeesofdss.cfg: $DATALINK_PYTHON_SCRIPT_DIR. Once the path of the


python script is found, that directory will be used to import data as described above.
If the string is a valid filename, the function will import that file into ADS. If the string is not a full path,
then the function will search for it in the following order: current directory (workspace),
workspace\data\python. Once the file is found, it will be imported as a .csv file, regardless if it has
a .csv extension or not.
If no path is passed, the function will search for the file \"Pyth2ADS_oneway.d\" in the
workspace\data\python directory. If it does not exist, the function will search for the file \"ads.dat\"
and use the data path specified in that file. Once the path is found, it will be used to import data as
described above.

Output

ADS MDIM array [Row,Col] data exported from python function ads.send(): complex number Python
arrays or strings

In case of an error:
if directory or file is not valid or does not exist, returns an error message
if python script or csv file not found, returns an error message showing all dirs searched
if no Pyth2ADS_datecode files found, returns an error message showing location checked
if return data is not numeric or read as data, returns data as strings

Example

MyData=dl_from_python("MyData.csv")

21
ADS and Python Integration Using Datalink

dl_python_bg()

dl_python_bg()
Invoke a Python script from ADS in the background mode. Use this function to export data from
ADS, find the Python script, and run the script.

This function does not return the data to ADS. To return data back to ADS use dl_python().

Syntax

dl_python_bg(script_name, <options>, <data>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Default Type Required

script_name Name of the python script to run. Script name or full file None String Yes
path. If the input is a filename and it does not exist in
the current directory, the following directories are
searched:
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPT_DIR
if /data/python doesn't exist, the function creates it.

22
ADS and Python Integration Using Datalink

Name Description Default Type Required

<options> The following options can be put in a single string and None String No
must be the first input to the python() function directly
after the Python script name
"rowformat”: always write 1D variables as a single
row regardless of size
“columnformat”: always write 1D variables as a
single column regardless of size
The rowformat or columnformat
option does not apply if data is
passed using "list(<tablename>)".
“scriptdir”: don’t execute, instead return the
directory location of the python script
"datadir": don’t execute, instead return the
directory location of the data
“pydir”: don’t execute, instead return the directory
location of the python executable
“__dir”: don’t execute, instead return script dir, data
dir, and python dir

23
ADS and Python Integration Using Datalink

Name Description Default Type Required

<data> Up to 50 ADS vars, separated by commas. None String No


If the data is ADS variables, the function creates
two csv files in /data/python called,
ADS2Pyth_oneway.d, ADS2Pyth_oneway.s. It
removes any file with the
name ADS2Pyth_datecode.csv which was
likely left in the directory due to a prior
incomplete datalink invocation.
It also creates a pointer file, ads.dat, which
resides in the directory of the Python script so
that the python script can point back to the
location of the data. The pointer contains the
location of the Workspace_DIR/data/
python directory.
supported data: swept_mdim, swept_matrix,
1D_arr, single_value…(real, complex, string)
arrays can be irregular
for 1D arrays, if less than 1000 data points,
write to a single row
for more than 1000 data points, write to a
single column
for Multidimensional variables, write a single
zero after the variable
Before executing the python
script, ADS2Pyth_datecode.csv is copied
to ADS2Pyth_oneway.d and
ADS2Pyth_datecode.csv is deleted. The string
inputs are saved to ADS2Pyth_oneway.s.
“list(tablename)”: Instead of exporting individual
variables, export an entire DDS table listing,
creating one file in /data/
python: ADS2Pyth_oneway.d. This input must
come directly after the python script name.
tablename must be a valid title of a table in
data display
only one table per call, cannot be combined
with ADS variables to output
All other subsequent ADS variables or
listings passed in are ignored.
In Python, the D variable will contain the
data, the S variable will contain var names
the file generated is the same as right
clicking on a table and selecting “export”

Output

No data is returned.

Example
rtn=dl_python_bg("surface.py",dB(S11))

The content of the script:

24
ADS and Python Integration Using Datalink

surface.py

import ads
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D

d,s=ads.get()
d = np.real(np.delete(d, (d.shape[0]-1), axis=0)) #Delete the last row

#Regrid the data, using uniformly spaced X and Y matricies


Ax = np.linspace(d[::,0].min(),d[::,0].max(),300)
Ay = np.linspace(d[::,1].min(),d[::,1].max(),300)

#Create 2D meshed XY data arrays necessary for 3D Plotting


xgrid, ygrid = np.meshgrid(Ax, Ay)

#Interpolate Z-data onto the uniform XY grid using a cubic interpolation function
zgrid= griddata((d[::,0],d[::,1]),d[::,2], (xgrid,
ygrid),method='cubic',fill_value=0,rescale=True)

#Set up, generate, and pop up the plot


ax1 = Axes3D(plt.figure(1))
ax1.view_init(30, 240)
surf=ax1.plot_surface(xgrid,ygrid,zgrid,cmap=plt.cm.terrain)
ax1.set_title('Surface Plot dB(S11)')
ax1.set_xlabel('Vdd')
ax1.set_ylabel('freq')
ax1.set_zlabel('dB(S11)')
plt.show()

3D Image

25
ADS and Python Integration Using Datalink

26
ADS and Python Integration Using Datalink

dl_clean_dir()

dl_clean_dir()
Removes all the temporary .csv files created by datalink.

Syntax

dl_clean_dir(<directoryName>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Defa Typ Requir


ult e ed

<directoryNam The directory from which to remove the temporary .csv files created by _wrk Stri No
e> datalink. \dat ng
a\py
If an invalid directory is specified, an error message is returned. thon
If no directory is specified, the default directory name is:
_wrk\data\python.

Example
rtn=dl_clean_dir("C:\Users\aakotkar\Desktop\DataLink")

27
ADS and Python Integration Using Datalink

VISA Functions

VISA Functions
dl_visa_list() — Get a list of instruments on VISA line.
dl_visa_select() — Select a VISA instrument.
dl_visa_ping() — Check if the instrument is responding.
dl_visa_query() — Query a VISA instrument.
dl_visa_query_data() — Query ASCII or Binary Data.
dl_visa_write() — Write a series of VISA commands to the specified instrument.
dl_string_to_data() — Convert a delimited string to data.

28
ADS and Python Integration Using Datalink

dl_visa_list()

dl_visa_list()
Get a list of instruments on VISA line.

Syntax

dl_visa_list()

Output

The list of instruments on visa line.

29
ADS and Python Integration Using Datalink

dl_visa_select()

dl_visa_select()
Select a VISA instrument.

Syntax

dl_visa_select(index)

Arguments

Name Description Default Type Required

index Instrument index. None Integer Yes

Output

Instrument address string.

30
ADS and Python Integration Using Datalink

dl_visa_ping()

dl_visa_ping()
Check if the instrument is responding.

Syntax

dl_visa_ping(index)

Arguments

Name Description Default Type Required

index Instrument index. None Integer Yes

Output
1: the instrument is responding.
0: the instrument is not responding.

31
ADS and Python Integration Using Datalink

dl_visa_query()

dl_visa_query()
Query a VISA instrument.

Syntax

dl_visa_query(instrument_id, <query>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Default Type Required

instrument_id The instrument address (string) or instrument None String/Int Yes


index (integer).

<query> The query command. *IDN? String No

Output

String result of the query

In case of an error: An error message string is returned if the instrument is not responding.

32
ADS and Python Integration Using Datalink

dl_visa_query_data()

dl_visa_query_data()
Query ASCII or Binary Data.

Syntax

dl_visa_query_data(instrument_id, scpi_cmd, <ascii_or_bin?


>,<bin_datatype>,<bin_endian?>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Def Typ Req


aul e uire
t d

instrume The instrument address (string) or instrument index (integer). No Stri Yes
nt_id ne ng/
Int

scpi_cmd SCPI command which queries the data return. No Stri Yes
Upon invocation, the function checks for instrument responsiveness sends the ne ng
query command, and the data from the instrument is written in a temporary
delimited text file (for capacity). This file is then read for the output and deleted.

<ascii_or instrument data format specification asc Stri No


_bin?> ii ng
int 0 (ascii); int 1 (binary)
accepts “ASCII”,“ascii”,”a”,”asc”; “binary”,”bin”,”b”,”Binary”,”BIN” for
binary

<bin_dat Specify the binary datatype. do Stri No


atype> ubl ng
String or characters: “f”=float, “d”=double, based on the py visa datatype values e

<bin_endi Specify if binary is big-endian? Tru Stri No


an?> String “T”,”true”,”True”,”TRUE” or “f”,”F”,”false”, ”False”,”FALSE” e ng

Output

A single string containing all the data from the instrument.

In case of an error:

33
ADS and Python Integration Using Datalink

An error message is returned if the instrument is not responding.


An error message is returned if data format (ascii_or_bin) appears incorrect.
An error message is returned if an invalid command or no data is returned.

34
ADS and Python Integration Using Datalink

dl_visa_write()

dl_visa_write()
Write a series of VISA commands to the specified instrument.

Syntax

dl_visa_write(instrument_id,<write_string>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Def Typ Req


aul e uire
t d

instrume The instrument address (string) or instrument index (integer). No Stri Yes
nt_id ne ng/
Int

<write_st A string of SCPI command(s), delimited by ‘;’ to write to the instrument. No Stri No
ring> ne ng
Upon invocation, the function checks if the instrument is responsive and sends
each write command. If the final command is not a query (ending in “?”), then
the *OPC? (operation complete) query is appended to the string so the
instrument returns 1 when complete.

Output

A single string containing return data from the instrument, usually 1 from the *OPC? Cmd

In case of an error:
An error message is returned if the instrument is not responding.
No data is returned if the query command is invalid.

35
ADS and Python Integration Using Datalink

dl_string_to_data()

dl_string_to_data()
Convert a delimited string to data.

Syntax

dl_string_to_data(string,<delimiter>,<leftsnip>,<rightsnip>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Def Typ Req


aul e uire
t d

string A single string containing some type of delimited, real or floating. No Stri Yes
ne ng

<delimite A single character specifying the delimiter. , Stri No


r> ng

<leftsnip The number of characters to remove from the beginning before conversion. No Int No
> ne

<rightsni The number of characters to remove from the end before conversion. No Int No
p> ne

Output

A single-dimensional floating point, indexed numeric array.

In case of an error: An error message string is returned if the conversion fails.

36
ADS and Python Integration Using Datalink

LoadPull Functions

LoadPull Functions
dl_create_contours() — Create ADS contours from Python data.
dl_assign_new_contour_levels() — Assigns new arbitrary contour levels to an existing set of contours.
dl_deembed_s2p_from_z() — Removes (de-embeds) a 2x2 S-matrix from an arbitrary set of impedances.

37
ADS and Python Integration Using Datalink

dl_create_contours()

dl_create_contours()
Create ADS contours from Python data.

Syntax

dl_create_contours(python_contour_data, <dtype?>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Default Type Required

python_contour_da Return data from Python in the format: None Srting Yes
ta Level, Segment \n Real contour Zvalues \n
Imag contour Zvalues \n Level, Segment
\n…
Real and imaginary values are comma
delimited and returned using
Send_Contours_to_ADS()
Level, Segment \n X Values \n Y Values \n
Level, Segment \n…

<dtype?> If 0, contour data is assumed to be 0 Int No


complex: row of real, row of imaginary, etc.
If 1, contour data is assumed to be
rectangular: row of X, row of Y, etc.

Output

Multidimensional variable: Contours[level, segment, index]

Example

dl_create_contours(python_contour_data, 0)

38
ADS and Python Integration Using Datalink

dl_assign_new_contour_levels()

dl_assign_new_contour_levels()
Assigns new arbitrary contour levels to an existing set of contours.

Syntax

dl_assign_new_contour_levels(contour_array,new_levels)

Arguments

All strings must be enclosed in quotes.

Name Description Def Ty Req


aul p uire
t e d

contou An array of contours in ADS (typically with dependency contour[level,segment,index]) No St Yes


r_array ne ri
n
g

new_le 1D real array with new levels corresponding to the contour array. The number of No St Yes
vels elements must be the same as the number of unique levels in contour_array. ne ri
n
g

Output

A contour array with updated levels for each contour.

39
ADS and Python Integration Using Datalink

dl_deembed_s2p_from_z()

dl_deembed_s2p_from_z()
Removes (de-embeds) a 2x2 S-matrix from an arbitrary set of impedances.

Syntax

dl_deembed_s2p_from_z(Sremove,Sembed,fr_q,Z_0_0)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description Default Type Required

Sremove 2 port S-matrix to remove. Can be swept frequency. Must None String Yes
be 2x2.

Sembed Complex gamma to de-embed. None String Yes

fre_q the frequency to de-embed. For cases where Sremove is None String Yes
swept frequency, fr_q must be a frequency point in the S-
matrix.

Z_0_0 System/port impedance of the network to de-embed. None String Yes

Output

A de-embedded version of Sembed.

40
ADS and Python Integration Using Datalink

Application Wrapper Functions

Application Wrapper Functions


dl_contour_py() — Use Python to create contours.

41
ADS and Python Integration Using Datalink

dl_contour_py()

dl_contour_py()
Use Python to create contours.

Syntax

dl_contour_py(swept_data,<gamma>,<rect_or_polar>,<step_size>,<num_lines>,<desired
_levels>,<interp_type>,<min_or_max>,<data_format>)

Arguments

Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.

Name Description D Ty Re
ef pe qui
au red
lt

swept_ 1D or Swept variable. For swept variables,at least 2 independent sweeps should be N Yes
data done: what(data)=[Y,X]. The dependant (data) will be contoured vs. the independents o
(Y and X). n
For complex variable sweeps of impedance or gamma, order is [Imag Part, e
Real Part], or [Phase, Mag].
For complex variable sweeps, it is also possible to pass in separate complex
values using <gamma>.
In that case, only the dependant part of (data) will be used, and all
independent values is ignored.

<gamm 1D or Swept variable, in a complex format, corresponding to the XY values for the N Co No
a> (data) input. o m
If a swept variable is passed, only inner dependent values will be used, n ple
independent values ignored. e x
If <rect_or_polar> is set to POLAR, the Phase will be used as Y and Mag will be
X (useful for loadpull).
If <rect_or_polar> is set to RECT, the Imaginary Part will be used as Y and Real
Part will be X.

<rect_o Either POLAR or RECT. Forloadpull applications, POLAR is recommended. N Str No


r_polar o ing
> n
e

<step_ Represents step size between contour lines. N Re No


size> o al
n or
e Int

42
ADS and Python Integration Using Datalink

Name Description D Ty Re
ef pe qui
au red
lt

<num_l Represents number of contour lines requested. N Int No


ines> o
n
e

<desire Single value or array representing specific desired contour levels. N Int No
d_level o
s> n
e

<interp 0=linear,1=nearest,2=cubic, representing interpolation type. N Int No


_type> o
n
e

<min_o 0 (Min) or 1 (Max), that specifies whether the contours are to be drawn from the N Int No
r_max> maximum value down or from the minimum value up. o
n
e

<data_f Either RI or MA specifying data format for the polar contour plot, in polar mode only. N Str No
ormat> When <gamma> is passed in outside of the data sweep, data_format is not used. o ing
n
e

Example

Rn=dl_contour_py(Results1,Load_Gammas,"POLAR",3,10,,2)

43
ADS and Python Integration Using Datalink

Datalink Examples

Datalink Examples
Example - Basic Datalink Operation
Example - 3D Surface Plot of an S-Parameter

44
ADS and Python Integration Using Datalink

Example - Basic Datalink Operation

Example - Basic Datalink Operation


This example illustrates the basic operation using Datalink. In this example, data from a simulation
is sent to python, processed in a python script, and returned to ADS.
The following schematic is used to generate simulation data.

Following simulation data is generated:

The Python script (multiply_by_two.py) with following contents is present in the


<Wrk_Dir>\data\python directory.

multiply_by_two.py

import ads #import ads library


d,s=ads.get() #get data from ADS
a=d*2 #multiply ADS data by 2
ads.send(a) #send data to ads

Stepped Process
1. Open Data Display.

45
ADS and Python Integration Using Datalink

2. Export simulation data to python. Use following equation:


send=dl_to_python(V,current.i)
3. Process data in Python.
run=dl_python("multiply_by_two.py")
4. Get processed data from Python.
get_data=dl_from_python()
5. Display data in Data Display.

Results:

Alternative Approach: Single Step Process


The above approach requires three steps to perform the complete process. Datalink provides an
alternative method to perform the communication with Python as a single step. The following single
Datalink function call can replace the three calls used to send data, process data, and get data.

rtn=dl_python("multiply_by_two.py",V,current.i)

46
ADS and Python Integration Using Datalink

Example - 3D Surface Plot of an S-Parameter

Example - 3D Surface Plot of an S-Parameter


This example illustrates the generation of a 3D surface plot of an S-Parameter using Datalink.
Following schematic is used to generate simulation data.

The Python script (surface.py) with following contents is present in the <Wrk_Dir>\data\python
directory.

47
ADS and Python Integration Using Datalink

multiply_by_two.py

import ads
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D

d,s=ads.get()
d = np.real(np.delete(d, (d.shape[0]-1), axis=0)) #Delete the last row

#Regrid the data, using uniformly spaced X and Y matricies


Ax = np.linspace(d[::,0].min(),d[::,0].max(),300)
Ay = np.linspace(d[::,1].min(),d[::,1].max(),300)

#Create 2D meshed XY data arrays necessary for 3D Plotting


xgrid, ygrid = np.meshgrid(Ax, Ay)

#Interpolate Z-data onto the uniform XY grid using a cubic interpolation


function
zgrid= griddata((d[::,0],d[::,1]),d[::,2], (xgrid,
ygrid),method='cubic',fill_value=0,rescale=True)

#Set up, generate, and pop up the plot


ax1 = Axes3D(plt.figure(1))
ax1.view_init(30, 240)
surf=ax1.plot_surface(xgrid,ygrid,zgrid,cmap=plt.cm.terrain)
plt.show()

Standard Data Display plots

48
ADS and Python Integration Using Datalink

The Data Display will not be accessible while any of the 3D plot windows are open. You can access DDS
after closing the plot window. To make Data Display accessible while a 3D plot window is open, use the
dl_python_bg() function.

To generate 3D Surface Plots


1. Generate the 3D plot using the custom script (surface.py).
2. Add the following equation.
rtn=dl_python("surface.py",dB(S11))
Following is the generated 3D plot:

This example uses dB(S11), any sweep parameter can be used.

49
This information is subject to
change without notice.

www.keysight.com

You might also like