Skip to content

Instantly share code, notes, and snippets.

@omry
Created March 6, 2021 10:29
Show Gist options
  • Save omry/09a2b971c83abce3970e2648f3785977 to your computer and use it in GitHub Desktop.
Save omry/09a2b971c83abce3970e2648f3785977 to your computer and use it in GitHub Desktop.
Hydra C++ example
app: ${hydra:runtime.cwd}/main
db:
driver: mysql
user: omry
password: secret
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
#include <fstream>
using json = nlohmann::json;
int main()
{
std::ifstream file("config.json");
json j = json::parse(file);
// pretty print with indent of 4 spaces
std::cout << "Config printed in C++\n" << std::setw(4) << j << '\n';
}
from omegaconf import DictConfig, OmegaConf
import hydra
import json
import subprocess
@hydra.main(config_name="config")
def my_app(cfg: DictConfig) -> None:
container = OmegaConf.to_container(cfg, resolve=True)
with open('config.json', 'w') as f:
json.dump(container, f)
subprocess.check_call([cfg.app])
if __name__ == "__main__":
my_app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment