TeamCOMPAS / COMPAS

COMPAS rapid binary population synthesis code
http://compas.science
MIT License
64 stars 64 forks source link

Latex error on CI #1148

Open avivajpeyi opened 1 week ago

avivajpeyi commented 1 week ago

Latex is not being found on the CI yet again...

From Ilya:

I am still getting e-mails like this when I submit PRs. As far as I can tell, they are because of latex issues. Can we modify the plot labels to not use latex, even if that makes them uglier?

>               raise child_exception_type(errno_num, err_msg, err_filename)
E               FileNotFoundError: [Errno 2] No such file or directory: 'latex'

/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/subprocess.py:1837: FileNotFoundError

The above exception was the direct cause of the following exception:

example_compas_output_path = '/home/runner/work/COMPAS/COMPAS/py_tests/test_data/COMPAS_Output/COMPAS_Output.h5'
capsys = <_pytest.capture.CaptureFixture object at 0x7f65aa30dd30>
test_archive_dir = '/home/runner/work/COMPAS/COMPAS/py_tests/test_artifacts'

    def test_plotter(example_compas_output_path, capsys, test_archive_dir):
        data_path = example_compas_output_path
        bse_detailed_out_path = os.path.join(
            os.path.dirname(data_path), "Detailed_Output/BSE_Detailed_Output_0.h5"
        )
        t0 = time.time()
>       plot_detailed_evolution.run_main_plotter(
            bse_detailed_out_path, outdir=test_archive_dir, show=False
        )

py_tests/test_plot_detailed_evolution.py:14: 
....

cls = <class 'matplotlib.texmanager.TexManager'>
command = ['latex', '-interaction=nonstopmode', '--halt-on-error', '--output-directory=tmp70z5_fwk', 'd9a3c38ae9dd21d7e595745c50e22975.tex']
tex = 'lp'

    @classmethod
    def _run_checked_subprocess(cls, command, tex, *, cwd=None):
        _log.debug(cbook._pformat_subprocess(command))
        try:
            report = subprocess.check_output(
                command, cwd=cwd if cwd is not None else cls._texcache,
                stderr=subprocess.STDOUT)
        except FileNotFoundError as exc:
>           raise RuntimeError(
                f'Failed to process string with tex because {command[0]} '
                'could not be found') from exc
E           RuntimeError: Failed to process string with tex because latex could not be found

/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/matplotlib/texmanager.py:254: RuntimeError

This is not the first time this issue has occurred. https://github.com/TeamCOMPAS/COMPAS/pull/960 https://github.com/TeamCOMPAS/COMPAS/pull/990 https://github.com/TeamCOMPAS/COMPAS/pull/1087

We could try this:

def safe_save_figure(fig, filename, **kwargs):
    check_directory_exists_and_if_not_mkdir(os.path.dirname(filename))
    from matplotlib import rcParams

    try:
        fig.savefig(fname=filename, **kwargs)
    except RuntimeError:
        logger.debug("Failed to save plot with tex labels turning off tex.")
        rcParams["text.usetex"] = False
        fig.savefig(fname=filename, **kwargs)
ilyamandel commented 6 days ago

Unrelated issue, but suggest fixing both at once:

We use example_bbh_compas_config to produce a BBH for testing. However, when options change, developers update compasConfigDefault.yaml and generally forget to update compasConfigDefault.yaml.

I suggest changing the process a bit to use compasConfigDefault.yaml (default settings) but only over-write the initial conditions (see example_bbh_compas_config) as command-line arguments when testing.