Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

.SENS with bpwl

23 views
Skip to first unread message

zhengqi gao

unread,
Aug 8, 2024, 4:49:47 PM8/8/24
to xyce-users
Hi,

I am following our previous thread about sensitivity. I now use bpwl source to enable sensitivity calculation for piece wise linear signal. I gave a very simple netlist which essentially contains two separate circuits Part I and Part II, and the sensitivity results should be all zero because the BPWL source is in Part I and the V(2) is in Part I. 

However, when I run the netlist, Xyce raises errors 'Function or variable V1/V2/V3/V4 is not defined', also a warning on sensitivity parameter lacks an analytic derivative.

I believe I did something wrong, but I cannot figure it out. 

Thanks so much for your time and help. 

-Zhengqi


* part I
vin 1 0 0.1
c1  1 2 0.1
r1  2 0 0.1

* part II
r2 4 0 0.1
r3 4 5 0.1
r4 5 0 0.1

.subckt test n ground t1=-1 v1=-1 t2=-1 v2=-1 t3=-1 v3=-1 t4=-1 v4=-1
r1 n ground 1.0
c1 n ground 1.0
bpwl1 n ground v = {table(time,{t1},{v1},{t2},{v2},{t3},{v3},{t4},{v4})}
.ends test

x4 4 0 test t0={param_0} v0={param_1} t1={param_2} v1={param_3} t2={param_4} v2={param_5} t3={param_6} v3={param_7} t4={param_8} v4={param_9}

.tran 0 10ms
.options timeint reltol=1e-6 abstol=1e-6
.options sensitivity direct=1 adjoint=0

.PRINT TRAN v(2)
.sens objfunc={v(2)} param=v1,v2,v3,v4

.PARAM param_0=0.0
.PARAM param_1=0.5870777433531418
.PARAM param_2=0.001
.PARAM param_3=-0.8774518659205758
.PARAM param_4=0.002
.PARAM param_5=1.355372276552544
.PARAM param_6=0.003
.PARAM param_7=-1.72683365703545
.PARAM param_8=0.004
.PARAM param_9=-1.0777735783116316

Tom Russo

unread,
Aug 8, 2024, 5:01:32 PM8/8/24
to zhengqi gao, xyce-users
The problem here is that the "v1", "v2", "v3" etc. are only subcircuit dummy parameter names, not the names of the parameters you're passing in from the top level.  To get what you want you have to use the actual parameter names from the ".param" line, such as  "param_1", "param_3" etc.


.sens objfunc={v(2)} param=param_3,param_5,param_7,param_9

should do the trick.

Also, you're only doing a ".print trans" in your netlist, which won't include any sensitivity output.  Add ".print sens" to get that information.   This netlist works, and puts all the sensitivity output into a ".SENS.prn" file.   The sensitivity information is, as you expect all zero  because v(2) does not depend on any of the bpwl parameters:

* part I
vin 1 0 0.1
c1  1 2 0.1
r1  2 0 0.1

* part II
r2 4 0 0.1
r3 4 5 0.1
r4 5 0 0.1

.subckt test n ground t1=-1 v1=-1 t2=-1 v2=-1 t3=-1 v3=-1 t4=-1 v4=-1
r1 n ground 1.0
c1 n ground 1.0
bpwl1 n ground v = {table(time,{t1},{v1},{t2},{v2},{t3},{v3},{t4},{v4})}
.ends test

x4 4 0 test t0={param_0} v0={param_1} t1={param_2} v1={param_3} t2={param_4} v2={param_5} t3={param_6} v3={param_7} t4={param_8} v4={param_9}

.tran 0 10ms
.options timeint reltol=1e-6 abstol=1e-6
.options sensitivity direct=1 adjoint=0

.PRINT TRAN v(2)
.print sens
.sens objfunc={v(2)} param=param_3,param_5, param_7, param_9


.PARAM param_0=0.0
.PARAM param_1=0.5870777433531418
.PARAM param_2=0.001
.PARAM param_3=-0.8774518659205758
.PARAM param_4=0.002
.PARAM param_5=1.355372276552544
.PARAM param_6=0.003
.PARAM param_7=-1.72683365703545
.PARAM param_8=0.004
.PARAM param_9=-1.0777735783116316
--
You received this message because you are subscribed to the Google Groups "xyce-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xyce-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xyce-users/1a5bd60d-fbe4-44a4-8b10-f297517e1d23n%40googlegroups.com.


--
Tom Russo    KM5VY 
Tijeras, NM 

 echo "prpv_a'rfg_cnf_har_cvcr" | sed -e 's/_/ /g' | tr [a-m][n-z] [n-z][a-m]

Tom Russo

unread,
Aug 8, 2024, 5:20:04 PM8/8/24
to zhengqi gao, xyce-users
There are other issues with your netlist as written that are causing it to crash at about 1ms, and these are due to the 1 Farad capacitor you've got in your test subcircuit.  Turn that into a 1pf capacitor and the problems go away, and the sensitivities of v(4) or v(5) start to be reasonable and nonzero.

* part I

.PARAM param_0=0.0
.PARAM param_1=0.5870777433531418
.PARAM param_2=0.001
.PARAM param_3=-0.8774518659205758
.PARAM param_4=0.002
.PARAM param_5=1.355372276552544
.PARAM param_6=0.003
.PARAM param_7=-1.72683365703545
.PARAM param_8=0.004
.PARAM param_9=-1.0777735783116316

vin 1 0 0.1
c1 1 2 .1

r1  2 0 0.1

* part II
r2 4 0 0.1
r3 4 5 0.1
r4 5 0 0.1

.subckt test n ground t0=0 v0=1 t1=-1 v1=-1 t2=-1 v2=-1 t3=-1 v3=-1 t4=-1 v4=-1
r1 n ground 1.0
c1 n ground 1.0p
bpwl1 n ground v = {table(time,{t0},{v0},{t1},{v1},{t2},{v2},{t3},{v3},{t4},{v4})}

.ends test

x4 4 0 test t0={param_0} v0={param_1} t1={param_2} v1={param_3} t2={param_4} v2={param_5} t3={param_6} v3={param_7} t4={param_8} v4={param_9}

.tran 0 10ms
.options timeint reltol=1e-6 abstol=1e-6
.options sensitivity direct=1 adjoint=0

.PRINT TRAN v(1) v(2) v(4) V(5)
.print sens
.sens objfunc={v(5)} param=param_3,param_5, param_7, param_9

xyce-users

unread,
Aug 8, 2024, 5:23:02 PM8/8/24
to xyce-users
I agree with Tom.  At the top level of the netlist (which is the reference point for the "param=" statement on the .sens line), it will not understand the parameter names on the subcircuit definition line.  The same goes for .params defined inside a subcircuit; internally they are basically the same as the .params on the definition line. 

In principle, one *could* make it so that the "param=" statement on the .sens line would understand these, but they would need to be fully resolved to include the subcircuit name.   So, if that were to happen, the fully resolved parameter names for the x4 subcircuit instance would be things like param=x4:v1,x4:v2,x4:v3,x4:v4.

However, this currently isn't implemented in Xyce.  Historically, the only parameters that are allowed to vary during a simulation are parameters that are set in the top level of the netlist.  And, currently when doing sensitivities based on .param parameters, it is necessary to perform finite differences to obtain the device derivative.  ie, the "df/dp" term in the dO/dp = dO/dx * (df/dx)^-1 * df/dp chain rule.

To perform a finite difference derivative with respect to a .param, that param must be mutable, so currently this only applies at the top level of the netlist.

Interestingly, in some recent developments there have been some exceptions to this "top level only" rule.  That is for the case of global vs. local variation in random operators such as {agauss}.   To support that properly it was necessary to modify Xyce to allow (in the use case of sampling and/or other UQ methods) to allow subcircuit internal parameters to be mutable.   But, at the time that I did that work it didn't occur to me to apply this same exception to sensitivity analysis, so currently it doesn't do that.

By the way, in our local copy of Xyce I've fixed the issue that prevented .param-based direct sensitivities from working with VPWL sources.  So, that works now equivalently to using them with B-sources.  Whenever we do the next merge to the public repository you'll see that fix.   That fix was very simple, and just involved adding two lines of code to one function.  

I've also started to work on making .param-sensitivities work for transient adjoints, but that is a more involved fix, so it  won't be published right away.

thanks,
Eric
Reply all
Reply to author
Forward
0 new messages