diff --git a/auto_selfcal/__init__.py b/auto_selfcal/__init__.py index 1d5581e..0b973fd 100644 --- a/auto_selfcal/__init__.py +++ b/auto_selfcal/__init__.py @@ -1,3 +1,22 @@ +try: + import os + if os.getenv("CASAPATH") is not None: + import casampi.private.start_mpi + + def setup_monolithic_CASA(pytest=False): + casa_path = os.getenv("CASAPATH").split(" ")[0] + os.system(f'cd {casa_path}/bin; ln -s casa auto_selfcal') + + if pytest: + try: + import pytest + os.system(f'cd {casa_path}/bin; ln -s casa pytest') + os.system(f'{casa_path}/bin/pip3 install --upgrade pytest') + except: + pass +except: + pass + from .auto_selfcal import auto_selfcal from .regenerate_weblog import regenerate_weblog from .split_calibrated_final import split_calibrated_final diff --git a/auto_selfcal/tests/test_auto_selfcal.py b/auto_selfcal/tests/test_auto_selfcal.py index acc8b21..7e046cb 100644 --- a/auto_selfcal/tests/test_auto_selfcal.py +++ b/auto_selfcal/tests/test_auto_selfcal.py @@ -50,7 +50,11 @@ def test_benchmark(tmp_path, dataset): os.system(f"cp -r /lustre/cv/projects/SRDP/selfcal-prototyping/datasets/{dataset}/cont.dat .") os.system(f"cp -r /lustre/cv/projects/SRDP/selfcal-prototyping/datasets/{dataset}/selfcal_library_reference.pickle .") - ex = submitit.SlurmExecutor(folder=".", python=f"OMP_NUM_THREADS=1 xvfb-run -d mpirun -n 8 {sys.executable}") + if os.getenv("CASAPATH") == None: + ex = submitit.SlurmExecutor(folder=".", python=f"OMP_NUM_THREADS=1 xvfb-run -d mpirun -n 8 {sys.executable}") + else: + casa_path = os.getenv("CASAPATH").split(" ")[0] + ex = submitit.SlurmExecutor(folder=".", python=f"xvfb-run -d {casa_path}/bin/mpicasa -n 8 {casa_path}/bin/python3") ex.update_parameters(partition="batch2", nodes=1, ntasks_per_node=8, cpus_per_task=1, use_srun=False, time=10080, \ mem="128gb", job_name=dataset) diff --git a/docs/installation.rst b/docs/installation.rst index a83f729..c378c3e 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -4,7 +4,7 @@ Installation Installing into Monolithic CASA ------------------------------- -Formal installation into monolithic CASA is not required, as we provide script versions of the main functionality of this package (see :ref:`Running in Monolithic CASA` for further details on usage). To use auto_selfcal in this way, simply download stable versions of the code on our `GitHub releases page `_. For the latest developmental version, run +Formal installation into monolithic CASA is not required, as we provide script versions of the main functionality of this package (see :ref:`Running the scripted version in Monolithic CASA` for further details on usage). To use auto_selfcal in this way, simply download stable versions of the code on our `GitHub releases page `_. For the latest developmental version, run .. code-block:: bash @@ -12,10 +12,23 @@ Formal installation into monolithic CASA is not required, as we provide script v in a terminal. The core auto_selfcal scripts now exist in the ``auto_selfcal/bin`` directory. -If you do, however, want to install into monolithic CASA, see below, under :ref:`Installing with pip`. If you opt for this route, be sure to use the ``pip`` installed with your monolithic CASA distribution (i.e. ``/bin/pip``). +It is, however, possible to pip install into monolithic CASA. If you opt for this route, be sure to use the ``pip`` installed with your monolithic CASA distribution: + +.. code-block:: bash + + /bin/pip3 install auto-selfcal + +With that done, you can also run the following command to properly set up the auto_selfcal command line tool: + +.. code-block:: bash + + /bin/casa -c "import auto_selfcal; auto_selfcal.setup_monolithic_CASA()" + +Installing into Modular CASA +---------------------------- Installing with pip -------------------- +^^^^^^^^^^^^^^^^^^^ auto_selfcal can be installed into any Python environment using the pip package manager: @@ -34,7 +47,7 @@ To install auto_selfcal with support for casampi: A note: casampi can be quite particular about versions of mpi4py and other libraries. If you are having trouble, check the included environment.yaml file, which should document a configuration that works for casa 6.6.5 (and can be used to directly create a working environment within the Anaconda package manager, see below). Installing with conda ---------------------- +^^^^^^^^^^^^^^^^^^^^^ To create an Anaconda environment into which auto_selfcal can be installed, we provide an Anaconda environment file that is capable of reproducing the necessary environment. To create an environment from this file, run: diff --git a/docs/running.rst b/docs/running.rst index 800b967..d2501a4 100644 --- a/docs/running.rst +++ b/docs/running.rst @@ -1,10 +1,10 @@ Running auto_selfcal ==================== -auto_selfcal can be run in two different modes, depending on whether you are using a modular CASA environment or a monolithic CASA distribution: +auto_selfcal can be run in multiple ways, depending on whether you are using a modular CASA environment or a monolithic CASA distribution, and whether the code was pip-installed or you are using the scripted version: -Running in Monolithic CASA --------------------------- +Running the scripted version in Monolithic CASA +----------------------------------------------- Although the structure is a little different, support remains for running auto_selfcal in a manner similar to versions 1.X within a monolithic CASA distribution. To do so, follow the instructions for :ref:`Installing into Monolithic CASA` and run: @@ -32,6 +32,47 @@ We also provide a tool to do continuum subtraction of the original MS files usin Note that with these scripts there is no support for command line arguments; to change these options, edit the bin/\*.py files directly. For details about the available parameters for each of these functions, see our :ref:`Top Level API`. +Running when pip-installed into Monolithic CASA +----------------------------------------------- + +If you pip install auto_selfcal into Monolithic CASA and properly setup the symbolic links (see :ref:`Installing into Monolithic CASA`) then the auto_selfcal command line tool should be available: + +.. code-block:: bash + + /bin/auto_selfcal -- ... + +or with mpicasa: + +.. code-block:: bash + + /bin/mpicasa -n /bin/auto_selfcal -- ... + +For the same examples as above, + +.. code-block:: bash + + /bin/mpicasa -n 5 /bin/auto_selfcal --action run + /bin/auto_selfcal --action apply + /bin/auto_selfcal --action contsub + +Alternatively, auto_selfcal can be imported into an interactive CASA session as with any Python package: + +.. code-block:: python + + from auto_selfcal import auto_selfcal, applycal_to_orig_MSes, uvcontsub_orig_MSes + + auto_selfcal(vislist=) + applycal_to_orig_MSes() + uvcontsub_orig_MSes() + +For a full list of command line options, run: + +.. code-block:: bash + + /bin/auto_selfcal --help + +or see the API documentation for the :meth:`auto_selfcal` function. + Running in Modular CASA ----------------------- diff --git a/docs/weblog.rst b/docs/weblog.rst index 1444804..771f754 100644 --- a/docs/weblog.rst +++ b/docs/weblog.rst @@ -24,7 +24,7 @@ If a weblog was not generated at the time that auto_selfcal was run, e.g. ``webl casa -c /bin/regenerate_weblog.py -In modular CASA, this can be done either via the command line tool +In modular CASA or monolithic CASA with auto_selfcal pip-installed, this can be done either via the command line tool .. code-block:: bash diff --git a/pyproject.toml b/pyproject.toml index 9e86ee7..7ef52ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [ [project.optional-dependencies] mpi = ["casampi","mpi4py<4.0.0"] -test = ["pytest","pytest-xdist","submitit"] +test = ["pytest","pytest-cov","pytest-xdist","submitit"] docs = ["sphinx","sphinx-automodapi","sphinx_book_theme","numpydoc"] [project.urls]