.. _nnevo_scipy_2DEG: Optimization of a 2DEG structure ================================ .. attention:: |The_nextnanoevo_package| is under development. .. contents:: :local: :backlinks: none Header --------- Relevant files - :guilabel:`Greg_Snider_MANUAL_1D_optimization_nnp.in` - :guilabel:`2DEG_example.py` (not available public yet) Relevant output files: - :guilabel:`bias_00000/density_electron.dat` Scope - design optimization - 2DEG - electron density Important variables - ``$quantum_well_width`` (thickness of the GaAs quantum well) Introduction ------------ This tutorial demonstrates the use of |nextnanoevo| for optimization of a 2DEG design from the tutorial :ref:`1D_schroedinger_poisson`. Objective ^^^^^^^^^ The first state (subband) confined in the GaAs quantum well is forming 2-dimensional electron gas (2DEG) formed at one of interfaces due to electric field originated from the Schottky layer. Multiple parameters of the structure are impacting formation of the 2DEG, and one of them is the width of the quantum well containing the 2DEG. Therefore, one can aim at choosing the best width of the quantum well for a given design, to obtain 2DEG with the highest possible occupation of the first state (subband). In this tutorial we show, how to perform such optimization. We show how to maximize occupation of the first electron state by varying the thickness of the GaAs quantum-well layer in the range from 1 nm to 20 nm. .. Intuitively, the smaller the quantum well width the more localized the electron density will be. In reality, once the well thickness is smaller than optimal value, the density is partially trapped in the neighboring regions of the 2DEG. The goal of this optimization is to determine the quantum well thickness in the 2DEG design that achieves the highest localization of electron density inside the 2DEG layer. Intuitively, the smaller the quantum well width the more localized the electron density will be. In reality, once the well thickness is smaller than optimal value, the density is partiallly trapped in the neighboring regions of the 2DEG. For even smaller quantum well thickness parameter the binding energy is so high that the ground state is not localized in the well anymore. So the objective of this optimization run is to find optimial quantum well thickness that maximizes the peak density inside the 2DEG layer. Variables under optimization: .. table:: ======================= ======== ================= =========== Name Units Initial value Bounds ======================= ======== ================= =========== ``$quantum_well_width`` nm 15.0 1.0-20.0 ======================= ======== ================= =========== Target output: .. table:: ======================================= ================= ================= ========= Name Units Initial value Target ======================================= ================= ================= ========= Occupation of the first subband :math:`cm^{-2}` 0.1668 max ======================================= ================= ================= ========= Scipy.optimize.minimize ^^^^^^^^^^^^^^^^^^^^^^^ In this example *scipy.optimize.minimize* algorithm is used. The algorithm searches for the minimum value in the provided variable space. In this tutorial only 1 variable is optimized, but the algorithm supports n-dimensional variable space. .. hint:: Every maximization problem can be formulated as minimization by changing the sign of the target value. Optimization script ------------------- At first, specify input file, variables, and relevant output files in the ``IO`` instance: .. code:: Python from nextnanoevo.IO import IO nn_io = IO(input_file_path, ['quantum_well_width'], [('bias_00000', 'Quantum', 'occupation_quantum_region_Gamma.dat')]) Next, define the metric function to extract the occupation of the first subband in the 2DEG region. .. code:: Python def max_first_state_occupation(df_list): gamma_first_state_occupation = df_list[0].variables[0].value[0] # negative sign to use "minimize" method return -gamma_first_state_occupation .. code:: Python metric = Metric(input_length=1, output_length=1, extraction_function=max_first_state_occupation) Create the Optimizer, and set the initial value and bounds for the quantum well thickness. .. code:: Python from nextnanoevo.OptimizerClass import Optimizer optimizer = Optimizer(nextnanoio=nn_io, metric=metric, optimization_method='minimize') # Setting the scipy.optimize.minimize arguments optimizer.set_optimization_parameters(x0=15, bounds=[(1, 20), ], method='Nelder-Mead') Run the optimization. The details are recorded in the Simulation*.log file, which tracks each input file execution. .. code:: Python result = optimizer.run_optimization() print(f"The optimal quantum well thickness is {result.x} nm") Output: .. code:: shell The optimal quantum well thickness is [8.34375] nm