• 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. Save transient values from a Monte Carlo simulation to a...

Stats

  • Locked Locked
  • Replies 10
  • Subscribers 126
  • Views 9828
  • 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

Save transient values from a Monte Carlo simulation to a .txt file

Yasso
Yasso over 2 years ago

Hello, I have a question regarding the data generated in Monte Carlo simulations. Currently I have an schematic which I need to simulate and save/retrieve specific transient values. My problem is that it doesnt save all the iterations, only the first or the last to a text file. I need to save those values to work later on python/Matlab and in a .txt is the easiest way.

I have the following in a .ocn (ocean script) which triggers after the simulation

Out_It1 = outfile(".../Iteration_1.txt" "w")
Out_It2 = outfile(".../Iteration_1.txt" "w")

for(i 1 19200
sprintf(g "/I%d/Vp" i)
ocnPrint(?output Out_It1  value(VT(g) 100m 'iteration 1) ?numberNotation 'none)
)
close(Out_It1)

for(i 1 19200
sprintf(g "/I%d/Vp" i)
ocnPrint(?output Out_It2 value(VT(g) 100m 'iteration 2) ?numberNotation 'none)
)
close(Out_It2)

I tried different things, and the data regarding this is very limited. Is it possible to do using an ocean script? Or if it isnt that easy could I get some insight on how to achive what I want. Thanks in advance,

Yass

  • Cancel
Parents
  • Yasso
    Yasso over 2 years ago

    Sorry, I made a mistake and cant edit the post, the file names are different,

    Out_It1 = outfile(".../Iteration_1.txt" "w")
    Out_It2 = outfile(".../Iteration_2.txt" "w")

    .... 

    Rest is the same.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to Yasso

    Dear Yasso,

    Yasso said:
    Currently I have an schematic which I need to simulate and save/retrieve specific transient values. My problem is that it doesnt save all the iterations,

    In the Monte Carlo GUI, did you happen to check the Save Waveforms radio button as shown in Figure 1 below?

    Yasso said:
    for(i 1 19200
    sprintf(g "/I%d/Vp" i)
    ocnPrint(?output Out_It1  value(VT(g) 100m 'iteration 1) ?numberNotation 'none)
    )

    Are you trying to access a signal defined as "/IXX/Vp" where XX=[1,19200]? I'm a bit confused as I was assuming the 19200 was the number of Monte Carlo iterations.

    Yasso said:
    Is it possible to do using an ocean script

    Definitely. I have accessed any Monte Carlo data I want from a set of Monte Carlo simulations using ocean. My methodology differs from yours as I traverse the Monte Carlo data base using ocean to access the data for each iteration for further post-processing.

    Shawn

    Figure 1

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Yasso
    Yasso over 2 years ago in reply to ShawnLogan

    Yes, I have the "Save Waveforms" enabled to true,

    ocnxlMonteCarloOptions( ?mcNumPoints "2" ?mcYieldTarget "99.865" ?mcNumBins "" ?samplingMode "random" ?wcdMinYieldSigma "3.0" ?dumpParamMode "yes" ?mcYieldAlphaLimit "0.05" ?mcStartingRunNumber "1" ?mcSigmaTarget "3" ?monteCarloSeed "12345" ?sssNumPoints "7000" ?highYieldExpectedYieldSigma "3" ?mcMethod "all" ?wcdInitialPoints "200" ?wcdMaxIterations "10" ?saveAllPlots "1" ?highYieldUseHistoryMC "0" ?saveProcess "1" ?wcdAutoNumPoints "1" ?mcStopEarly "0" ?highYieldCreateCorners "0" ?saveMismatch "1" ?wcdSkipLowYieldSpecs "1" ?wcdEnableVarReduction "1" )

    The code lines I added are writting into the .txt file the voltage values from instances with the name "I<number of the instance>", exactly the parrameter "Vp". It's basically an array of instances. So for each iteration in MC there are 19000 Vp values that need to be saved into a .txt. Unfortunately it only saves the first or the last iteration, not both in separated files. Just to clarify, I would like to simulate 30 iterations of this array composed of 19000 elements and save the Vp value in different files. This will later be used in a Matlab/Phyton script.

    I'm using a version of cadence 6.1.8-64b (2018-19)

    And thanks for the help!

    Yass

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to Yasso

    Dear Yass,

    Thank for clarifying your simulation! I now understand that you do indeed want to save each of the 19200 individual node voltages for each monte carlo iteration in a separate file.

    Yasso said:
    Just to clarify, I would like to simulate 30 iterations

    Perhaps I am overlooking something obvious, but it appears you are only specifying 2 iterations - not 30 - in your oceanXL command:

    Yasso said:
    ocnxlMonteCarloOptions( ?mcNumPoints "2" ?mcYieldTarget "99.865" ?mcNumBins "" ?samplingMode "random" ?wcdMinYieldSigma "3.0" ?dumpParamMode "yes"

    Note that ?mcNumPoints is set to "2".

    1. Hence, it seems there will only be two iterations and not 30 iterations. As such, you will only be able to generate two files with 19200 values in each - one for the first iteration and a second for the second iteration.

    Yasso said:
    Unfortunately it only saves the first or the last iteration, not both in separated files. Just to clarify, I would like to simulate 30 iterations of this array composed of 19000 elements and save the Vp value in different files.

    2. Your ocnPrint() command syntax may be the reason you are finding your result is only for the first or last iteration. The syntax you are using does not appear to include sufficient information to access the iteration you are interested in saving. oceanXL is the language to use with Assembler and Explorer to take advantage of their database structures. I can provide an example ocean script (not oceanXL) that will traverse your Monte Carlo database and access each voltage and place it in a text file. However, there is a recommended method using oceanXL in the Troubleshooting Article at URL:

    https://support.cadence.com/apex/ArticleAttachmentPortal?id=a1Od0000002JnSHEA0&pageName=ArticleContent

    The article provides a SKILL routine CCSDumpFile() to include in your .csdinit file in your working directory.  You define your output expressions using the CCDDumpFile() function.

    If you would rather run a conventional ocean script and are interested in an example, I placed an example at the Forum post at URL:

    https://community.cadence.com/cadence_technology_forums/f/custom-ic-skill/54157/ocean-script-to-get-monte-carlo-iteration-id-directory

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Yasso
    Yasso over 2 years ago in reply to ShawnLogan

    Hello Shawn, sorry for the late reply,

    Yes, the num of iterations is set to 2 for testing. and I will change it to higher ammounts the moment it works. ocnPrint() was my default command for printing data to .txt, but now knowing that the databases are constructed different for Monte Carlo It explains why I dont get the results I wanted.

    I can't see the support.cadence links because where I work I need to ask EuroPractice (the middle man between Cadence and our work enviroment) to send the tickets for me. I'm checking the seccond script example you have linked me, but it's quite advanced.

    Is it possible for an example with a structure like this,

    Fullscreen Test_ocnXL.txt Download
    ;====================Set to Maestro mode explorer =============================
    ocnSetXLMode("explorer")
    ocnxlProjectDir( "/simulation" )
    ocnxlTargetCellView( ""ARRAY" "ARRAY_TEST" "MC" )
    ocnxlResultsLocation( "" )
    ocnxlSimResultsLocation( "" )
    ocnxlMaxJobFail( 20 )
    
    ;====================== Tests setup ============================================
    
    
    ocnxlBeginTest("ARRAY_TEST:1")
    simulator( 'spectre )
    design( "ARRAY" "ARRAY_TEST" "schematic")
    modelFile( 
        '("../corner.lib.scs" "mc")
    
    )
    analysis('tran ?stop "101m" ?errpreset "conservative"  )
    
    desVar(	  "sigma" 3	)
    envOption(
    	'analysisOrder  list("pz" "dcmatch" "stb" "tran" "envlp" "ac" "dc" "lf" "noise" "xf" "sp" "pss" "pac" "pstb" "pnoise" "pxf" "psp" "qpss" "qpac" "qpnoise" "qpxf" "qpsp" "hb" "hbac" "hbstb" "hbnoise" "hbxf" "sens" "acmatch") 
    )
    option(	'pzSeverity  "None" 
    	'noiseSeverity  "None" 
    	'spSeverity  "None" 
    	'acSeverity  "None" 
    	'dcOpSeverity  "None" 
    	'dcSeverity  "None" 
    	'tranSeverity  "None" 
    	'gmin  "0" 
    )
    option(	'dc_pivot_check  "yes"  
    	'gmin  "1e-18" 
    )
    option( ?categ 'turboOpts
    	'apsplus  t 
    	'errorLevel  "Moderate" 
    	'uniMode  "APS" 
    )
    temp( 27 ) 
    Out_It1 = outfile("/It1.txt" "w")
    Out_It2 = outfile("/It2.txt" "w")
    ocnxlEndTest() 
    
    ;====================== Sweeps setup ===========================================
    
    ;====================== Model Group setup ==========================================
    
    ;====================== Corners setup ==========================================
    
    ;====================== Checks and Asserts setup ============================================
    ocnxlPutChecksAsserts(?netlist nil)
    
    ;====================== Job setup ==============================================
    ocnxlJobSetup( '(
    	"blockemail" "1"
    	"configuretimeout" "300"
    	"defaultcpuvalue" "1"
    	"defaultmemoryvalue" "1000"
    	"distributionmethod" "Local"
    	"jobruntype" "ICRP"
    	"estimatememoryvalue" ""
    	"estimationsimulationmode" "0"
    	"lingertimeout" "300"
    	"maxjobs" "1"
    	"name" "Maestro Default"
    	"preemptivestart" "1"
    	"providecpuandmemorydata" "1"
    	"reconfigureimmediately" "1"
    	"runpointsvalue" "5"
    	"runtimeout" "-1"
    	"scaleestimatedbycpu" "100"
    	"scaleestimatedbymemory" "100"
    	"showerrorwhenretrying" "1"
    	"showoutputlogerror" "0"
    	"startmaxjobsimmed" "1"
    	"starttimeout" "300"
    	"usesameprocess" "1"
    	"warndisklow" "0"
    	"warnthresholdvalue" "100"
    ) )
    
    ;====================== Disabled items =========================================
    ocnxlSetAllParametersDisabled(t)
    
    ;====================== Run Mode Options ======================================
    ocnxlMonteCarloOptions( ?mcNumPoints "2" ?mcYieldTarget "99.865" ?mcNumBins "" ?samplingMode "random" ?wcdMinYieldSigma "3.0" ?dumpParamMode "yes" ?mcYieldAlphaLimit "0.05" ?mcStartingRunNumber "1" ?mcSigmaTarget "3" ?monteCarloSeed "12345" ?sssNumPoints "7000" ?highYieldExpectedYieldSigma "3" ?mcMethod "all" ?wcdInitialPoints "200" ?wcdMaxIterations "10" ?saveAllPlots "1" ?highYieldUseHistoryMC "0" ?saveProcess "1" ?wcdAutoNumPoints "1" ?mcStopEarly "0" ?highYieldCreateCorners "0" ?saveMismatch "1" ?wcdSkipLowYieldSpecs "1" ?wcdEnableVarReduction "1" )
    
    ;====================== Starting Point Info ======================================
    
    ;====================== Run command ============================================
    ocnxlRun( ?mode 'monteCarlo ?nominalCornerEnabled t ?allCornersEnabled nil ?allSweepsEnabled t)
    ocnxlOutputSummary(?yieldSummary t ?exprSummary nil ?specSummary nil ?detailed nil)
    ocnxlOpenResults()
    
    < CODE TO EXTRACT DATA FROM THE MC ITERATIONS >
    -----
    -----
    -----
    -----
    ;====================== End XL Mode command ===================================
    ocnxlEndXLMode("explorer")
    close(Out_Tig_It1)
    close(Out_Tig_It2)

    Where in the section below a code/line of code to extract the data?

    Sorry if I'm asking something complicated, I know it requires work, If theres an ocnXL document with the informations on how to extract this I will gladly take it.

    Thanks again, and happy holidays!

    Yass 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to Yasso

    Dear Yass,

    Yasso said:
    Yes, the num of iterations is set to 2 for testing. and I will change it to higher ammounts the moment it works.

    I now understand and thank you, Yass, for the clarification!

    Yasso said:
    I can't see the support.cadence links because where I work I need to ask EuroPractice (the middle man between Cadence and our work enviroment) to send the tickets for me.

    That is unfortunate - please continue to try to access the documents. I understand that I am not permitted to include the content of an On-line support document in a Forum post and hence, with apologies, I cannot provide you the document I referred to.

    Yasso said:
    I'm checking the seccond script example you have linked me, but it's quite advanced.

    It really is not - otherwise I would not be able to understand it!! I tried to remove all the unnecessary code that illustrate a specific example and include the code below as a text file. The lines you need to modify are highlighted in yellow in Figure 1. You may still choose not to try this, but I wanted to at least try to make it appear less complicated to you.

    Yasso said:
    Where in the section below a code/line of code to extract the data?

    Unless I am misunderstanding your question, the code to extract the data is where the text "< CODE TO EXTRACT DATA FROM THE MC ITERATIONS >" appears. This is after the run command and is preceded by the command to open the results database.

    Shawn

    Fullscreen simplified_annotated_mc_params_sml_122622.txt Download
    
    ; Interative directory number (set to value X of your Montecarlo.X results directory, in the case X=0)
    
    montecarlo_num = 0
    sprintf(montecarlo_num_val "%d" montecarlo_num)
    
    ; Main routine
    
    simulator('spectre)
    date = strcat("040822")
    circuit_name = strcat("<name_of_your_test>")
    base_results=strcat("<full_UNIX_path_to_your_simulation_maestro_directory>/results/maestro/MonteCarlo." montecarlo_num_val "/")
    sub_dir = strcat("/<name_of_your_test>/groupRunDataDir/psf/mc1_separate/")
    sub_netlist_dir = strcat("/<name_of_your_test>/groupRunDataDir/")
    
    sprintf(montecarlo_num_val "%d" montecarlo_num)
    
    init_val = 1
    final_val = 200 ;set final_value = 2 in your example case or 30 in your final case
    
    sim_case = init_val
    
    ; When you run a Monte Carlo simulation, the netlists are shared between simulations
    ; the ocean script runs two loops to traverse this data base. sim_case_delta is the number
    ; of simulations that share a common netlist. The value can be found by examining the number of directories
    ; under the /<name_of_your_test>/groupRunDataDir/psf/mc1_separate/ directory in your results path
    
    sim_case_delta = 3 
    
    while( sim_case < (final_val + 1)
    
    printf("sim_case = %d\n" sim_case)
    sprintf(sim_case_val "%d" sim_case)
    
    sub_sim_case = sim_case
    
    while( (sub_sim_case < (sim_case + sim_case_delta)) && (sub_sim_case < (final_val + 1))
    
    ;; -----------
    sprintf( sub_sim_case_val "%03d" sub_sim_case)
    printf( "sub_sim_case = %03d\n" sub_sim_case)
    
    results=strcat( base_results sim_case_val sub_dir sub_sim_case_val )
    printf("Results directory\n%s\n" results)
    
    netlist_dir = strcat( base_results sim_case_val sub_netlist_dir "netlist")
    printf("Netlist directory\n%s\n" netlist_dir)
    ;; -----------
    
    openResults(results)
    selectResult('tran)
    ;ocnPrint(?output "outputs.txt" outputs())
    
    
    printf("Completed reading waveforms.\n")
    
    
    if((sub_sim_case == init_val) then
    
    ; Define output file for simulation results and write header
    
    sprintf(fname "<name_of_your_output_file")
    fp_params = outfile( fname "w")
    fprintf(fp_params "Corner number,Process,vdda (mV),Temperature (C),") ; header for output file
    ; Place  output expressions here to add to file
    close(fp_params)
    else
    
    fp_params = outfile( fname "a")
    
    ; Place same output expressions here to add to file
    close(fp_params)
    
    )
    
    sub_sim_case = sub_sim_case + 1) ; close sub_sim_case loop
    
    sim_case = sim_case + sim_case_delta) ; close sim_case loop
    
    exit()
    
    
    
    Figure 1

    simplified_annotated_mc_params_sml_excel_122622.xlsx

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to Yasso

    Dear Yass,

    I tried to respond to each of your concerns, but my response was flagged as spam. Hopefully, it will be re-classified for you to view it. Sorry, but I'm  to sure I understand what triggered its "spam rating".

    The text of my response follows.

    Dear Yass,

    Yasso said:
    Yes, the num of iterations is set to 2 for testing. and I will change it to higher ammounts the moment it works.
    I now understand and thank you, Yass, for the clarification!

    Yasso said:
    I can't see the support.cadence links because where I work I need to ask EuroPractice (the middle man between Cadence and our work enviroment) to send the tickets for me.
    That is unfortunate - please continue to try to access the documents. I understand that I am not permitted to include the content of an On-line support document in a Forum post and hence, with apologies, I cannot provide you the document I referred to.

    Yasso said:
    I'm checking the seccond script example you have linked me, but it's quite advanced.
    It really is not - otherwise I would not be able to understand it!! I tried to remove all the unnecessary code that illustrate a specific example and include the code below as a text file. The lines you need to modify are highlighted in yellow in Figure 1. You may still choose not to try this, but I wanted to at least try to make it appear less complicated to you.

    Yasso said:
    Where in the section below a code/line of code to extract the data?
    Unless I am misunderstanding your question, the code to extract the data is where the text "< CODE TO EXTRACT DATA FROM THE MC ITERATIONS >" appears. This is after the run command and is preceded by the command to open the results database.

    Shawn

    Figure 1

    Document: simplified_annotated_mc_params_sml_122622.txt

    Fullscreen 8228.simplified_annotated_mc_params_sml_122622.txt Download
    
    ; Interative directory number (set to value X of your Montecarlo.X results directory, in the case X=0)
    
    montecarlo_num = 0
    sprintf(montecarlo_num_val "%d" montecarlo_num)
    
    ; Main routine
    
    simulator('spectre)
    date = strcat("040822")
    circuit_name = strcat("<name_of_your_test>")
    base_results=strcat("<full_UNIX_path_to_your_simulation_maestro_directory>/results/maestro/MonteCarlo." montecarlo_num_val "/")
    sub_dir = strcat("/<name_of_your_test>/groupRunDataDir/psf/mc1_separate/")
    sub_netlist_dir = strcat("/<name_of_your_test>/groupRunDataDir/")
    
    sprintf(montecarlo_num_val "%d" montecarlo_num)
    
    init_val = 1
    final_val = 200 ;set final_value = 2 in your example case or 30 in your final case
    
    sim_case = init_val
    
    ; When you run a Monte Carlo simulation, the netlists are shared between simulations
    ; the ocean script runs two loops to traverse this data base. sim_case_delta is the number
    ; of simulations that share a common netlist. The value can be found by examining the number of directories
    ; under the /<name_of_your_test>/groupRunDataDir/psf/mc1_separate/ directory in your results path
    
    sim_case_delta = 3 
    
    while( sim_case < (final_val + 1)
    
    printf("sim_case = %d\n" sim_case)
    sprintf(sim_case_val "%d" sim_case)
    
    sub_sim_case = sim_case
    
    while( (sub_sim_case < (sim_case + sim_case_delta)) && (sub_sim_case < (final_val + 1))
    
    ;; -----------
    sprintf( sub_sim_case_val "%03d" sub_sim_case)
    printf( "sub_sim_case = %03d\n" sub_sim_case)
    
    results=strcat( base_results sim_case_val sub_dir sub_sim_case_val )
    printf("Results directory\n%s\n" results)
    
    netlist_dir = strcat( base_results sim_case_val sub_netlist_dir "netlist")
    printf("Netlist directory\n%s\n" netlist_dir)
    ;; -----------
    
    openResults(results)
    selectResult('tran)
    ;ocnPrint(?output "outputs.txt" outputs())
    
    
    printf("Completed reading waveforms.\n")
    
    
    if((sub_sim_case == init_val) then
    
    ; Define output file for simulation results and write header
    
    sprintf(fname "<name_of_your_output_file")
    fp_params = outfile( fname "w")
    fprintf(fp_params "Corner number,Process,vdda (mV),Temperature (C),") ; header for output file
    ; Place  output expressions here to add to file
    close(fp_params)
    else
    
    fp_params = outfile( fname "a")
    
    ; Place same output expressions here to add to file
    close(fp_params)
    
    )
    
    sub_sim_case = sub_sim_case + 1) ; close sub_sim_case loop
    
    sim_case = sim_case + sim_case_delta) ; close sim_case loop
    
    exit()
    
    
    

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to ShawnLogan

    Dear Yass,

    My figure 1 follows:

    1614.simplified_annotated_mc_params_sml_excel_122622.xlsx

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Yasso
    Yasso over 2 years ago in reply to ShawnLogan

    Hello Shawn,

    Thanks for all the help, with the code and explanation your provided I'm confident in achieving the results I want. Thanks again!

    Yasso

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to Yasso

    Dear Yasso,

    Wonderful! Good luck - I am sure you will have success in no time at all!

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to Yasso

    Dear Yasso,

    Wonderful! Good luck - I am sure you will have success in no time at all!

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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