コード例 #1
0
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
コード例 #2
0
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()
コード例 #3
0
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()
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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"
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
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"
コード例 #10
0
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
コード例 #11
0
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())
コード例 #12
0
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)