• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. Use if statement to define parameters in Monte Carlo si...

Stats

  • Locked Locked
  • Replies 7
  • Subscribers 125
  • Views 12509
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use if statement to define parameters in Monte Carlo simulation

Holz
Holz over 3 years ago

Hi everyone,

in adexl I have a global variable "IFL", is has only four values 1,2,3,4. In Monte Carlo simulation, I would like to randomly select value of "IFL" from them, so in scs file I write:

parameters
     IFL_value=0 \
     ifl=0
if (IFL_value < 1/4) {
   ifl=1
} else if (IFL_value< 2/4) {
   ifl=2
} else if (IFL_value < 3/4) {
   ifl=3
} else { ifl=4 }

statistics {

 process{   vary IFL_value dist=unif N=1

 }

}

And in global variable, "IFL" is "ifl". And I get following error, it looks like I did something wrong in if statement.

Cannot run the simulation because syntax error `Unexpected equals "="' was encountered at line 21, column 6. Correct the syntax error and rerun the simulation.

So should I change the code to something like:

ifl = {

if (IFL_value < 1/4) : 1

else if (IFL_value < 2/4)  :2

............

}

Or is there any other solution? Any feedback would be appreciated

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    The simplest would be to use nested ternary expressions like this:

    parameters \
         IFL_value=0 \
         ifl=IFL_value<1/4 ? 1 : IFL_value<2/4 ? 2 : IFL_value<3/4 ? 3 : 4
    
    statistics {
     process{
       vary IFL_value dist=unif N=1
     }
    }

    The ternary expressions can be read as 'if expr1 then val1 else if expr2 then val2 else if expr3 then val3 else val4'

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    The simplest would be to use nested ternary expressions like this:

    parameters \
         IFL_value=0 \
         ifl=IFL_value<1/4 ? 1 : IFL_value<2/4 ? 2 : IFL_value<3/4 ? 3 : 4
    
    statistics {
     process{
       vary IFL_value dist=unif N=1
     }
    }

    The ternary expressions can be read as 'if expr1 then val1 else if expr2 then val2 else if expr3 then val3 else val4'

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • Holz
    Holz over 3 years ago in reply to Andrew Beckett

    Thanks Andrew, I get error:

    In my design, I connect a pulse current source to each net and  use "a_1","b_1","cin_1" to control the the current direction(as shown in following figure). And the values of these parameters are also randomly sampled use monte carlo(either vdd or 0). It seems like virtuoso can't generate netlists in a right way. I have tried to set "a_1","b_1","cin_1" to constant values like "vdd,vdd,0", then I get no error. Do you have suggestion how to solve this problem? Thanks a lot.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Holz

    There's not enough information to diagnose what you've done wrong - the blow up suggests that you are trying to (maybe) force a current through an open circuit, which means that it's trying to push it into the gmin conductance (which would be 1TOhm by default). However, there's not enough context in your description to know what you've done wrong.

    I suggest you contact customer support as that will minimise any guesswork involved in figuring out what's gone wrong.

    I rather doubt that it's "virtuoso can't generate netlists in a right way". The expressions you have tor "i_net01" or "l_net01" (it's a picture so I can't read it) look a bit strange - these are doing some kind of logical combination of values but using == operators on numbers that are floating point (which is a very bad idea, because tiny rounding errors or simulator accuracy differences would mean that it's highly unlikely you'll get an exact parameter value match). However, I've no idea whether that's what the problem is - as I said, there's not enough information to go on.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Holz
    Holz over 3 years ago in reply to Andrew Beckett

    Sorry for the unclarity of problem. I generate the netlist of monte carlo simulation, I just put the definition of current source here:

    I_source5 (net05 0) isource type=exp val0=0 val1=I_net05 td1=10p tau1=5p \
            tau2=100p
    I_source4 (net04 0) isource type=exp val0=0 val1=I_net04 td1=10p tau1=5p \
            td2=25p tau2=100p
    I_source3 (net03 0) isource type=exp val0=0 val1=I_net03 td1=10p tau1=5p \
            td2=25p tau2=100p
    I_source2 (net02 0) isource type=exp val0=0 val1=I_net02 td1=10p tau1=5p \
            td2=25p tau2=100p
    I_source1 (net01 0) isource type=exp val0=0 val1=I_net01 td1=10p tau1=5p \
            td2=25p tau2=100p

    So I connect one current source to each of the five nets in my circuit. I run a monte carlo simualtion, which has 10000 points. In each point or each sub-simulation, I use a global variable "IFL" to control whether a current source is active or not(active means current strength is not 0A). Here, in each sub-simulation, only one current source is active. For example when (IFL==1 and cin_1==vdd and a_1==vdd and b_1==0), then current source "I_source1" is active, whose peak value is "I_net01", also "-current" (-100uA). All other four current sources has 0A current. The direction of current (positive or negative) is controlled by input vector "a_1","b_1","cin_1"

    I use Monte carlo to randomly get the values of "IFL" "a_1" "b_1" "cin_1", here is what I wrote in .scs file:

    parameters vdd=0.8 \
               a1_value=0 \
               b1_value=0 \
               c1_value=0 \
               a1=(a1_value>0?vdd:0) \
               b1=(b1_value>0?vdd:0) \
               c1=(c1_value>0?vdd:0) \          
               IFL_value=0 \
               ifl=IFL_value<1/5 ? 1 :IFL_value<2/5 ? 2 : IFL_value<3/5 ? 3 : IFL_value<4/5 ? 4 : 5
    statistics {
       process {
          vary a1_value dist=unif N=1
          vary b1_value dist=unif N=1
          vary c1_value dist=unif N=1
          vary IFL_value dist=unif N=1
    }
    }

    And about the "==" operator, if I define the "ifl" in the way shown in the above code, it should not be problematical right?

    My problem is, when I set "a_1""b_1""cin_1" to constant value, for example "vdd,vdd,vdd", I don't get any error. But when I try to use monte carlo on "a_1""b_1""cin_1", I get error:

    Error found by spectre during IC analysis, during transient analysis `tran', during Monte Carlo analysis `mc1'.

    ERROR (SPECTRE-16385): There were 14 attempts to find the DC solution. In some of those attempts, a signal exceeded the blowup limit of its quantity.

    The last signal that failed is V(I57.net040) = -1.46598 GV, for which the quantity is `V' and the blowup limit is (1 GV). It is possible that the circ

    uit has no DC solution. If you really want signals this large, set the `blowup' parameter of this quantity to a larger value.

    Error found by spectre during IC analysis, during transient analysis `tran', during Monte Carlo analysis `mc1'.

    ERROR (SPECTRE-16080): Cannot print DC solution because DC did not converge. Resolve the convergence issue and rerun the simulation.

    I hope now my problem is clear to you. I'm wondering which step in wrong.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Holz

    As I said, you should contact customer support (not quite sure why you had 8 attempts to post some information here). This site is not customer support - it's a community forum.

    However, in order to show that the issue is beyond what you've posted, I assembled the pieces you provided above, added a dummy circuit (five 10Ohm resistors) and run the simulation on the netlist I produced. Not a blow up in sight - this simulates with no problems at all:

    //
    
    // replicate the stuff from ADE
    parameters current=100u
    parameters cin_1=c1 b_1=b1 a_1=a1 IFL=ifl \
      I_net01=(IFL==1)&&(cin_1==vdd&&a_1==vdd&&b_1==0)&&-current||0 \
      I_net02=(IFL==2)&&(cin_1==0&&a_1==vdd&&b_1==vdd)&&-current||0 \
      I_net03=(IFL==3)&&(cin_1==vdd&&a_1==vdd&&b_1==vdd)&&-current||0 \
      I_net04=(IFL==4)&&(cin_1==0&&a_1==vdd&&b_1==0)&&-current||0 \
      I_net05=(IFL==5)&&((cin_1==0&&a_1==0&&b_1==vdd)||(cin_1==0&&a_1==vdd&&b_1==0))&&-current||0
    
    // replicate the parameters in the forum post
    parameters vdd=0.8 \
               a1_value=0 \
               b1_value=0 \
               c1_value=0 \
               a1=(a1_value>0?vdd:0) \
               b1=(b1_value>0?vdd:0) \
               c1=(c1_value>0?vdd:0) \          
               IFL_value=0 \
               ifl=IFL_value<1/5 ? 1 :IFL_value<2/5 ? 2 : IFL_value<3/5 ? 3 : IFL_value<4/5 ? 4 : 5
    
    statistics {
       process {
          vary a1_value dist=unif N=1
          vary b1_value dist=unif N=1
          vary c1_value dist=unif N=1
          vary IFL_value dist=unif N=1
       }
    }
    
    // now the current sources
    I_source5 (net05 0) isource type=exp val0=0 val1=I_net05 td1=10p tau1=5p \
            tau2=100p
    I_source4 (net04 0) isource type=exp val0=0 val1=I_net04 td1=10p tau1=5p \
            td2=25p tau2=100p
    I_source3 (net03 0) isource type=exp val0=0 val1=I_net03 td1=10p tau1=5p \
            td2=25p tau2=100p
    I_source2 (net02 0) isource type=exp val0=0 val1=I_net02 td1=10p tau1=5p \
            td2=25p tau2=100p
    I_source1 (net01 0) isource type=exp val0=0 val1=I_net01 td1=10p tau1=5p \
            td2=25p tau2=100p
    
    // some load - used 10 ohm resistors
    R1 (net01 0) resistor r=10
    R2 (net02 0) resistor r=10
    R3 (net03 0) resistor r=10
    R4 (net04 0) resistor r=10
    R5 (net05 0) resistor r=10
    
    mc montecarlo numruns=10000 savefamilyplots=yes {
      tran tran stop=100p
    }

    So the issue appears to be related to your circuit. You do always need to be careful with ideal current sources, because there's no current limiter in the source - as I said, it will try to drive the current regardless of the load, even if the junctions are off. That's why I suggested you contact customer support, as without seeing the full problem, this is going to be hard to diagnose.

    My point about == remains. You can get away with it here, but it's an accident waiting to happen.

    By the way, just as a quick point - you do realise that IFL_value will vary between -1 and +1, so that means that ifl is 6 times more likely to be 1 than 2, 3, 4 or 5? Maybe that was intended?

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Holz
    Holz over 3 years ago in reply to Andrew Beckett

    Thanks for your answer! IFL_value varies between -1 and +1, I did something wrong here. Actually I want to have same propability that ifl is set to 1 2 3 4 5. So now I change this part now to:

           ifl=IFL_value< -3/5 ? 1 :IFL_value< -1/5 ? 2 : IFL_value<1/5 ? 3 : IFL_value<3/5 ? 4 : 5
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Holz

    Just to give a little update on this topic - in SPECTRE20.1 ISR12 (released recently) there's a new distribution type sunif which stands for set-uniform or discrete-uniform. More can be found out about this in this "what's new" presentation (note, it's not been published yet)

    However, the example I gave much earlier in this thread here can be changed to this:

    parameters \
         ifl=1
    
    statistics {
     process{
       vary ifl dist=sunif values=[1 2 3 4]
     }
    }
    
    V1 (n1 0) vsource dc=ifl
    
    mc montecarlo numruns=200 savefamilyplots=yes {
        dc dc
    }

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information