def get_feature(self, project_name, experiment_id, feature_name): """Retrieve a feature from the configured filesystem. 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 the feature with name `feature_name` is logged to. feature_name : str The name of the feature to retrieve. Returns ------- rubicon.domain.Feature The feature with name `feature_name`. """ feature_metadata_path = self._get_feature_metadata_path( project_name, experiment_id, feature_name) try: open_file = self.filesystem.open(feature_metadata_path) except FileNotFoundError: raise RubiconException( f"No feature with name '{feature_name}' found.") with open_file as f: feature = json.load(f) return domain.Feature(**feature)
def get_features(self, project_name, experiment_id): """Retrieve all features 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 features from. Returns ------- list of rubicon.domain.Feature The features logged to the experiment with ID `experiment_id`. """ feature_metadata_root = self._get_feature_metadata_root( project_name, experiment_id) try: feature_metadata_paths = self._ls_directories_only( feature_metadata_root) features = [ domain.Feature(**json.loads(data)) for data in self.filesystem.cat(feature_metadata_paths).values() ] except FileNotFoundError: return [] return features
def test_get_parameters(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 = asyncio.run(project.log_experiment()) parameter_name = f"test parameter {uuid.uuid4()}" parameter_domains = [ domain.Feature(name=f"{parameter_name} {i}") for i in range(0, 3) ] rubicon.repository.get_parameters.return_value = parameter_domains parameters = asyncio.run(experiment.parameters()) expected = [call.get_parameters(project_name, experiment.id)] parameter_ids = [p.id for p in parameters] for parameter_id in [p.id for p in parameter_domains]: assert parameter_id in parameter_ids parameter_ids.remove(parameter_id) assert len(parameter_ids) == 0 assert rubicon.repository.mock_calls[2:] == expected
async def get_feature(self, project_name, experiment_id, feature_name): """Overrides `rubicon.repository.BaseRepository.get_feature` to asynchronously retrieve a feature from the configured filesystem. 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 the feature with name `feature_name` is logged to. feature_name : str The name of the feature to retrieve. Returns ------- rubicon.domain.Feature The feature with name `feature_name`. """ feature_metadata_path = self._get_feature_metadata_path( project_name, experiment_id, feature_name) try: feature = json.loads( await self.filesystem._cat_file(feature_metadata_path)) except FileNotFoundError: raise RubiconException( f"No feature with name '{feature_name}' found.") return domain.Feature(**feature)
def test_get_features(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 = asyncio.run(project.log_experiment()) feature_name = f"test feature {uuid.uuid4()}" feature_domains = [ domain.Feature(name=f"{feature_name} {i}") for i in range(0, 3) ] rubicon.repository.get_features.return_value = feature_domains features = asyncio.run(experiment.features()) expected = [call.get_features(project_name, experiment.id)] feature_ids = [f.id for f in features] for feature_id in [f.id for f in feature_domains]: assert feature_id in feature_ids feature_ids.remove(feature_id) assert len(feature_ids) == 0 assert rubicon.repository.mock_calls[2:] == expected
def test_get_metrics(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 = asyncio.run(project.log_experiment()) metric_name = f"test metric {uuid.uuid4()}" metric_domains = [ domain.Feature(name=f"{metric_name} {i}") for i in range(0, 3) ] rubicon.repository.get_metrics.return_value = metric_domains metrics = asyncio.run(experiment.metrics()) expected = [call.get_metrics(project_name, experiment.id)] metric_ids = [m.id for m in metrics] for metric_id in [m.id for m in metric_domains]: assert metric_id in metric_ids metric_ids.remove(metric_id) assert len(metric_ids) == 0 assert rubicon.repository.mock_calls[2:] == expected
async def log_feature(self, name, description=None, importance=None): """Overrides `rubicon.client.Experiment.log_feature` to asynchronously create a feature under the experiment. Parameters ---------- name : str The features's name. description : str The feature's description. Use to provide additional context. importance : float The feature's importance. Returns ------- rubicon.client.Feature The created feature. """ feature = domain.Feature(name, description=description, importance=importance) await self.repository.create_feature(feature, self.project.name, self.id) return Feature(feature, self._config)
async def get_features(self, project_name, experiment_id): """Overrides `rubicon.repository.BaseRepository.get_features` to asynchronously retrieve all features 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 features from. Returns ------- list of rubicon.domain.Feature The features logged to the experiment with ID `experiment_id`. """ feature_metadata_root = self._get_feature_metadata_root(project_name, experiment_id) try: feature_metadata_paths = await self._ls_directories_only(feature_metadata_root) features = [ domain.Feature(**json.loads(data)) for data in await asyncio.gather( *[self.filesystem._cat_file(path) for path in feature_metadata_paths] ) ] except FileNotFoundError: return [] return features
def _create_feature(repository, experiment=None): if experiment is None: experiment = _create_experiment(repository) feature = domain.Feature(name=f"Test Feature {uuid.uuid4()}") repository.create_feature(feature, experiment.project_name, experiment.id) return feature
def test_properties(): domain_feature = domain.Feature("age", description="That age tho", importance=0.5) feature = Feature(domain_feature) assert feature.name == "age" assert feature.description == "That age tho" assert feature.importance == 0.5 assert feature.id == domain_feature.id assert feature.created_at == domain_feature.created_at
def _create_feature_domain(experiment=None): if experiment is None: project = domain.Project(f"Test Project {uuid.uuid4()}") experiment = _create_experiment_domain(project) return experiment, domain.Feature(name="test feature")