Automated optimization of a Double Quantum Well#
- Input files:
double_QW_AlGaAs.nnp
- Python scripts:
double_QW_local_optimization.pydouble_QW_bayesian.pydouble_QW_evolution.py
General setup of the example#
We use a simple example of a double quantum well (DQW) to demonstrate optimization of a nano device with the help of different methods included in nextnano optimizers.
Figure 6 Double quantum well made from \(\mathrm{Al}_{x}\mathrm{Ga}_{1-x}\mathrm{As}\) alloys.#
The DQW is made from \(\mathrm{Al}_{x}\mathrm{Ga}_{1-x}\mathrm{As}\)
alloys. The widths of the outer and inner barriers are
fixed to 15.0nm and 2.0nm, respectively. The fraction
of Al in all barriers is 0.35. Remaining 4 parameters,
namely, the widths of quantum wells (Lx_QW1, Lx_QW2), and
the fractions of Al in quantum wells (Al_QW1, Al_QW2), are
treated as optimization parameters and can be varied
during optimization.
The optimization problem is formulated as a kind of inverse engineering.
First, random values are assigned to the optimization variables. These
values are chosen as $Lx_QW1 = 10.506, $Lx_QW2 = 11.302, $Al_QW1 = 0.182,
$Al_QW2 = 0.219 in the double_QW_AlGaAs.nnp input file. Next, lowest four
energy levels, \(E_{0,1,2,3}\), and corresponding wave functions,
\(\psi_{0,1,2,3}\), are calculated by using the nextnano solver.
Here, the subscript \(i=0\) denotes the ground state.
Figure 7 Four lowest energy levels (left panel) and corresponding wave functions (right panel) for the DQW with parameters defined in the text.#
Finally, transition energies
and dipole matrix elements
are calculated and provided to the optimizer as targets. The values of the optimization variables are initially not known to the optimizer. The optimization task is to find a set of the optimization variables, which minimizes deviations of \(\omega_{i,0}\) and \(X_{k,l}\) from their target values.
Common optimization configuration#
The problem described above can be solved with the help of any method from nextnano optimizers package.
Regardless of the method chosen, the IO and Metric class are defined in the same way.
IO configuration#
In the IO class, the following has to be defined:
the path to the nextnano input file used for the simulations:
double_QW_AlGaAs.nnp;the variables to be optimized:
Lx_QW1,Lx_QW2,Al_QW1, andAl_QW2;full path to the nextnano output files used to calculate the objective:
energy_spectrum_k00000.datfor the energy levels \(E_{0,1,2,3}\)envelopes_k00000.datfor the wave functions \(\psi_{0,1,2,3}\)
The code below shows how to define the IO class for this example.
import os
from nextnano_optimizers.io import IO
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
input_file_path = os.path.join(THIS_DIR, "double_QW_AlGaAs.nnp")
variable_names = ["Lx_QW1", "Lx_QW2", "Al_QW1", "Al_QW2"]
nn_io = IO(
input_file_path,
variable_names=variable_names,
output_files=[
"bias_00000/Quantum/qr/Gamma/energy_spectrum_k00000.dat",
"bias_00000/Quantum/qr/Gamma/envelopes_k00000.dat",
],
)
Metric configuration#
Metric defines the objective function to be minimized.
In this example, the objective is to minimize the deviations of transition energies and dipole matrix elements from their target values.
from itertools import combinations
import numpy as np
from nextnano_optimizers.metric import Metric
N_STATES = 4
TARGET_TRANSITIONS = np.array([0.0255, 0.0556, 0.0812]) # E1 - E0, E2 - E0, E3 - E0 (eV)
PAIRS = list(combinations(range(N_STATES), 2)) # 0-1, 0-2, 0-3, 1-2, 1-3, 2-3
TARGET_DIPOLES = np.array([2.0652, 2.3316, 0.7223, 3.8012, 1.3743, 6.0064]) # Target dipole moments (nm), in the same order as PAIRS
def deviation_transitions_dipoles(datafiles):
energies = datafiles[0].variables["Energy"].value
transitions = energies[1:N_STATES] - energies[0]
x = datafiles[1].coords["x"].value
psi = [datafiles[1].variables[f"Psi_{i + 1}"].value for i in range(N_STATES)]
dipoles = np.array([abs(np.trapezoid(psi[i] * x * psi[j], x)) for i, j in PAIRS])
return np.array([
np.abs(transitions - TARGET_TRANSITIONS).sum() / TARGET_TRANSITIONS.mean()
+ np.abs(dipoles - TARGET_DIPOLES).sum() / TARGET_DIPOLES.mean()
])
metric = Metric(input_shape=(2,), num_obj=1, extraction_function=deviation_transitions_dipoles)
The following global variables are used to define the extraction function:
N_STATES- number of energy levels and wave functions used in calculations of transition energies and dipole matrix elements;TARGET_TRANSITIONS- target values of transition energies \(\omega_{i,0}\) in eV;PAIRS- list of pairs of states used to calculate dipole matrix elements \(X_{k,l}\);TARGET_DIPOLES- target values of dipole matrix elements \(X_{k,l}\) in nm.
The extraction function deviation_transitions_dipoles takes as input an array of nextnanopy datafiles and calculates the objective function value.
Datafiles are provided in the same order as they are defined in the IO class:
datafiles[0]isenergy_spectrum_k00000.dat, which contains energy levelsdatafiles[1]isenvelopes_k00000.dat, which contains wave function envelopes
The function calculates transition energies and dipole matrix elements and returns the normalized sum of absolute deviations from the target values.
The defined deviation_transitions_dipoles function is then passed to the Metric class as an extraction function, together with the 2 additional parameters:
input_shape- number of input datafiles, which is 2 in this example;num_obj- number of objective values, which is 1 in this example.
Application of various optimization methods#
The above described optimization problem can be tackled with the help of any method from nextnano optimizers package. You can use the following links to learn more about applications of Local Optimizers, Bayesian Optimization, Evolutionary Algorithms and Reinforcement Learning (coming soon) to this toy problem. Since different algorithms are used to solve one and the same problem, one can easily compare their performance, find pro and contra of each method, and choose the appropriate method for realistic optimizations.
Summary#
The table below summarizes the optimization results obtained with different methods. The best design found by each method is shown together with the corresponding objective value and the number of evaluations spent.
Method |
Objective |
|
|
|
|
Evaluations |
|---|---|---|---|---|---|---|
Ideal design |
0 |
10.506 |
11.302 |
0.182 |
0.219 |
– |
0.743 |
12.000 |
12.000 |
0.173 |
0.204 |
148 |
|
0.032 |
10.524 |
11.345 |
0.181 |
0.218 |
300 |
|
0.087 |
10.597 |
11.494 |
0.176 |
0.213 |
900 |
Local optimization ends in a local minimum, and the final design is still far from the ideal one. The optimization results are dependent on the starting point, and different starting points lead to different local minima.
Bayesian optimization recovers the ideal design with an accuracy of 0.05nm in the well widths and 0.001 in the Al fractions.
Evolutionary algorithm recovers the ideal design with an accuracy of 0.2nm in the well widths and 0.01 in the Al fractions, but requires a larger number of evaluations to reach this result.
For this specific example, Bayesian optimization is the most efficient method, as it finds a design close to the ideal one, requiring less evaluations than the evolutionary algorithm.