Skip to content

Commit

Permalink
Moving parallel example to end of notebook, commenting out, and addin…
Browse files Browse the repository at this point in the history
…g note about runtime.
  • Loading branch information
tddesjardins committed Sep 27, 2024
1 parent cd91cab commit 476936a
Showing 1 changed file with 57 additions and 50 deletions.
107 changes: 57 additions & 50 deletions content/notebooks/romanisim/romanisim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,54 @@
"source": [
"If we want to simulate an L1 ramp cube, then we can change the level variable above to 1, which will also change the output file name to `*_uncal.asdf`. The rest of the information stays the same.\n",
"\n",
"## Running Roman I-Sim with Shell Scripts\n",
"\n",
"You can also run Roman I-Sim tasks from the command line with executables and shell scripts. These are not easily accessible from a Jupyter notebook, but command line executables romanisim-make-image and romanisim-make-catalog (for making a catalog file from Gaia) exist. The scripts in the S3 bucket provide examples for how to use these. Let's look at one now:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s3_uri = 's3://roman-sci-test-data-prod-summer-beta-test/ROMANISIM/CATALOGS_SCRIPTS/make_ra0.47_dec0.51_pa0_l1_f129.sh'\n",
"fs = s3fs.S3FileSystem()\n",
"\n",
"with fs.open(s3_uri, 'rb') as f:\n",
" for line in f.readlines():\n",
" print(line.decode())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For additional help with the executables, the -h option can be used to get the help text for the input arguments:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!romanisim-make-catalog -h"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!romanisim-make-image -h"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Advanced Use Case: Parallelized Simulations\n",
"\n",
"Often, we will want to run a simulation using multiple detectors rather than just one at a time. Looping over the above in a serial fashion can take quite a long time, so we want to parallelize the work. In the example below, we will show how to parallelize the procedure with the Python standard library `concurrent` module. Note that there are other, more sophisticated tools such as Dask that can achieve scalable results, and we may cover that in future tutorials."
Expand Down Expand Up @@ -393,29 +441,9 @@
"source": [
"We'll also need to allocate a number of threads to the pool. For this example, let's simulate two detectors at the same time, in this case WFI02 and WFI03 since we already simulated WFI01. This should be scalable based on the computational resources you have available on the RSP. \n",
"\n",
"**WARNING:** Please be cautious when parallelizing tasks such as Roman I-Sim as it can easily consume all of your RSP resources if handled incorrectly!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with ThreadPoolExecutor(2) as pool:\n",
" futures = [pool.submit(run_romanisim, full_catalog, **{'sca': x}) for x in [2, 3]]\n",
" wait(futures)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After running this cell, you may notice that some of the log messages are a bit jumbled. That's because the two simulations are running asynchronously on different threads, so messages from both arrive back to the notebook at slightly different but overlapping times.\n",
"**WARNING:** Please be cautious when parallelizing tasks such as Roman I-Sim as it can easily consume all of your RSP resources if handled incorrectly!\n",
"\n",
"## Running Roman I-Sim with Shell Scripts\n",
"\n",
"You can also run Roman I-Sim tasks from the command line with executables and shell scripts. These are not easily accessible from a Jupyter notebook, but command line executables romanisim-make-image and romanisim-make-catalog (for making a catalog file from Gaia) exist. The scripts in the S3 bucket provide examples for how to use these. Let's look at one now:"
"We have commented out the lines below. If you want to run the parallelized simulation, uncomment all of the lines in the following code cell. **Note: this code cell will take a long time to run.**"
]
},
{
Expand All @@ -424,37 +452,16 @@
"metadata": {},
"outputs": [],
"source": [
"s3_uri = 's3://roman-sci-test-data-prod-summer-beta-test/ROMANISIM/CATALOGS_SCRIPTS/make_ra0.47_dec0.51_pa0_l1_f129.sh'\n",
"fs = s3fs.S3FileSystem()\n",
"\n",
"with fs.open(s3_uri, 'rb') as f:\n",
" for line in f.readlines():\n",
" print(line.decode())"
"#with ThreadPoolExecutor(2) as pool:\n",
"# futures = [pool.submit(run_romanisim, full_catalog, **{'sca': x}) for x in [2, 3]]\n",
"# wait(futures)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For additional help with the executables, the -h option can be used to get the help text for the input arguments:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!romanisim-make-catalog -h"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!romanisim-make-image -h"
"After running this cell, you may notice that some of the log messages are a bit jumbled. That's because the two simulations are running asynchronously on different threads, so messages from both arrive back to the notebook at slightly different but overlapping times."
]
},
{
Expand All @@ -477,7 +484,7 @@
"source": [
"## About this notebook\n",
"**Author:** Sanjib Sharma, Tyler Desjardins \n",
"**Updated On:** 2024-23-01"
"**Updated On:** 2024-09-27"
]
},
{
Expand All @@ -498,9 +505,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Roman Calibration latest (2024-03-25)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "roman-cal"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit 476936a

Please sign in to comment.