def test_amdahl_basic():
    """Test that the Amdahl scaling model works"""

    amdahl = ScalingModelAmdahl(name="amdahl", F=0.5)
    app = Application.construct(mpi_ranks=256, minimal_efficiency=0.2)
    assert amdahl.scale(app)
    assert app.mpi_ranks == 9

    amdahl = ScalingModelAmdahl(name="amdahl", F=0.999)
    app = Application.construct(mpi_ranks=256, minimal_efficiency=0.8)
    assert amdahl.scale(app)
    assert app.mpi_ranks == 251
Example #2
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,
        )
Example #3
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)
def test_add_optscript():
    TEST_STRING = """## OPTSCRIPT here ##"""

    outfile = io.StringIO()
    jg = jobfile_generator.JobfileGenerator(
        # construct empty invalid objects, because we know here we don't need them:
        application=Application.construct(),
        job_options=JobOptions.construct(),
        batch_fhandle=outfile,
        scheduler="torque",
    )

    jg.add_optscript(
        Script(
            id=uuid.uuid4(),
            conditions={},
            data={
                "stage": "pre",
                "raw": TEST_STRING
            },
        ),
        {},
    )

    # If everything worked correctly, our test line should have been
    # inserted into the output file by attempting to add an option script.
    assert TEST_STRING in outfile.getvalue()
def test_add_optscript_jinja2():
    """Verify that the jobscript generator does jinja2 replacement according to the dict"""

    outfile = io.StringIO()

    jg = jobfile_generator.JobfileGenerator(
        # construct empty invalid objects, because we know here we don't need them:
        application=Application.construct(),
        job_options=JobOptions.construct(),
        batch_fhandle=outfile,
        scheduler="torque",
    )

    jg.add_optscript(
        Script(
            id=uuid.uuid4(),
            conditions={},
            data={
                "stage":
                "pre",
                "raw":
                "cp -R data/ {{ preferred_storage_location.replace('file://', '') }}/",
            },
        ),
        {"preferred_storage_location": "/var/tmp"},
    )

    assert "cp -R data/ /var/tmp/" in outfile.getvalue()
def test_amdahl_max():
    """Test that the Amdahl scaling model obeys the given max number of ranks"""

    amdahl = ScalingModelAmdahl(name="amdahl", F=0.999)
    app = Application.construct(mpi_ranks=256, minimal_efficiency=0.1)
    assert amdahl.scale(app)
    assert app.mpi_ranks == 256  # capped by the given number of mpi ranks
def test_scaler_max(dbengine):
    driver = Driver(dbengine)

    stmt = insert(db.Optimisation).values(
        opt_dsl_code="test01",
        app_name="testapp",
        target="enable_opt_build:false",
    )
    driver.update_sql(stmt)

    MAX_NRANKS = 16
    MAX_NTHREADS = 4

    stmt = insert(db.ScalingModel).values(
        opt_dsl_code="test01",
        model={
            "name": "max",
            "max_nranks": MAX_NRANKS,
            "max_nthreads": MAX_NTHREADS
        },
    )
    driver.update_sql(stmt)

    scaler = Scaler(driver)
    app = Application.construct(app_tag="testapp", mpi_ranks=256, threads=8)
    assert scaler.scale(app)  # the scaling should run
    assert app.mpi_ranks == MAX_NRANKS
    assert app.threads == MAX_NTHREADS
def test_enforce_infra_storage_pref(dbengine):
    """
    Check that Enforcer.enforce_opt returns the storage location from an infra
    """

    driver = Driver(dbengine)
    enforcer = Enforcer(driver)

    infra = InfrastructureIn(
        name="testinfra",
        configuration={
            "storage": {
                "file:///var/tmp": {
                    "storage_class": "default-ssd"
                },
                "file:///data": {
                    "storage_class": "default-common"
                },
            }
        },
    )
    stmt = insert(db.Infrastructure).values(**infra.dict())
    driver.update_sql(stmt)

    _, tenv = enforcer.enforce_opt(
        "fancy",
        Job.construct(
            target=Target(name="testinfra", job_scheduler_type="slurm"),
            application=Application.construct(storage_class_pref=None),
        ),
        ["myfeat:true"],
    )

    # no spec will return the "slowest" (cheaptest) storage class first
    assert tenv["preferred_storage_location"] == "file:///data"

    _, tenv = enforcer.enforce_opt(
        "fancy",
        Job.construct(
            target=Target(name="testinfra", job_scheduler_type="slurm"),
            application=Application.construct(
                storage_class_pref="default-ssd"),
        ),
        ["myfeat:true"],
    )

    assert tenv["preferred_storage_location"] == "file:///var/tmp"
def test_amdahl_correctness():
    """Verify that the proposed number of ranks matches the scaling"""

    amdahl = ScalingModelAmdahl(name="amdahl", F=0.8)
    app = Application.construct(mpi_ranks=256, minimal_efficiency=0.5)
    assert amdahl.scale(app)
    assert app.mpi_ranks < 256
    assert app.mpi_ranks > 1
    assert amdahl.efficiency(app.mpi_ranks) == pytest.approx(0.5, 1e-6)
def test_scaler_no_model(dbengine):
    driver = Driver(dbengine)

    stmt = insert(db.Optimisation).values(
        opt_dsl_code="test01",
        app_name="testapp",
        target="enable_opt_build:false",
    )
    driver.update_sql(stmt)

    scaler = Scaler(driver)
    app = Application.construct(app_tag="testapp", mpi_ranks=256)
    assert not scaler.scale(app)
Example #11
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)
Example #12
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,
        )
def test_enforce_infra_storage_script(dbengine):
    """
    Check that Enforcer.enforce_opt returns an infra- & storage-conditioned script
    """

    driver = Driver(dbengine)
    enforcer = Enforcer(driver)

    # insert a script which should be enabled if the chosen infra provides this storage_class

    script = ScriptIn(
        conditions={
            "infrastructure": {
                "name": "testinfra",
                "storage_class": "default-ssd"
            }
        },
        data={
            "stage": "pre",
            "raw": "echo 'hello any storage'"
        },
    )
    stmt = insert(db.Script).values(**script.dict())
    driver.update_sql(stmt)

    scripts, _ = enforcer.enforce_opt(
        "inexistentapp",
        Job.construct(
            target=Target(name="testinfra", job_scheduler_type="slurm")),
        [],
    )

    assert not scripts, "script returned despite no infrastructure entry"

    infra = InfrastructureIn(
        name="testinfra",
        configuration={
            "storage": {
                "file:///var/tmp": {
                    "storage_class": "default-ssd"
                }
            }
        },
    )
    stmt = insert(db.Infrastructure).values(**infra.dict())
    driver.update_sql(stmt)

    scripts, _ = enforcer.enforce_opt(
        "fancy",
        Job.construct(
            target=Target(name="testinfra", job_scheduler_type="slurm"),
            application=Application.construct(storage_class_pref=None),
        ),
        ["myfeat:true"],
    )

    assert scripts, "scripts not found"

    # insert a script which should be enabled if the chosen infra provides this storage_class
    script = ScriptIn(
        conditions={
            "infrastructure": {
                "storage_class": "default-ssd"
            },
            "application": {
                "name": "testapp"
            },
        },
        data={
            "stage": "pre",
            "raw": "echo 'hello ssd-only'"
        },
    )
    stmt = insert(db.Script).values(**script.dict())
    driver.update_sql(stmt)

    scripts, _ = enforcer.enforce_opt(
        "testapp",
        Job.construct(
            target=Target(name="testinfra", job_scheduler_type="slurm"),
            application=Application.construct(storage_class_pref=None),
        ),
        [],
    )
    assert len(scripts) == 2, "scripts not found"
def test_amdahl_noop():
    """Test that the Amdahl scaling model doesn't do anything without an efficiency"""

    amdahl = ScalingModelAmdahl(name="amdahl", F=0.999)
    app = Application.construct(mpi_ranks=256)
    assert not amdahl.scale(app)  # without an efficiency Amdahl should not run
def test_noop():
    """Test that the noop model always returns false"""

    appmodel_noop = ApplicationScalingModelIn(opt_dsl_code="",
                                              model={"name": "noop"})
    assert not appmodel_noop.model.scale(Application.construct())
def test_scaler_no_dsl_code(dbengine):
    driver = Driver(dbengine)

    scaler = Scaler(driver)
    app = Application.construct(app_tag="testapp", mpi_ranks=256)
    assert not scaler.scale(app)