Ways to run MLflow
You can explicitly specify start_run() and end_run()
import mlflow
if __name__=="__main__":
mlflow.set_experiment(experiment_id="446269725962928702")
mlflow.start_run(run_name="MyFirstMLflow_run")
mlflow.log_param("learning_rate", 0.01)
mlflow.end_run()


Or you can use with to start and end the run
import mlflow
if __name__=="__main__":
with mlflow.start_run(run_name="MySecondMLflow_run", experiment_id = "446269725962928702") as run:
mlflow.log_param("learning_rate", 0.01)
print("Run ID: ", run.info.run_id)
print("Run Info: ", run.info)
Run ID: 4e24e3f695574503bd49df5961f37ec3
Run Info: <RunInfo: artifact_uri='file:///c:/Users/dof07/Desktop/mlflow/MyFirstMLflow_artifact_loc/4e24e3f695574503bd49df5961f37ec3/artifacts', end_time=None, experiment_id='446269725962928702', lifecycle_stage='active', run_id='4e24e3f695574503bd49df5961f37ec3', run_name='MySecondMLflow_run', run_uuid='4e24e3f695574503bd49df5961f37ec3', start_time=1741048851677, status='RUNNING', user_id='YOUNGJIN'>


import mlflow
from mlflow_utils import create_mlflow_experiment
from mlflow_utils import get_mlflow_experiment
if __name__ == "__main__":
experiment_id = create_mlflow_experiment(
experiment_name = "MyFirstMLflow",
artifact_location="MyFirstMLflow_artifact_loc",
tags={"env":"dev", "version":"1.0.0"},
)
experiment = get_mlflow_experiment(experiment_id=experiment_id)
print("Experiment name: {}".format(experiment.name))
with mlflow.start_run(run_name="MyThirdMLflow_run", experiment_id = experiment.experiment_id) as run:
mlflow.log_param("learning_rate", 0.01)
print("Run ID: {}".format(run.info.run_id), "\n",
"Experiment ID: {}".format(run.info.experiment_id), "\n",
"Status: {}".format(run.info.status), "\n",
"Start time: {}".format(run.info.start_time), "\n",
"End time: {}".format(run.info.end_time), "\n",
"Lifecycle_stage: {}".format(run.info.lifecycle_stage))
Experiment MyFirstMLflow already exists.
Experiment name: MyFirstMLflow
Run ID: dab5dabc58794edaba8cc559f4658c5e
Experiment ID: 446269725962928702
Status: RUNNING
Start time: 1741048960551
End time: None
Lifecycle_stage: active


NOTE: Running MLflow outputs further files that contain the info
