예제 #1
0
def test_workflow_matmul_topheavy_complicated():
    A = np.array([[1, 2], [2, 1]])
    B = np.array([[-3, 1], [-3, 0.5]])

    mm1 = MatMul(name="mm1")
    mm2 = MatMul(name="mm2")
    mm3 = MatMul(name="mm3")
    mm4 = MatMul(name="mm4")
    mm5 = MatMul(name="mm5")
    mm6 = MatMul(name="mm6")

    mm1.requires(a=A, b=B)
    mm2.requires(a=A, b=mm1)
    mm3.requires(a=A, b=B)
    mm4.requires(a=A, b=B)
    mm5.requires(a=A, b=B)
    mm6.requires(a=mm4, b=mm5)

    results = mtr.Workflow(mm1, mm2, mm3, mm4, mm5, mm6).compute().results

    assert np.allclose(results["mm1"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm2"], np.array([[-27, 7], [-27, 6.5]]))
    assert np.allclose(results["mm3"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm4"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm5"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm6"], np.array([[63, -13], [58.5, -11.75]]))
예제 #2
0
def test_workflow_matmul_complicated():
    A = np.array([[1, 2], [2, 1]])
    B = np.array([[-3, 1], [-3, 0.5]])

    mm1 = MatMul(name="mm1")
    mm2 = MatMul(name="mm2")
    mm3 = MatMul(name="mm3")
    mm4 = MatMul(name="mm4")
    mm5 = MatMul(name="mm5")

    mm1.requires(a=A, b=B)
    mm2.requires(a=A, b=B)
    mm3.requires(a=mm1, b=mm2)
    mm4.requires(a=mm2, b=mm3)
    mm5.requires(a=mm4, b=mm1)

    results = mtr.Workflow(mm1, mm2, mm3, mm4, mm5).compute().results

    assert np.allclose(results["mm1"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm2"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm3"], np.array([[63, -13], [58.5, -11.75]]))
    assert np.allclose(results["mm4"], np.array([[-450, 93.5], [-420.75, 87.625]]))
    assert np.allclose(
        results["mm5"], np.array([[3208.5, -666.25], [2998.125, -622.4375]])
    )
예제 #3
0
def test_workflow_multiply_linear():
    mul1 = Mul(name="mul1")
    mul1.requires(a=2, b=3)

    mul2 = Mul(name="mul2")
    mul2.requires(a=mul1, b=-1)

    mul3 = Mul(name="mul3")
    mul3.requires(a=10, b=mul2)

    wf = mtr.Workflow(mul1, mul2, mul3)
    results = wf.compute().results
    assert results["mul1"] == 6
    assert results["mul2"] == -6
    assert results["mul3"] == -60
예제 #4
0
def test_workflow_matmul_linear():
    A = np.array([[1, 2], [2, 1]])
    B = np.array([[-3, 1], [-3, 0.5]])

    mm1 = MatMul(name="mm1")
    mm2 = MatMul(name="mm2")
    mm3 = MatMul(name="mm3")

    mm1.requires(a=A, b=B)
    mm2.requires(a=B, b=A)
    mm3.requires(a=mm1, b=mm2)

    results = mtr.Workflow(mm1, mm2, mm3).compute().results

    assert np.allclose(results["mm1"], np.array([[-9, 2], [-9, 2.5]]))
    assert np.allclose(results["mm2"], np.array([[-1, -5], [-2, -5.5]]))
    assert np.allclose(results["mm3"], np.array([[5, 34], [4, 31.25]]))
예제 #5
0
def test_no_duplicates():
    def _f(x, y):
        return x + y

    def _g(x, y):
        return x * y

    mock = unittest.mock.Mock(return_value=4)
    f = mtr.FunctionTask(mock, name="f")
    g = mtr.FunctionTask(_g, name="g")

    f.requires(x=1, y=3)
    g.requires(x=f, y=-1)

    wf = mtr.Workflow(g)
    wf.compute()

    mock.assert_called_once()
예제 #6
0
import materia as mtr

if __name__ == "__main__":
    f1 = mtr.FunctionTask(lambda x: x**2)
    f2 = mtr.FunctionTask(lambda x: x + 1)

    f1.requires(x=10)
    f2.requires(x=f1)

    wf = mtr.Workflow(f1, f2)
    print(wf.run(1))
예제 #7
0
def h(a, b):
    return a + 2 * b


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--dask_scratch", type=str)
    args = parser.parse_args()

    t1 = mtr.FunctionTask(f)
    t1.requires(x=13, y=7, z=3)

    t2 = mtr.FunctionTask(g)
    t2.requires(a=t1, b=2)

    t3 = mtr.FunctionTask(h)
    t3.requires(a=11, b=t1)

    w = mtr.Workflow(t2, t3)

    cluster = dask.distributed.LocalCluster()

    with dask.config.set(temporary_directory=args.dask_scratch):
        with dask.distributed.Client(cluster) as client:
            results = w.compute()

            restarted_results = w.compute(restart=results)

    print(results)
    print(restarted_results)
예제 #8
0
파일: ex1.py 프로젝트: kijanac/materia
import argparse
import materia as mtr

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--packmol", metavar="packmol", type=str, default="packmol")
    args = parser.parse_args()

    packmol = mtr.Packmol(args.packmol)

    pack = mtr.PackmolSolvate(
        shells=3,
        tolerance=2.0,
        engine=packmol,
        io=mtr.IO("pack.in", "pack.out", temp=True),
        mass_density=789 * mtr.kg / mtr.m ** 3,
    )
    solute = mtr.Structure.generate(
        smiles="CCN1C(=CC=CC2=[N+](C3=CC=CC=C3C=C2)CC)C=CC4=CC=CC=C41.[I-]"
    )
    solvent = mtr.Structure.retrieve(name="ethanol")

    pack.requires(solute=solute, solvent=solvent)

    results = mtr.Workflow(pack).run(available_cores=1)
    print(results)
예제 #9
0
import argparse
import materia as mtr
import dask.distributed

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--qcenv", type=str)
    parser.add_argument("--scratch", type=str)
    parser.add_argument("--dask_scratch", type=str)
    parser.add_argument("--num_evals", type=int)
    args = parser.parse_args()

    m = mtr.Molecule("benzene")

    qchem = mtr.QChem(qcenv=args.qcenv, scratch_dir=args.scratch)

    io = mtr.IO("gs.in", "gs.out", "minimize_koopman_error")

    min_ke = qchem.minimize_koopman_error(io, name="min_ke")
    min_ke.requires(molecule=m, num_evals=args.num_evals)

    wf = mtr.Workflow(min_ke)

    cluster = dask.distributed.LocalCluster()
    with dask.config.set(temporary_directory=args.dask_scratch):
        with dask.distributed.Client(cluster) as client:
            print(wf.compute()["min_ke"])