1D Diode Example Convergence Error Correction

Hello,

I have been working on using a non-linearly squares algorithm to approximate device properties using devsim. Currently, I am running the diode program with ten parameters: n_i, mu_n, mu_p, T, n1, p1, taun, taup, acceptors, and donors. I first run the diode program with a set of default parameters to obtain a set of experimental data. These default parameters are the original parameters set in the diode example, e.g., n_i = 1e10, mu_n = 400, mu_p = 200, etc. The diode program is then given an inital guess of parameters to obtain a set of simulated data that has been fitted to the experimental data using the scipy.optimize.least_squares() algorithm in python. So far I’ve been running my program with an initial guess of parameters that are equivalent to the default parameters, so the data should already be fitted.

The problem I’ve been running into is that the 1D diode example, when running with the default parameters, sometimes gives me a “devsim_py3.error: Convergence failure!” This does not occur every time the program is run, but it does occur often. My code stores the results of the diode program (the values of the permittivity and other node models and edge models at each point on the mesh) after each execution of the program, so when a convergence failure occurs, the result is a 0-d array. This 0-d array causes errors when iterating over arrays – and while this error can be avoided using a “while True” loop to run the diode program over and over until the diode program returns an array whose dimension is greater than zero – such a workaround can greatly increase runtime since the convergence failure occurs so often.

So my question is, why does the convergence failure occur and how do I fix it? Here is a screenshot of my terminal output of the error:

(This output was generated by running the original 1-d diode example using the code shown in the documentation)

Hi @Masamune ,

The issue could be many things. A few things come to mind:

  1. Make sure the inputs are physical.
  2. Use default parameters that always converge for the first solution. Then use devsim.set_parameter to change the values and run devsim.solve to converge upon the new solution. The simulator will detect the changes in the parameters and recalculate all of the models.
  3. Refine the mesh so the spacing is tighter. This may help convergence.

I figured out what was causing the errors coincidentally. For reference, I am running devsim on an Ubuntu 22.04 virtual machine. Since my program needs to run the diode program repeatedly to optimize a set number of variables, I used multithreading to optimize each variable at the same time to speed up the program. Through the use of print statements I saw that my program wasn’t actually running all threads concurrently, they were running one by one, so I thought that the issue may have been that I wasn’t allocating enough threads to my VM. I changed the number of cores that my VM could use up from 3 to 4. This change produced baffling results as the convergence errors began occurring 100% of the time for any devsim program I ran, even though I know they worked before. I just changed the number of cores for my VM from 4 to 1, and now when I run my programs they work as intended. So for some reason, the number of cores my VM uses appears to be related to the frequency of convergence errors.

Thanks for the update. The simulator does not support Python threading. It is probably better to launch separate processes. Please note that the Intel MKL solver uses threading and automatically chooses a number of threads. If you want to run multiple simulations at the same time, you can set:

export MKL_NUM_THREADS=1

so that the threads don’t overwhelm the machine.