4#ifndef GPR_AUXILIARY_MLFLOW_FILE_STORE_H_
5#define GPR_AUXILIARY_MLFLOW_FILE_STORE_H_
27 return add(key,
static_cast<long>(value));
30 JsonRecord&
add(std::string_view key, std::string_view value);
33 return add(key, std::string_view(value));
35 JsonRecord&
add(std::string_view key,
const Eigen::VectorXd& value);
36 JsonRecord&
add(std::string_view key,
const Eigen::MatrixXd& value);
39 [[nodiscard]] std::string
str()
const;
42 void separator(std::string_view key);
43 std::ostringstream out_;
60 const std::string& json)
const;
61 [[nodiscard]]
Response put(
const std::string& path,
const std::string& body,
62 const std::string& content_type)
const;
63 [[nodiscard]]
Response get(
const std::string& path)
const;
64 [[nodiscard]]
const std::string&
host() const noexcept
68 [[nodiscard]]
int port() const noexcept
72 [[nodiscard]]
const std::string&
prefix() const noexcept
78 Response request(
const std::string& method,
const std::string& path,
79 const std::string& body,
80 const std::string& content_type)
const;
84 double timeout_seconds_ = 0.0;
104 std::map<std::string, std::string>
tags;
112 static std::unique_ptr<MlflowRun>
start(
const Options& options);
117 void logParam(std::string_view key, std::string_view value);
118 void logParam(std::string_view key,
double value);
119 void logParam(std::string_view key,
long value);
120 void logMetric(std::string_view key,
double value,
long step = 0);
121 void setTag(std::string_view key, std::string_view value);
123 void logArtifact(
const std::filesystem::path& file,
124 const std::string& name =
"");
131 [[nodiscard]]
const std::string&
runId() const noexcept
137 return experiment_id_;
139 [[nodiscard]]
const std::filesystem::path&
runDirectory() const noexcept
145 return rest_ !=
nullptr;
152 struct PendingMetric {
160 void connectRemote(
const Options& options);
161 void disableStreaming(
const std::string& why);
162 void uploadRecordStreams();
163 void appendLocal(
const std::filesystem::path& file,
164 const std::string& text);
165 std::filesystem::path store_;
166 std::filesystem::path run_dir_;
167 std::string experiment_id_;
168 std::string remote_experiment_id_;
170 std::string run_name_;
171 std::string tracking_uri_;
172 std::string remote_artifact_uri_;
173 long start_time_ms_ = 0;
174 bool finished_ =
false;
175 std::unique_ptr<MlflowRestClient> rest_;
176 std::vector<PendingMetric> pending_metrics_;
177 std::vector<std::pair<std::string, std::string>> pending_params_;
178 std::vector<std::pair<std::string, std::string>> pending_tags_;
179 std::vector<std::string> record_streams_;
181 std::map<std::filesystem::path, std::ofstream> append_streams_;
187[[nodiscard]] MlflowRun*
activeRun() noexcept;
195 std::string_view key);
A JSON object assembled field by field; one line of a record stream.
JsonRecord & add(std::string_view key, double value)
JsonRecord & addRaw(std::string_view key, std::string_view json)
A nested object, already rendered.
JsonRecord & add(std::string_view key, const char *value)
JsonRecord & add(std::string_view key, int value)
int port() const noexcept
Response post(const std::string &path, const std::string &json) const
MlflowRestClient(std::string_view tracking_uri, double timeout_seconds)
Throws std::invalid_argument on a URI that is not plain http.
Response put(const std::string &path, const std::string &body, const std::string &content_type) const
Response get(const std::string &path) const
const std::string & host() const noexcept
const std::string & prefix() const noexcept
void setTag(std::string_view key, std::string_view value)
void logMetric(std::string_view key, double value, long step=0)
void logArtifact(const std::filesystem::path &file, const std::string &name="")
Copy a file into artifacts/ (optionally under a relative name).
const std::filesystem::path & runDirectory() const noexcept
void logParam(std::string_view key, std::string_view value)
void finish(Status status)
void appendRecord(std::string_view stream, const JsonRecord &record)
Append one JSON line to artifacts/STREAM_NAME.jsonl.
const std::string & runId() const noexcept
std::string identityJson() const
const std::string & experimentId() const noexcept
MlflowRun(const MlflowRun &)=delete
bool streaming() const noexcept
MlflowRun & operator=(const MlflowRun &)=delete
static std::unique_ptr< MlflowRun > start(const Options &options)
void flush()
Send buffered metrics, params and tags to the tracking server.
MlflowRun * activeRun() noexcept
void setActiveRun(MlflowRun *run) noexcept
std::string sanitizeKey(std::string_view key)
MLflow key alphabet: alphanumerics, underscore, dash, dot, space, slash.
std::string jsonStringField(std::string_view json, std::string_view key)
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
double timeout_seconds
per REST request
std::string tracking_uri
http://host:port of mlflow server
std::filesystem::path store
local file store (mlruns)
std::map< std::string, std::string > tags