def test_set_experiment(): with pytest.raises(TypeError): mlflow.set_experiment() with pytest.raises(Exception): mlflow.set_experiment(None) with pytest.raises(Exception): mlflow.set_experiment("") try: with TempDir() as tracking_uri: tracking.set_tracking_uri(tracking_uri.path()) name = "random_exp" exp_id = mlflow.create_experiment(name) mlflow.set_experiment(name) run = start_run() assert run.info.experiment_id == exp_id end_run() another_name = "another_experiment" mlflow.set_experiment(another_name) exp_id2 = mlflow.tracking.MlflowClient().get_experiment_by_name( another_name) another_run = start_run() assert another_run.info.experiment_id == exp_id2.experiment_id end_run() finally: # Need to do this to clear active experiment to restore state mlflow.tracking.fluent._active_experiment_id = None
def test_start_and_end_run(tracking_uri_mock): # Use the start_run() and end_run() APIs without a `with` block, verify they work. active_run = start_run() mlflow.log_metric("name_1", 25) end_run() finished_run = tracking.MlflowClient().get_run(active_run.info.run_uuid) # Validate metrics assert len(finished_run.data.metrics) == 1 assert finished_run.data.metrics["name_1"] == 25
def test_set_experiment_with_deleted_experiment_name(tracking_uri_mock): name = "dead_exp" mlflow.set_experiment(name) run = start_run() end_run() exp_id = run.info.experiment_id tracking.MlflowClient().delete_experiment(exp_id) with pytest.raises(MlflowException): mlflow.set_experiment(name)
def test_start_and_end_run(tracking_uri_mock): # Use the start_run() and end_run() APIs without a `with` block, verify they work. active_run = start_run() mlflow.log_metric("name_1", 25) end_run() finished_run = tracking.MlflowClient().get_run(active_run.info.run_uuid) # Validate metrics assert len(finished_run.data.metrics) == 1 expected_pairs = {"name_1": 25} for metric in finished_run.data.metrics: assert expected_pairs[metric.key] == metric.value
def test_start_and_end_run(): try: tracking.set_tracking_uri(tempfile.mkdtemp()) # Use the start_run() and end_run() APIs without a `with` block, verify they work. active_run = start_run() mlflow.log_metric("name_1", 25) end_run() finished_run = tracking.get_service().get_run(active_run.info.run_uuid) # Validate metrics assert len(finished_run.data.metrics) == 1 expected_pairs = {"name_1": 25} for metric in finished_run.data.metrics: assert expected_pairs[metric.key] == metric.value finally: tracking.set_tracking_uri(None)
def test_set_experiment(tracking_uri_mock, reset_active_experiment): with pytest.raises(TypeError): mlflow.set_experiment() with pytest.raises(Exception): mlflow.set_experiment(None) with pytest.raises(Exception): mlflow.set_experiment("") name = "random_exp" exp_id = mlflow.create_experiment(name) mlflow.set_experiment(name) run = start_run() assert run.info.experiment_id == exp_id end_run() another_name = "another_experiment" mlflow.set_experiment(another_name) exp_id2 = mlflow.tracking.MlflowClient().get_experiment_by_name(another_name) another_run = start_run() assert another_run.info.experiment_id == exp_id2.experiment_id end_run()