Ejemplo n.º 1
0
def ingest_to_search(name, path, idx="dlhub-test"):
    """Ingests the model metadata into Globus Search
    Args:
        name (str): The model name. (generally the same as container directory name
                    but not always) e.g. "cifar10"
        path (str): Path to the model metadata. e.g. "metadata/cifar10.json"
        idx (str): The Globus Index to upload search metadata to. Defaults=dlhub-test
    """
    if path == None:
        return
    dl = client.DLHub()
    uuid = dl.get_id_by_name(name)
    iden = "https://dlhub.org/api/v1/servables/{}".format(uuid)
    index = mdf_toolbox.translate_index(idx)

    with open(path, 'r') as f:
        ingestable = json.load(f)

    ingestable = mdf_toolbox.format_gmeta(ingestable,
                                          acl="public",
                                          identifier=iden)
    ingestable = mdf_toolbox.format_gmeta(
        [ingestable])  # Make it a GIngest list of GMetaEntry

    ingest_client = mdf_toolbox.login(
        services=["search_ingest"])["search_ingest"]
    ingest_client.ingest(index, ingestable)
    print("Ingestion of {} to DLHub servables complete".format(name))
def test_run():
    dl = client.DLHub()
    name = "zhuozhao_test_noop"
    data = {"data": ["V", "Co", "Zr"]}
    serv = dl.get_id_by_name(name)
    res = dl.run(serv, data)

    # Check the results
    assert isinstance(res, pandas.DataFrame)
def test_get_id_by_name():
    dl = client.DLHub()
    name = "oqmd_model"
    r = dl.get_id_by_name(name)
    r2 = dl.get_servables()
    true_val = r2["uuid"][r2["name"].tolist().index(name)]
    assert r == true_val

    # Invalid name
    with pytest.raises(IndexError):
        dl.get_id_by_name("foo")
def test_submit():
    dl = client.DLHub()

    # Make an example function
    model = PythonStaticMethodModel('numpy.linalg', 'norm')
    model.set_name('1d_norm')
    model.set_title('Norm of a 1D Array')
    model.set_inputs('ndarray', 'Array to be normed', shape=[None])
    model.set_outputs('number', 'Norm of the array')

    # Submit the model
    dl.submit_servable(model)
Ejemplo n.º 5
0
def ingest_to_search(name, path, idx):
    if path == None:
        return
    dl = client.DLHub()
    uuid = dl.get_id_by_name(name)
    iden = "https://dlhub.org/api/v1/servables/{}".format(uuid)
    index = mdf_toolbox.translate_index(idx)

    with open(path, 'r') as f:
        ingestable = json.load(f)

    ingestable = mdf_toolbox.format_gmeta(ingestable,
                                          acl="public",
                                          identifier=iden)
    ingestable = mdf_toolbox.format_gmeta(
        [ingestable])  # Make it a GIngest list of GMetaEntry

    ingest_client = mdf_toolbox.login(
        services=["search_ingest"])["search_ingest"]
    ingest_client.ingest(index, ingestable)
    print("Ingestion of {} complete".format(name))
def test_dlhub_init():
    dl = client.DLHub()
    assert dl.service == "https://dlhub.org/api/v1"
    assert isinstance(dl, client.DLHub)
def test_get_servables():
    dl = client.DLHub()
    r = dl.get_servables()
    assert isinstance(r, pandas.DataFrame)
    assert r.shape[-1] > 0
    assert r.shape[0] != 0