Tagged: co-simulation, interconnect, python
-
-
June 16, 2021 at 9:33 pm
lipee36
SubscriberI have a question about co-simulating python with Interconnect. I've ran all the examples successfully, and I was able to reproduce simple scenarios based on them.
My question is regarding the capabilities of the co-simulation itself. What I am looking to do is to create a circuit on interconnect and execute it on a loop, using dynamic inputs generated by my python script. A very dummy example of this functionality:
June 17, 2021 at 1:05 amGuanhui Wang
Ansys EmployeeHi lipee36
Thank you for the post. I believe what you have described is possible using the Python API. Please check out this example here: https://support.lumerical.com/hc/en-us/articles/360034936773-Python-co-simulation-with-INTERCONNECT
June 18, 2021 at 5:54 pmlipee36
Subscriber
thank you very much for your suggestion. Indeed, I've tried to replicate this example. If I run the example, it returns an error (something like "co_simulation_example.icp could not be read" - although I can open the project and executes it from the interface, or using the .lsf script.
Anyhow, I've tried to adapt it to a very simple example, and yet I have errors:
inlumapi.evalScript(h,'''File "F:\Programs\Lumerical\api\python\lumapi.py", line 251, in evalScriptraise LumApiError("Failed to evaluate code")lumapi.LumApiError: 'Failed to evaluate code'
This is the simple circuit I am trying to use as example:
and this is the adapted script:
import sys, os, random, pdb
import numpy as np
os.add_dll_directory('F:\\Programs\\Lumerical\\api\\python')
sys.path.append("F:\\Programs\\Lumerical\\api\\python")
CWD = os.path.dirname(os.path.abspath(__file__)) ## No need to run this line if using python console
os.chdir("F:\\Programs\\Lumerical\\api\\python")
import lumapi
h = lumapi.open("interconnect", hide=True)
#####################################################
# Define user parameters
#
time_window = 5e-9
Nsamples = 8192
power_in_1 = 100
power_in_2 = 0
frequency_in = 1550
phase_in = 0
# end user parameters
#####################################################
# we must load the file after starting INTERCONNECT
lumapi.evalScript(h,''' load("MZI.icp"); ''');
# intialize simply by pushing data to Lumerical script workspace
lumapi.putDouble(h,"time_window",time_window);
lumapi.putDouble(h,"Nsamples",Nsamples);
lumapi.putDouble(h,"power_in_1",power_in_1);
lumapi.putDouble(h,"power_in_2",power_in_2);
lumapi.putDouble(h,"frequency_in",frequency_in);
lumapi.putDouble(h,"phase_in",phase_in);
lumapi.evalScript(h,'''
# turn off history and redrawing
redrawoff;
historyoff;
# time vectors
t = linspace(0,time_window,Nsamples+1);
t = t(1:end-1);
dt = t(2)-t(1);
# restore design mode in case we are in analysis mode
switchtodesign;
setnamed("::Root Element","time window",time_window);
setnamed("::Root Element","number of samples",Nsamples);
setnamed("CWL_1","power",power_in_1);
setnamed("CWL_1","frequency",frequency_in);
setnamed("CWL_2","power",power_in_2);
setnamed("CWL_2","frequency",frequency_in);
setnamed("MZI_1","phase_shift",phase_in);
# intialize the simulation
runinitialize;
# initialize struct used for passing co-sim data
v = struct;
# End initialization
#####################################################
''')
output = np.empty((314,2))
counter = 0
while [phase_in < 3.15]:
lumapi.evalScript(h,'''
#set parameters
setvalue("CWL_1","power",power_in_1);
setvalue("CWL_1","frequency",frequency_in);
setvalue("CWL_2","power",power_in_2);
setvalue("CWL_2","frequency",frequency_in);
setvalue("MZI_1","phase_shift",phase_in);
# run INTERCONNECT step
runstep;
# read signals from INTERCONNECT simulation
v.index = 1;
v1 = getvalue("COSIM_1","port",v);
v.index = 2;
v2 = getvalue("COSIM_1","port",v);
''');
output[counter][0] = lumapi.getVar(h,"v1")
output[counter][1] = lumapi.getVar(h,"v2")
phase_in = phase_in + 0.01
# run finalize of INTERCONNECT
lumapi.evalScript(h,"runfinalize;")
print(output)
lumapi.close(h)
The error I've mentioned before is due the line I've highlighted bold . Can you see any obvious mistake/problem?
Thanks again!
February 24, 2022 at 9:02 amliqiande
Subscriberõ¢áÕÑ¢´╝îµêæþø«Õë쵡úÕ£¿ÕüÜÞ┐ÖþºìÕÀÑõ¢£´╝îµêæÞâ¢Úù«õ¢áÕÉù´╝ƒ
Viewing 3 reply threads- You must be logged in to reply to this topic.
Ansys Innovation SpaceBoost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.
Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
Trending discussions- “Import optical generation” or “delta generation rate”?
- Why am I getting “process exited without calling finalize”, and how do I fix it?
- Error on Lumerical device
- Using a license file on a new license server
- Error: addfdtd is not a valid function or a variable name
- Ansys Insight: Diverging Simulations
- Ansys Insight: Transmission results greater than one
- Ansys Insight: About override mesh in FDTD: its use and settings
- Ansys Insight: Convergence issues in CHARGE
- Is there a Lumerical script command to output the Simulation and Memory requirements?
Top Contributors-
2706
-
2142
-
1355
-
1144
-
462
Top Rated Tags© 2023 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-