multi-parameter sweep

126 views
Skip to first unread message

Fede

unread,
Sep 9, 2017, 4:15:47 AM9/9/17
to xyce-users
Hi,

I would like to sweep two parameters together in a single sweep. For example, to perform a standard two tones intermodulation simulation I would like to use something like

...
** parameters
.param df=1e6                 ; tone frequency spacing
.param lo_freq=1e9              ; carrier frequency
.param s1_mag=10m               ; magnitude of tone s1
.param s1_freq={lo_freq + df}   ; frequency of tone s1
.param s2_mag={s1_mag}          ; magnitude of tone s2
.param s2_freq={lo_freq + 2*df} ; frequency of tone s2

** driving sources
vs1 vin  vin1 sin(0 {s1_mag} {s1_freq} 0 0 0}
vs2 vin1 0    sin(0 {s2_mag} {s2_freq} 0 0 0}

** simulation
.hb {s1_freq} {s2_freq}

** loop
.step dec {s1_mag} 1m 10m 5
...

As far as I understand from the manual there are many unsupported aspects in this netlist snippet:

  • Expressions are not supported in the '.step' command. The sweep variable has to be a device parameter. However, a voltage source seems to only be able to generate a single tone. Using two '.step' commands, one for each voltage source, results in many combinations that are of no interest.
  • In narrow band circuits, such as communication receivers, one is often interested in the linearity at different frequency offsets. Therefore I would like to be able to sweep the parameter 'df'. This has the same problem as above with '.step'. On top of this one can't use expressions in simulation commands such as '.hb'. So, even using two '.step' command producing more simulations than desired, this would still not work as the simulation frequencies would also have to be changed at each sweep step.

Is there a recommended way to achieve the above in a different and simple way?

If not, are there any plans to make expressions usable in simulation, '.step' and possibly more places?


Best Regards,

Fede

xyce-users

unread,
Sep 9, 2017, 12:03:53 PM9/9/17
to xyce-users

Fede:

You state:


Expressions are not supported in the '.step' command. The sweep variable has to be a device parameter. However, a voltage source seems to only be able to generate a single tone. Using two '.step' commands, one for each voltage source, results in many combinations that are of no interest.

This is not entirely correct: no, you can't step arbitrary brace-delimited expressions or parameters defined by ".param" statements, but the .STEP command supports sweeping not only device parameters but also global parameters defined in .global_param statements.  So you can accomplish some of what you want by replacing your .param statements with .global_param statements:

*parameters
.global_param s1_mag=10m
[...]


vs1 vin  vin1 sin
(0 {s1_mag} {s1_freq} 0 0 0}
vs2 vin1
0    sin(0 {s2_mag} {s2_freq} 0 0 0}
[...]

.step dec s1_mag 1m 10m 5

Note that you do not enclose the parameter name in braces on the .step line --- it is not an expression, it is simply the name of the parameter to sweep. 

Because .param statements are essentially parse-time macro substitutions, they can't be swept --- they must evaluate to a constant at the beginning of a run, and are replaced by that constant everywhere where they appear during an early phase of netlist parsing.  By the time analysis is run the code no longer even knows that a parameter was used.  .global_param statements, however, define runtime variables, and these may be swept by .step parameters.  In some contexts they may even be explicitly time-dependent expressions (though not solution-variable dependent).  The other important difference between .param and .global_param is that .global_param statements define parameters that have global scope --- they are visible to all levels of netlist hierarchy regardless of where they are defined and may not be redefined by statements at lower levels.  .param statements are always scoped to the level of netlist hierarchy where they are defined.

I have reviewed the documentation of the .step command and found that it inadequately describes what types of parameters may be used, and all of the examples shown are sweeping device parameters.  There is mention in the .param and .global_param documentation about whether or not they can be used in .step, but it would be better if .step had more complete documentation and more varied examples.  We'll try to improve it for the next release.

You are absolutely correct, however, that the .hb analysis statement does not support having its parameters defined by expressions, and so there is currently no way for you to do a .step over a parameter and have harmonic balance analysis run using tones computed from parameters that are swept.  This limitation applies to all analysis statements in Xyce such as .tran or .dc. Thought we have had other requests for that sort of feature and there is clearly merit to adding it, it is more difficult to implement at this time and may not get done soon.

For the time being, your only choice for performing harmonic balance runs with different tones specified would be to do each set of tones in a separate run of Xyce, and manage the runs with an external script of some kind that rewrites the .hb line for each run.

xyce-users

unread,
Sep 9, 2017, 12:14:25 PM9/9/17
to xyce-users
I realized that I was a little too aggressive trimming your example down when I demonstrated how to use .global_param.  It would have been better if I had added a few more lines:
*parameters

.global_param df=1e6                 ; tone frequency spacing
.
global_param lo_freq=1e9              ; carrier frequency
.
global_param s1_mag=10m               ; magnitude of tone s1
.
global_param s1_freq={lo_freq + df}   ; frequency of tone s1
.
global_param s2_mag={s1_mag}          ; magnitude of tone s2
.
global_param s2_freq={lo_freq + 2*df} ; frequency of tone s2[...]


vs1 vin  vin1 sin
(0 {s1_mag} {s1_freq} 0 0 0}
vs2 vin1
0    sin(0 {s2_mag} {s2_freq} 0 0 0}
[...]
.step dec s1_mag 1m 10m 5

In this example, you can sweep s1_mag and s2_mag, also being a global param with an expression that depends on s1_mag will also be swept in step with it.  Unlike .param parameters, which are evaluated at parse time, global params with expression values are evaluated at the time they are used, and the expressions are re-evaluated if any dependent variables change.

Since I've redefined it as a global parameter, you could also sweep df if you wanted to, and s1_freq and s2_freq would change accordingly, but as you pointed out, you could not then run the .hb analysis with the right frequencies for each step, so this doesn't help you much.  You would still need to do each HB run with modified frequencies in a separate run of Xyce to accomplish that.

Fede

unread,
Sep 10, 2017, 10:14:58 AM9/10/17
to xyce-users
Thank you for the detailed and very clear answer!

Fede
Reply all
Reply to author
Forward
0 new messages