Esempio n. 1
0
    def test_modak_egi_xthi(self):
        print("Test MODAK")
        m = MODAK()
        dsl_file = SCRIPT_DIR / "input" / "mpi_test_egi.json"
        model = JobModel.parse_raw(dsl_file.read_text())
        job_link = m.optimise(model.job)

        self.assertEqual(
            _tsreplaced(SCRIPT_DIR.joinpath("input/mpi_test_egi.sh").read_text()),
            _tsreplaced(pathlib.Path(job_link.jobscript).read_text()),
        )
Esempio n. 2
0
    def test_modak_ai(self):
        print("Test MODAK")
        m = MODAK()
        dsl_file = SCRIPT_DIR / "input" / "tf_snow.json"
        model = JobModel.parse_raw(dsl_file.read_text())
        job_link = m.optimise(model.job)

        self.assertEqual(
            _tsreplaced(
                SCRIPT_DIR.joinpath("input/skyline-extraction-training.sh").read_text()
            ),
            _tsreplaced(pathlib.Path(job_link.jobscript).read_text()),
        )
Esempio n. 3
0
    def test_non_git_src(self, mock__get_optimisation):
        """
        Tests a minimal job (with a build section)
        """
        mock__get_optimisation.side_effect = fake__get_optimisation

        job = Job.construct(
            job_options=JobOptions.parse_obj(
                {
                    "job_name": "test_job",
                    "node_count": 4,
                    "process_count_per_node": 2,
                    "standard_output_file": "test.out",
                    "standard_error_file": "test.err",
                    "combine_stdout_stderr": "true",
                    "copy_environment": "false",
                }
            ),
            application=Application.parse_obj(
                {
                    "executable": "./foo",
                    "build": {
                        "build_command": "sleep 1",
                        "src": "http://example/tar.gz",
                    },
                }
            ),
        )
        MODAK().get_buildjob(job)

        self.assertEqual(
            "wget --no-check-certificate 'http://example/tar.gz'\nsleep 1",
            mock__get_optimisation.call_args.args[0].application.executable,
        )
Esempio n. 4
0
    def test_minimal_no_build(self, _):
        """
        Tests a minimal job (with no build section)
        """
        job = Job.construct(
            job_options=JobOptions.parse_obj(
                {
                    "job_name": "test_job",
                    "node_count": 4,
                    "process_count_per_node": 2,
                    "standard_output_file": "test.out",
                    "standard_error_file": "test.err",
                    "combine_stdout_stderr": "true",
                }
            ),
            application=Application.parse_obj(
                {
                    "executable": "./foo",
                }
            ),
        )
        expected_return = ""
        return_value = MODAK().get_buildjob(job)

        self.assertEqual(expected_return, return_value)
Esempio n. 5
0
    def test_minimal_build(self, mock__get_optimisation):
        """
        Tests a minimal job (with a build section)
        """

        mock__get_optimisation.side_effect = fake__get_optimisation

        job = Job.construct(
            job_options=JobOptions.parse_obj(
                {
                    "job_name": "test_job",
                    "node_count": 4,
                    "process_count_per_node": 2,
                    "standard_output_file": "test.out",
                    "standard_error_file": "test.err",
                    "combine_stdout_stderr": "true",
                }
            ),
            application=Application.parse_obj(
                {
                    "executable": "./foo",
                    "build": {
                        "build_command": "sleep 1",
                        "src": "git://example/git/repo.git",
                    },
                }
            ),
        )
        return_value = MODAK().get_buildjob(job)

        calljob = deepcopy(job)
        calljob.job_options.job_name = "test_job_build"
        calljob.job_options.node_count = 1
        calljob.job_options.process_count_per_node = 1
        calljob.job_options.standard_output_file = "build-test.out"
        calljob.job_options.standard_error_file = "build-test.err"
        calljob.application.executable = "git clone git://example/git/repo.git\nsleep 1"
        self.assertEqual(return_value, FAKE__GET_OPTIMISATION_VALUE)
        mock__get_optimisation.assert_called_once()
        self.assertEqual(mock__get_optimisation.call_args.args[0], calljob)
Esempio n. 6
0
    def test_build_parallelism(self, mock__get_optimisation):
        """
        Tests a minimal job (with a build section)
        """
        mock__get_optimisation.side_effect = fake__get_optimisation

        job = Job.construct(
            job_options=JobOptions.parse_obj(
                {
                    "job_name": "test_job",
                    "node_count": 4,
                    "process_count_per_node": 2,
                    "standard_output_file": "test.out",
                    "standard_error_file": "test.err",
                    "combine_stdout_stderr": "true",
                    "copy_environment": "false",
                }
            ),
            application=Application.parse_obj(
                {
                    "executable": "./foo",
                    "build": {
                        "build_command": "sleep {{BUILD_PARALLELISM}}",
                        "src": "http://example/tar.gz",
                        "build_parallelism": 4,
                    },
                }
            ),
        )
        MODAK().get_buildjob(job)

        # get_buildjob() should take the original job as a template
        # and replace the executable with the build command
        self.assertEqual(
            "wget --no-check-certificate 'http://example/tar.gz'\nsleep 4",
            mock__get_optimisation.call_args.args[0].application.executable,
        )
Esempio n. 7
0
async def modak_get_optimisation(model: JobModel):
    m = MODAK()
    model.job.job_content = m.get_optimisation(model.job)
    return model
Esempio n. 8
0
async def get_build(model: JobModel):
    m = MODAK()
    model.job.build_script = m.get_buildjob(model.job)
    return model
Esempio n. 9
0
async def get_image(model: JobModel):
    m = MODAK()
    container_runtime = m.get_opt_container_runtime(model.job)
    model.job.application.container_runtime = container_runtime
    return model
Esempio n. 10
0
async def optimise(model: JobModel):
    m = MODAK()
    model.job.job_script, model.job.build_script = m.optimise(model.job)
    return model
Esempio n. 11
0
#!/usr/bin/env python3

import pathlib
import sys

sys.path.append(".")

from MODAK.MODAK import MODAK  # noqa:E402
from MODAK.model import JobModel  # noqa:E402

m = MODAK()
dsl_file = pathlib.Path("test/input/mpi_test.json")
dsl_content = dsl_file.read_text()
model = JobModel.parse_raw(dsl_content)
link = m.optimise(model.job)

print(link)