mlflow-client-go/experiment.go

98 lines
2.7 KiB
Go
Raw Normal View History

2024-05-15 08:14:29 +00:00
package mlflow
import (
"bytes"
"encoding/json"
"net/http"
)
func SearchExperiments(conf Config, opts ExperimentSearchOptions) (*ExperimentSearchReply, error) {
resp, err := http.Post(conf.ApiURI+"/api/2.0/mlflow/experiments/search", "application/json", opts.getReader())
exp := ExperimentSearchReply{}
err = apiReadReply(resp, err, &exp)
if err != nil {
return nil, err
}
return &exp, nil
}
func GetExperiment(conf Config, id string) (*Experiment, error) {
resp, err := http.Get(conf.ApiURI + "/api/2.0/mlflow/experiments/get" + "?experiment_id=" + id)
exp := ExperimentGetReply{}
err = apiReadReply(resp, err, &exp)
if err != nil {
return nil, err
}
return &exp.Experiment, nil
}
func GetExperimentByName(conf Config, name string) (*Experiment, error) {
resp, err := http.Get(conf.ApiURI + "/api/2.0/mlflow/experiments/get-by-name" + "?experiment_name=" + name)
exp := ExperimentGetReply{}
err = apiReadReply(resp, err, &exp)
if err != nil {
return nil, err
}
return &exp.Experiment, nil
}
func DeleteExperiment(conf Config, id string) error {
resp, err := http.Post(conf.ApiURI+"/api/2.0/mlflow/experiments/delete", "application/json", bytes.NewReader([]byte(`{"experiment_id":"`+id+`"}`)))
err = apiReadReply(resp, err, nil)
if err != nil {
return err
}
return nil
}
func RestoreExperiment(conf Config, id string) (*Experiment, error) {
resp, err := http.Post(conf.ApiURI+"/api/2.0/mlflow/experiments/restore", "application/json", bytes.NewReader([]byte(`{"experiment_id":"`+id+`"}`)))
err = apiReadReply(resp, err, nil)
if err != nil {
return nil, err
}
return GetExperiment(conf, id)
}
func UpdateExperiment(conf Config, id string, newName string) (*Experiment, error) {
args := `{"experiment_id":"` + id + `","new_name":"` + newName + `"}`
resp, err := http.Post(conf.ApiURI+"/api/2.0/mlflow/experiments/update", "application/json", bytes.NewReader([]byte(args)))
err = apiReadReply(resp, err, nil)
if err != nil {
return nil, err
}
return GetExperiment(conf, id)
}
func CreateExperiment(conf Config, exp *Experiment) (*Experiment, error) {
resp, err := http.Post(conf.ApiURI+"/api/2.0/mlflow/experiments/create", "application/json", bytes.NewReader([]byte(exp.serialize())))
xp := ExperimentCreateReply{}
err = apiReadReply(resp, err, &xp)
if err != nil {
return nil, err
}
return GetExperiment(conf, xp.ExperimentId)
}
func SetExperimentTagTag(conf Config, opts SetExperimentTagRequest) error {
args, err := json.Marshal(opts)
if err != nil {
return err
}
resp, err := http.Post(conf.ApiURI+"/api/2.0/mlflow/experiments/set-experiment-tag", "application/json", bytes.NewReader([]byte(args)))
err = apiReadReply(resp, err, nil)
if err != nil {
return err
}
return nil
}