Back to all questions

How do I write a YAML configuration file for MatCraft?

Getting Started
yaml
configuration
schema

YAML configuration files are the primary way to define materials and campaigns in MatCraft. The schema is designed to be readable and self-documenting.

Material Definition

A material YAML defines the design space — what can vary and what you want to optimize:

yaml
name: "lithium-ion-cathode-v2"
domain: battery
description: "NMC cathode composition optimization"

components:
  - name: nickel_fraction
    type: continuous
    bounds: [0.3, 0.9]
    description: "Ni molar fraction in NMC"
  - name: manganese_fraction
    type: continuous
    bounds: [0.05, 0.4]
  - name: cobalt_fraction
    type: continuous
    bounds: [0.05, 0.3]
  - name: coating_thickness
    type: continuous
    bounds: [1.0, 20.0]
    unit: "nm"

constraints:
  - type: sum_equals
    components: [nickel_fraction, manganese_fraction, cobalt_fraction]
    value: 1.0
    tolerance: 0.001

objectives:
  - name: specific_capacity
    direction: maximize
    unit: "mAh/g"
  - name: cycle_retention
    direction: maximize
    unit: "%"
    description: "Capacity retention after 500 cycles"
  - name: material_cost
    direction: minimize
    unit: "$/kg"

Campaign Configuration

Campaign settings can be included in the same file or a separate one:

yaml
campaign:
  max_iterations: 20
  batch_size: 5
  surrogate:
    type: mlp
    hidden_layers: [64, 64]
    learning_rate: 0.001
    epochs: 200
  acquisition:
    type: expected_improvement
    exploration_weight: 0.1
  convergence:
    patience: 5
    min_improvement: 0.01

Key Schema Rules

  • component types: continuous, discrete, or categorical. Categorical components use choices instead of bounds.
  • objective directions: maximize or minimize.
  • constraint types: sum_equals, sum_lte, ratio_between, or custom (with a Python expression).
  • All numeric bounds are inclusive.
  • The domain field is optional but enables domain-specific physics models and validation.

Validation

Validate your YAML before launching a campaign:

bash
materia config validate my_material.yaml

This checks for schema errors, bound consistency, constraint feasibility, and warns about potential issues like very high-dimensional spaces or tight constraints.

Related Questions