{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T08:08:06.174626Z", "start_time": "2018-11-24T07:52:46.148236Z" } }, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\",category =RuntimeWarning)\n", "import numpy as np\n", "import makeqx as mkq\n", "import de2 as de\n", "import multiprocessing as mp\n", " \n", "# def arc_0(qx, lam_min=400, lam_max=800, npoints=50):\n", "# cthick = qx[0]\n", "# q_x = qx[1:]\n", "# Rs0, Rp0 = mkq.tmm_lam_parallel(q_x, cthick, 0, n_par=12, lam_low=lam_min, lam_high=lam_max, lam_pts=npoints, n_subs=1.52)\n", "# return np.mean(Rs0)\n", " \n", "# def arc_dig_0(qx, lam_min=400, lam_max=800, npoints=50):\n", "# cthick = qx[0]\n", "# q_x = mkq.digitize_qx(qx[1:], dlevels=2)\n", "# Rs0, Rp0 = mkq.tmm_lam_parallel(q_x, cthick, 0, n_par=12, lam_low=lam_min, lam_high=lam_max, lam_pts=npoints, n_subs=1.52)\n", "# return np.mean(Rs0)\n", "\n", "\n", "def tmm_wrapper2(arg):\n", " args, kwargs = arg\n", " return mkq.tmm_eval_wsweep(*args, **kwargs)\n", "\n", "\n", "def arc_par(pop, **kwargs):\n", " jobs = []\n", " pool=mp.Pool(60)\n", " for indiv in pop:\n", " indivi = mkq.digitize_qx(indiv[1:], dlevels=2)\n", " jobs.append((indivi, indiv[0], 0))\n", " arg = [(j, kwargs) for j in jobs]\n", " answ = np.array(pool.map(tmm_wrapper2, arg))\n", " pool.close()\n", " return np.mean(answ, axis=1)\n", "\n", " \n", "num_layers = 35 \n", "bnds = [(0, 1)]*num_layers\n", "bnds = [(300, 400)] + bnds\n", "its_first = 0\n", "psnew = 500\n", "its_second = 500\n", "\n", "pop = np.ones((psnew, 1+ num_layers))\n", "for indiv in range(psnew):\n", " pop[indiv,1:] = mkq.make_qx(num_layers)\n", " pop[indiv,0] = np.random.uniform( bnds[0][0], bnds[0][1], 1 )\n", " \n", "b, c, hstry = de.de_cp(fobj=arc_par, bounds=bnds, pop=pop, history=[], it_start=its_first, popsize=psnew, its=its_second, lam_low=400, lam_high=800, lam_pts=50)\n", "\n", "\n", "#m1 = mkq.tmm_eval2(qx=pop[0][1:], cthick=pop[0][0]) \n", "#m2 = mkq.tmm_eval(qx=pop[0][1:], cthick=pop[0][0]) \n", "\n", "#arc_par(pop, lam_low=400, lam_high=800, lam_pts=50)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "start_time": "2018-11-25T05:56:13.149Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 14.620526569593837\n", "5 14.620526569593837\n", "10 14.620526569593837\n", "15 14.620526569593837\n", "20 9.74940559015386\n", "25 8.272239076481561\n", "30 8.272239076481561\n", "35 7.104313257254263\n", "40 4.295486548704374\n", "45 2.380561145573948\n", "50 2.380561145573948\n", "55 2.380561145573948\n", "60 1.717713024452679\n", "65 1.717713024452679\n", "70 1.717713024452679\n", "75 1.717713024452679\n", "80 1.3160948342395318\n", "85 1.3123680110893694\n", "90 0.9706808480376451\n", "95 0.8869983624926128\n", "100 0.8869983624926128\n", "105 0.8869983624926128\n", "110 0.7612086009656585\n", "115 0.7612086009656585\n", "120 0.7345701574595528\n", "125 0.5480017639146584\n", "130 0.5480017639146584\n", "135 0.5480017639146584\n", "140 0.47102733135844466\n", "145 0.34366533410402916\n", "150 0.34366533410402916\n", "155 0.34366533410402916\n", "160 0.34366533410402916\n", "165 0.34366533410402916\n", "170 0.34366533410402916\n", "175 0.34366533410402916\n", "180 0.34366533410402916\n", "185 0.34366533410402916\n", "190 0.34366533410402916\n", "195 0.34366533410402916\n", "200 0.34366533410402916\n", "205 0.34366533410402916\n" ] } ], "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\",category =RuntimeWarning)\n", "import numpy as np\n", "import makeqx as mkq\n", "import de2 as de\n", "import multiprocessing as mp\n", "import qxnew as qn \n", "# def arc_0(qx, lam_min=400, lam_max=800, npoints=50):\n", "# cthick = qx[0]\n", "# q_x = qx[1:]\n", "# Rs0, Rp0 = mkq.tmm_lam_parallel(q_x, cthick, 0, n_par=12, lam_low=lam_min, lam_high=lam_max, lam_pts=npoints, n_subs=1.52)\n", "# return np.mean(Rs0)\n", " \n", "# def arc_dig_0(qx, lam_min=400, lam_max=800, npoints=50):\n", "# cthick = qx[0]\n", "# q_x = mkq.digitize_qx(qx[1:], dlevels=2)\n", "# Rs0, Rp0 = mkq.tmm_lam_parallel(q_x, cthick, 0, n_par=12, lam_low=lam_min, lam_high=lam_max, lam_pts=npoints, n_subs=1.52)\n", "# return np.mean(Rs0)\n", "\n", "\n", "def tmm_wrapper2(arg):\n", " args, kwargs = arg\n", " return qn.tmm_eval_wsweep(*args, **kwargs)\n", "\n", "\n", "def arc_par(pop, **kwargs):\n", " jobs = []\n", " pool=mp.Pool(90)\n", " for indiv in pop:\n", " indiv = indiv.reshape((int(indiv.size/2), 2))\n", " indiv[:,1] = mkq.digitize_qx(indiv[:,1], dlevels=2)\n", " indiv = indiv.flatten()\n", " jobs.append((indiv, 0.5, 8 , 0))\n", " arg = [(j, kwargs) for j in jobs]\n", " answ = np.array(pool.map(tmm_wrapper2, arg))\n", " pool.close()\n", " return np.mean(answ, axis=1)\n", "\n", " \n", "num_layers = 50\n", "d_min = 0.5\n", "d_max = 8\n", "\n", "bnds = [(d_min, d_max), (0,1) ]*num_layers\n", "#bnds = [(300, 400)] + bnds\n", "its_first = 0\n", "psnew = 320\n", "its_second = 500\n", "\n", "pop = np.ones((psnew, 2*num_layers))\n", "for indiv in range(psnew):\n", " pop[indiv] = qn.make_qxn(num_layers, dlevels=2)\n", " pop[indiv][::2] = (d_max - d_min)*pop[indiv][::2] + d_min\n", " pop[indiv,0] = np.random.uniform( bnds[0][0], bnds[0][1], 1 )\n", " \n", "b, c, hstry = de.de_cp(fobj=arc_par, bounds=bnds, pop=pop, history=[], it_start=its_first, popsize=psnew, its=its_second, lam_low=400, lam_high=800, lam_pts=50)\n", "\n", "np.sum(b[::2]), b[::2], b[1::2], c\n", "\n", "#m1 = mkq.tmm_eval2(qx=pop[0][1:], cthick=pop[0][0]) \n", "#m2 = mkq.tmm_eval(qx=pop[0][1:], cthick=pop[0][0]) \n", "\n", "#" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2018-11-25T05:28:27.167141Z", "start_time": "2018-11-25T05:28:27.159054Z" } }, "outputs": [ { "data": { "text/plain": [ "(33.093934964446646,\n", " array([2.44511696, 6.27208212, 1.19221335, 0.5 , 2.13392 ,\n", " 0.5 , 1.17464269, 0.5 , 0.5 , 0.5 ,\n", " 0.5 , 0.5 , 0.5 , 0.5 , 1.01725833,\n", " 1.33161583, 0.5 , 0.5 , 0.5 , 0.5 ,\n", " 1.50581117, 0.5356352 , 1.51977252, 0.5 , 0.5 ,\n", " 2. , 0.5 , 2.9658668 , 0.5 , 0.5 ]),\n", " array([0., 0., 0., 1., 0., 0., 1., 1., 1., 1., 0., 0., 1., 0., 1., 1., 1.,\n", " 0., 1., 0., 1., 0., 1., 1., 0., 0., 1., 0., 1., 1.]),\n", " 0.47579005978506084)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-04T12:53:39.666806Z", "start_time": "2018-11-04T12:53:39.659691Z" } }, "outputs": [], "source": [ "import makeqx as mkq\n", "mkq.make_qx(10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-04T13:56:02.195399Z", "start_time": "2018-11-04T13:56:02.187776Z" } }, "outputs": [], "source": [ "bnds[0][0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T09:33:46.310018Z", "start_time": "2018-11-24T09:33:46.290131Z" } }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "import qxnew as qn" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T09:33:48.151601Z", "start_time": "2018-11-24T09:33:48.128603Z" } }, "outputs": [], "source": [ "qx = qn.make_qxn(40,5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T09:33:50.326789Z", "start_time": "2018-11-24T09:33:50.307053Z" } }, "outputs": [], "source": [ "qx" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T07:07:44.202457Z", "start_time": "2018-11-24T07:07:44.180095Z" } }, "outputs": [], "source": [ "qn.make_nxdx(qx, d_min=2, d_max=10, wavelen=550, n_substrate=1.52)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T07:07:45.345103Z", "start_time": "2018-11-24T07:07:45.322470Z" } }, "outputs": [], "source": [ "qn.tmm_eval_wbk(qx, 2, 10, 0, 550, 1.52)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-11-24T07:07:47.293093Z", "start_time": "2018-11-24T07:07:47.155314Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from jupyterthemes import jtplot\n", "# currently installed theme will be used to\n", "# set plot style if no arguments provided\n", "jtplot.style()\n", "Rs = qn.tmm_eval_wsweep(qx, d_min=2 , d_max=10, inc_ang=0, lam_low=400, lam_high=800, lam_pts=50, n_subs=1.52) # in nm\n", "lams = np.linspace(400, 800, endpoint=True, num=50)\n", "plt.plot(lams, Rs )\n", "plt.xlabel('Wavelength (nm)')\n", "plt.ylabel('Reflectance (%)')\n", "plt.ylim([0,100])\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false } }, "nbformat": 4, "nbformat_minor": 2 }