Crates.io | conflag |
lib.rs | conflag |
version | 0.1.1 |
source | src |
created_at | 2023-04-14 04:50:52.153714 |
updated_at | 2023-04-14 18:32:33.729814 |
description | A simple and powreful configuration language, extending JSON with declarative and functional language features. |
homepage | https://github.com/bethebunny/conflag |
repository | https://github.com/bethebunny/conflag |
max_upload_size | |
id | 838931 |
size | 101,691 |
Conflag is a data language. It's perfect for application configuration, once those configurations grow beyond a few command line flags or a 5-line JSON file.
Example use cases for Conflag:
Write your data declaratively, but with table-stakes like references, comments, and multiple files.
Any valid JSON file is already a valid Conflag file, so migration is easy, and the syntax is clear and easy to read. Get started in minutes and leave JSON behind.
Rust with Serde:
cargo add conflag --features serde
Python:
git clone https://github.com/bethebunny/conflag
cd conflag
cargo build --release --features python
cp target/release/libconflag.so conflag.so
Write a config file: object.cfg
{
hello: (name) => "Hello, " + name,
name: "Stef",
message: hello(name),
double: (x) => x + x,
data: map(double, [1, 2, 3, 4, 5]),
}
#[derive(serde::Deserializer, Debug)]
struct Stuff {
message: String,
data: Vec<u64>,
}
fn main() {
let raw: &str = fs::read_to_string("object.cfg").unwrap();
let stuff: Stuff = conflag::serde::from_str(raw).unwrap();
println!("{stuff:?}");
}
>>> import conflag
>>> s = conflag.loads(open("object.cfg").read())
>>> s.name
"Stef"
>>> s.message
"Hello, Stef"
>>> s.data
[2, 4, 6, 8, 10]
The following config will load to a list of model hyperparameter configs, running a parameter sweep over values for a dropout parameter.
It demonstrates a few features, such as
if
and map
functionsmodel_params
with fine-grained adjustments{
// Base hyperparams for a simple model
model_params: {
decoder_mlp: {
hidden_layers: [1024, 512, 256],
dropout: 0.2,
activation: "relu",
norm: null,
}
},
// Let's make a helper function to help us with the sweep.
// Like numpy's arange, create a list with a range of float values
arange: (start, stop, step) => {
// Name an internal computation in an anonymous scope
done: if(step > 0, start >= stop, start <= stop),
// Recursive calls allow building any necessary helpers
result: if(done, [], [start] + arange(start + step, stop, step)),
}.result,
// Create a list that contains a copy of model_params for each value in our sweep
experiments: map(
// & is the patch operator, letting us override just the parts we want to change
(_dropout) => model_params + {decoder_mlp: &{dropout: _dropout}},
arange(0, 0.4, 0.01),
),
// We don't need to expose any of the other junk to our program!
// The data hides it in this anonymous scope and only produces the output.
}.experiments