Ejemplo n.º 1
0
    def get_parameter(self, project_name, experiment_id, parameter_name):
        """Retrieve a parameter from the configured filesystem.

        Parameters
        ----------
        project_name : str
            The name of the project this parameter belongs to.
        experiment_id : str
            The ID of the experiment the parameter with name
            `parameter_name` is logged to.
        parameter_name : str
            The name of the parameter to retrieve.

        Returns
        -------
        rubicon.domain.Parameter
            The parameter with name `parameter_name`.
        """
        parameter_metadata_path = self._get_parameter_metadata_path(
            project_name, experiment_id, parameter_name)

        try:
            open_file = self.filesystem.open(parameter_metadata_path)
        except FileNotFoundError:
            raise RubiconException(
                f"No parameter with name '{parameter_name}' found.")

        with open_file as f:
            parameter = json.load(f)

        return domain.Parameter(**parameter)
Ejemplo n.º 2
0
    def get_parameters(self, project_name, experiment_id):
        """Retrieve all parameters from the configured filesystem
        that belong to the experiment with ID `experiment_id`.

        Parameters
        ----------
        project_name : str
            The name of the project the experiment with ID
            `experiment_id` is logged to.
        experiment_id : str
            The ID of the experiment to retrieve all parameters
            from.

        Returns
        -------
        list of rubicon.domain.Parameter
            The parameters logged to the experiment with ID
            `experiment_id`.
        """
        parameter_metadata_root = self._get_parameter_metadata_root(
            project_name, experiment_id)

        try:
            parameter_metadata_paths = self._ls_directories_only(
                parameter_metadata_root)
            parameters = [
                domain.Parameter(**json.loads(data)) for data in
                self.filesystem.cat(parameter_metadata_paths).values()
            ]
        except FileNotFoundError:
            return []

        return parameters
Ejemplo n.º 3
0
    def log_parameter(self, name, value=None, description=None):
        """Create a parameter under the experiment.

        Parameters
        ----------
        name : str
            The parameter's name.
        value : object, optional
            The parameter's value. Can be an object of any JSON
            serializable (via rubicon.utils.DomainJSONEncoder)
            type.
        description : str, optional
            The parameter's description. Use to provide
            additional context.

        Returns
        -------
        rubicon.client.Parameter
            The created parameter.
        """
        parameter = domain.Parameter(name,
                                     value=value,
                                     description=description)
        self.repository.create_parameter(parameter, self.project.name, self.id)

        return Parameter(parameter, self._config)
Ejemplo n.º 4
0
    async def get_parameter(self, project_name, experiment_id, parameter_name):
        """Overrides `rubicon.repository.BaseRepository.get_parameter` to
        asynchronously retrieve a parameter from the configured filesystem.

        Parameters
        ----------
        project_name : str
            The name of the project this parameter belongs to.
        experiment_id : str
            The ID of the experiment the parameter with name
            `parameter_name` is logged to.
        parameter_name : str
            The name of the parameter to retrieve.

        Returns
        -------
        rubicon.domain.Parameter
            The parameter with name `parameter_name`.
        """
        parameter_metadata_path = self._get_parameter_metadata_path(
            project_name, experiment_id, parameter_name)

        try:
            parameter = json.loads(
                await self.filesystem._cat_file(parameter_metadata_path))
        except FileNotFoundError:
            raise RubiconException(
                f"No parameter with name '{parameter_name}' found.")

        return domain.Parameter(**parameter)
Ejemplo n.º 5
0
    async def get_parameters(self, project_name, experiment_id):
        """Overrides `rubicon.repository.BaseRepository.get_parameters` to
        asynchronously retrieve all parameters from the configured filesystem
        that belong to the experiment with ID `experiment_id`.

        Parameters
        ----------
        project_name : str
            The name of the project the experiment with ID
            `experiment_id` is logged to.
        experiment_id : str
            The ID of the experiment to retrieve all parameters
            from.

        Returns
        -------
        list of rubicon.domain.Parameter
            The parameters logged to the experiment with ID
            `experiment_id`.
        """
        parameter_metadata_root = self._get_parameter_metadata_root(project_name, experiment_id)

        try:
            parameter_metadata_paths = await self._ls_directories_only(parameter_metadata_root)
            parameters = [
                domain.Parameter(**json.loads(data))
                for data in await asyncio.gather(
                    *[self.filesystem._cat_file(path) for path in parameter_metadata_paths]
                )
            ]
        except FileNotFoundError:
            return []

        return parameters
Ejemplo n.º 6
0
def _create_parameter(repository, experiment=None):
    if experiment is None:
        experiment = _create_experiment(repository)

    parameter = domain.Parameter(name=f"Test Parameter {uuid.uuid4()}",
                                 value=8)
    repository.create_parameter(parameter, experiment.project_name,
                                experiment.id)

    return parameter
Ejemplo n.º 7
0
def test_properties():
    domain_parameter = domain.Parameter("name",
                                        value="value",
                                        description="description")
    parameter = Parameter(domain_parameter)

    assert parameter.id == domain_parameter.id
    assert parameter.name == domain_parameter.name
    assert parameter.value == domain_parameter.value
    assert parameter.description == domain_parameter.description
    assert parameter.created_at == domain_parameter.created_at
Ejemplo n.º 8
0
def test_to_dask_df(asyn_client_w_mock_repo):
    rubicon = asyn_client_w_mock_repo

    project_name = f"Test Project {uuid.uuid4()}"
    project = asyncio.run(rubicon.create_project(project_name))

    experiment_domains = [
        domain.Experiment(project_name=project_name,
                          name=f"Test Experiment {uuid.uuid4()}")
        for _ in range(0, 2)
    ]

    parameter_domains = [domain.Parameter("n_components")]
    metric_domains = [domain.Metric("accuracy", 90)]

    rubicon.repository.get_experiments.return_value = experiment_domains
    rubicon.repository.get_tags.return_value = [{
        "added_tags": [],
        "removed_tags": []
    }]
    rubicon.repository.get_parameters.return_value = parameter_domains
    rubicon.repository.get_metrics.return_value = metric_domains

    ddf = asyncio.run(project.to_dask_df())
    df = ddf.compute()

    # check that all experiments made it into df
    assert len(df) == 2

    # check the cols within the df
    exp_details = [
        "id", "name", "description", "model_name", "commit_hash", "tags",
        "created_at"
    ]
    for detail in exp_details:
        assert detail in df.columns
Ejemplo n.º 9
0
def _create_parameter_domain(experiment=None):
    if experiment is None:
        project = domain.Project(f"Test Project {uuid.uuid4()}")
        experiment = _create_experiment_domain(project)

    return experiment, domain.Parameter(name="test parameter", value=0)