dcbench.common package

Submodules

dcbench.common.artifact module

class Artifact(artifact_id, **kwargs)[source]

Bases: abc.ABC

Parameters

artifact_id (str) –

Return type

None

DEFAULT_EXT: str = ''
download(force=False)[source]
Parameters

force (bool) –

classmethod from_data(data, artifact_id=None)[source]
Parameters
  • data (Any) –

  • artifact_id (Optional[str]) –

static from_yaml(loader, node)[source]
Parameters

loader (yaml.loader.Loader) –

property is_downloaded: bool
property is_uploaded: bool
isdir: bool = False
abstract load()[source]
Return type

Any

property local_path: str
property remote_url: str
abstract save(data)[source]
Parameters

data (Any) –

Return type

None

static to_yaml(dumper, data)[source]
Parameters
upload(force=False, bucket=None)[source]
Parameters
  • force (bool) –

  • bucket (Optional[storage.Bucket]) –

class ArtifactContainer(id, artifacts, attributes=None)[source]

Bases: abc.ABC, collections.abc.Mapping, dcbench.common.table.RowMixin

Parameters
  • id (str) –

  • artifacts (Mapping[str, Artifact]) –

  • attributes (Mapping[str, BASIC_TYPE]) –

artifact_specs: Mapping[str, ArtifactSpec]
container_type: str
download(force=False)[source]
Parameters

force (bool) –

Return type

bool

classmethod from_artifacts(artifacts, attributes=None, container_id=None)[source]
Parameters
  • artifacts (Mapping[str, Artifact]) –

  • attributes (Mapping[str, BASIC_TYPE]) –

  • container_id (str) –

static from_yaml(loader, node)[source]
Parameters

loader (yaml.loader.Loader) –

property is_downloaded: bool
property is_uploaded: bool
task_id: str = 'none'
static to_yaml(dumper, data)[source]
Parameters
upload(force=False, bucket=None)[source]
Parameters
  • force (bool) –

  • bucket (Optional[storage.Bucket]) –

class ArtifactSpec(description: 'str', artifact_type: 'type')[source]

Bases: object

Parameters
  • description (str) –

  • artifact_type (type) –

Return type

None

artifact_type: type
description: str
class CSVArtifact(artifact_id, **kwargs)[source]

Bases: dcbench.common.artifact.Artifact

Parameters

artifact_id (str) –

Return type

None

DEFAULT_EXT: str = 'csv'
load()[source]
Return type

pandas.core.frame.DataFrame

save(data)[source]
Parameters

data (pandas.core.frame.DataFrame) –

Return type

None

class DataPanelArtifact(artifact_id, **kwargs)[source]

Bases: dcbench.common.artifact.Artifact

Parameters

artifact_id (str) –

Return type

None

DEFAULT_EXT: str = 'mk'
isdir: bool = True
load()[source]
Return type

pandas.core.frame.DataFrame

save(data)[source]
Parameters

data (meerkat.datapanel.DataPanel) –

Return type

None

class ModelArtifact(artifact_id, **kwargs)[source]

Bases: dcbench.common.artifact.Artifact

Parameters

artifact_id (str) –

Return type

None

DEFAULT_EXT: str = 'pt'
load()[source]
Return type

dcbench.common.modeling.Model

save(data)[source]
Parameters

data (dcbench.common.modeling.Model) –

Return type

None

class VisionDatasetArtifact(artifact_id, **kwargs)[source]

Bases: dcbench.common.artifact.DataPanelArtifact

Parameters

artifact_id (str) –

Return type

None

COLUMN_SUBSETS = {'celeba': ['id', 'image', 'identity', 'split'], 'imagenet': ['id', 'image', 'name', 'synset']}
DEFAULT_EXT: str = 'mk'
download(force=False)[source]
Parameters

force (bool) –

classmethod from_name(name)[source]
Parameters

name (str) –

isdir: bool = True
class YAMLArtifact(artifact_id, **kwargs)[source]

Bases: dcbench.common.artifact.Artifact

Parameters

artifact_id (str) –

Return type

None

DEFAULT_EXT: str = 'yaml'
load()[source]
Return type

pandas.core.frame.DataFrame

save(data)[source]
Parameters

data (Any) –

Return type

None

dcbench.common.download_utils module

This file contains utility functions for downloading datasets. The code in this file is taken from the torchvision package, specifically, https://github.com/pytorch/vision/blob/master/torchvision/datasets/utils.py. We package it here to avoid users having to install the rest of torchvision. It is licensed under the following license:

BSD 3-Clause License

Copyright (c) Soumith Chintala 2016, All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS β€œAS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

calculate_md5(fpath, chunk_size=1048576)[source]
Parameters
  • fpath (str) –

  • chunk_size (int) –

Return type

str

check_integrity(fpath, md5=None)[source]
Parameters
  • fpath (str) –

  • md5 (Optional[str]) –

Return type

bool

check_md5(fpath, md5, **kwargs)[source]
Parameters
  • fpath (str) –

  • md5 (str) –

  • kwargs (Any) –

Return type

bool

download_and_extract_archive(url, download_root, extract_root=None, filename=None, md5=None, remove_finished=False, size=None)[source]
Parameters
  • url (str) –

  • download_root (str) –

  • extract_root (Optional[str]) –

  • filename (Optional[str]) –

  • md5 (Optional[str]) –

  • remove_finished (bool) –

  • size (Optional[int]) –

Return type

None

download_file_from_google_drive(file_id, root, filename=None, md5=None)[source]

Download a Google Drive file from and place it in root.

Parameters
  • file_id (str) – id of file to be downloaded

  • root (str) – Directory to place downloaded file in

  • filename (str, optional) – Name to save the file under. If None, use the id of the file.

  • md5 (str, optional) – MD5 checksum of the download. If None, do not check

download_url(url, root, filename=None, md5=None, size=None)[source]

Download a file from a url and place it in root.

Parameters
  • url (str) – URL to download file from

  • root (str) – Directory to place downloaded file in

  • filename (str, optional) – Name to save the file under. If None, use the basename of the URL

  • md5 (str, optional) – MD5 checksum of the download. If None, do not check

  • size (Optional[int]) –

Return type

None

extract_archive(from_path, to_path=None, remove_finished=False)[source]
Parameters
  • from_path (str) –

  • to_path (Optional[str]) –

  • remove_finished (bool) –

Return type

None

gen_bar_updater(total)[source]
Return type

Callable[[int, int, int], None]

iterable_to_str(iterable)[source]
Parameters

iterable (Iterable) –

Return type

str

list_dir(root, prefix=False)[source]

List all directories at a given root.

Parameters
  • root (str) – Path to directory whose folders need to be listed

  • prefix (bool, optional) – If true, prepends the path to each result, otherwise only returns the name of the directories found

Return type

List[str]

list_files(root, suffix, prefix=False)[source]

List all files ending with a suffix at a given root.

Parameters
  • root (str) – Path to directory whose folders need to be listed

  • suffix (str or tuple) – Suffix of the files to match, e.g. β€˜.png’ or (β€˜.jpg’, β€˜.png’). It uses the Python β€œstr.endswith” method and is passed directly

  • prefix (bool, optional) – If true, prepends the path to each result, otherwise only returns the name of the files found

Return type

List[str]

verify_str_arg(value, arg=None, valid_values=None, custom_msg=None)[source]
Parameters
  • value (dcbench.common.download_utils.T) –

  • arg (Optional[str]) –

  • valid_values (Optional[Iterable[dcbench.common.download_utils.T]]) –

  • custom_msg (Optional[str]) –

Return type

dcbench.common.download_utils.T

dcbench.common.method module

class Method(config=None, **kwargs)[source]

Bases: abc.ABC

Parameters

config (dict) –

class Config(n_slices: int = 5, emb_group: str = 'main', emb: str = 'emb', xmodal_emb: str = 'emb')[source]

Bases: object

Parameters
  • n_slices (int) –

  • emb_group (str) –

  • emb (str) –

  • xmodal_emb (str) –

Return type

None

emb: str = 'emb'
emb_group: str = 'main'
n_slices: int = 5
xmodal_emb: str = 'emb'
RESOURCES_REQUIRED = {'cpu': 1, 'custom_resources': {'ram_gb': 4}}

dcbench.common.problem module

class Problem(id, artifacts, attributes=None)[source]

Bases: dcbench.common.artifact.ArtifactContainer

Parameters
  • id (str) –

  • artifacts (Mapping[str, Artifact]) –

  • attributes (Mapping[str, BASIC_TYPE]) –

artifact_specs: Mapping[str, ArtifactSpec]
container_type: str = 'problem'
abstract evaluate(solution)[source]
Parameters

solution (Solution) –

name: str
solution_class: type
summary: str

dcbench.common.result module

class Result[source]

Bases: object

dcbench.common.solution module

class Result(source)[source]

Bases: Mapping

static load(path)[source]
Parameters

path (str) –

Return type

dcbench.common.solution.Result

save(path)[source]
Parameters

path (str) –

Return type

None

class Solution(id, artifacts, attributes=None)[source]

Bases: dcbench.common.artifact.ArtifactContainer

Parameters
  • id (str) –

  • artifacts (Mapping[str, Artifact]) –

  • attributes (Mapping[str, BASIC_TYPE]) –

artifact_specs: Mapping[str, ArtifactSpec]
container_type: str = 'solution'

dcbench.common.solve module

dcbench.common.utils module

Module contents