-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0921ef4
commit a89135a
Showing
94 changed files
with
190 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a918bec5", | ||
"metadata": {}, | ||
"source": [ | ||
"## <code>GerchbergSaxton_Matrix_MultiProcess.ipynb </code> \n", | ||
" - 03-31-2022\n", | ||
" - Author: Raghav K. Chhetri\n", | ||
" - Multiprocessed Phase Retrievel via Gerchberg-Saxton algorithm to generate phase masks for an SLM \n", | ||
" - Using \"LightPipes for Python\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "1c5fd314", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Invoking __init__.py for matrixpack\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from matrixpack import mask_func, move_func\n", | ||
"from functools import partial\n", | ||
"from LightPipes import nm\n", | ||
"import multiprocessing\n", | ||
"import matplotlib\n", | ||
"%matplotlib inline\n", | ||
"import pylab as plt\n", | ||
"import time" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "40f6a823", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"lamda=488*nm\n", | ||
"niter=50\n", | ||
"dtag='MATRIX'\n", | ||
"path='D:\\\\masks'\n", | ||
"positions = move_func.move(3)\n", | ||
"#position = move_func.move(3)[0:8]\n", | ||
"num_workers = multiprocessing.cpu_count()\n", | ||
"print(num_workers)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5e864059", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"### Compute\n", | ||
"\n", | ||
" If each beam were allowed three choices: -step, 0, or +step, then 3^9 = 19683 possible combinations!\n", | ||
" Alternatively, I'm only selecting a few cases that follow these rules:\n", | ||
" - Each beam has two choices: 0 or +step, then 2^9 = 512 combinations\n", | ||
" - Each beam has two choices: 0 or -step (512-1 combinations: all zeros is already counted)\n", | ||
" - Each beam has two choices: +step or -step (512-2 combinations: all +step already counted, all -step already counted)\n", | ||
" \n", | ||
" So, only need to consider 1533 combinations. \n", | ||
" Note: 9 -bit representation of a number between 0 and 2^9-1= 511 can be obtained by f'{j:09b}'\n", | ||
" \n", | ||
" #adg corresponds to beams 147 = far\n", | ||
" #beh corresponds beams 258 = mid\n", | ||
" #cfi corresponds beams 369 = near\n", | ||
" \n", | ||
" Process:\n", | ||
" 1. Auto-generate a list of beam positions using the rules above: list_move_um()\n", | ||
" 2. Multiprocess mask_func.mask() to generate phase masks for all beam positions on the list " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "8b89208f", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Took 135.3 sec\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"t0 = time.time()\n", | ||
"if __name__ == '__main__':\n", | ||
" pool = multiprocessing.Pool(processes=num_workers) \n", | ||
" poolfun = partial(mask_func.mask, wavelength=lamda, Niter=niter, tag=dtag, outPath=path)\n", | ||
" pool.map(poolfun, positions)\n", | ||
" pool.close()\n", | ||
" pool.join() \n", | ||
"print('Took', round(time.time()-t0,2), 'sec')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"id": "b0a21662", | ||
"metadata": {}, | ||
"source": [ | ||
"# 12 iterations, 1533 masks took 11.5 hours in D13 --> if linear, 1533 masks, 50 iterations = 2 days\n", | ||
"# 50 iterations, 8 masks took 34 minutes in D13 --> if linear, 1533 masks, 50 iterations = 4.5 days" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.9.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.