Grid models that survive the round trip.
cim-kit reads, navigates, validates and writes CIM/CGMES power-system models in Rust — and writes them back file for file, object for object, in the same serialized form the published ENTSO-E conformity models use.
use cim_kit::prelude::*;
use cim_kit::cgmes3::{SCHEMA, views::ACLineSegment};
fn main() -> cim_kit::Result<()> {
// A CGMES model is a *set* of profile files describing the same objects.
let grid = Dataset::load_dir(SCHEMA, "MicroGrid-BE")?;
for line in grid.view::<ACLineSegment>() {
let kv = line.base_voltage_in(&grid).and_then(|bv| bv.nominal_voltage());
println!("{:?} {kv:?} kV r={:?} x={:?}", line.name(), line.r(), line.x());
}
// Structural checks, against the profile.
for finding in grid.validate().iter() {
println!("{finding}");
}
Ok(())
}Why cim-kit#
The mature CIM implementations are Java (PowSyBl), C++ (libcimpp) and Python (pycgmes, CIMpy). cim-kit is a fast, memory-safe Rust core for model servers, edge controllers and WebAssembly tooling: one crate, one mandatory dependency, the typed model generated from ENTSO-E's published vocabularies. cimoxide is the other Rust option, with a struct per class over a quad store and SHACL/SPARQL built in.
What makes it correct#
Each of these is enforced by a test against the published conformity models.
A model is a set of files
Equipment and Steady State Hypothesis describe the same SynchronousMachine under one identifier. Objects merge by mRID, whatever its spelling; load order does not matter.
A read is whole or nothing
A truncated transfer or broken XML is an error, never a partial model, and a property given twice for one object is reported with both positions.
Provenance decides the export
Each value and each object records the file it came from, so a re-export reproduces the original file set — boundary nodes included.
The element class is derived
An SSH file writes <cim:Equipment> for an ACLineSegment, because SSH declares Equipment. rdf:ID versus rdf:about also comes from the RDFS, per class and profile.
A number's spelling is kept
2.62637E-05 is written back as read, while equality compares numbers — so a difference never reports a reformatting as a change.
Output is checked by others
XML and XML Namespaces, the N-Triples grammar, PowSyBl and rdflib, in CI.
The full conformance record is here.
Standard RDF, with the datatypes CIM/XML omits#
CIM/XML carries no datatypes, so a graph loaded straight from it fails ENTSO-E's SHACL shapes. cim-kit exports N-Triples or Turtle per profile with every value typed from the profile:
<urn:uuid:17086487-56ba-4979-b8de-064025a6b4da>
a cim:ACLineSegment ;
cim:ACLineSegment.r "2.2"^^xsd:float ;
cim:ConductingEquipment.BaseVoltage <urn:uuid:a7f1d8de-d658-428a-821b-3a5ae5965fd1> ;
cim:Equipment.aggregate "false"^^xsd:boolean ;
cim:IdentifiedObject.name "BE-Line_1" ;
eu:IdentifiedObject.shortName "BE-L_1" .Every profile with data in every CGMES 3.0 conformity model passes ENTSO-E's shapes under pyshacl, in CI — see Standard RDF.
Install#
cargo add cim-kit # the library
cargo install cim-kit --features cli # the `cim` command line
brew install hupe1980/tap/cim-kit # the `cim` command line (macOS Apple Silicon, Linux)cim info MicroGrid-BE/ # what a model set contains
cim validate MicroGrid-BE/ --rule CIM0007 # exits 1 on any error
cim rdf MicroGrid-BE/ --out graphs/ # one typed RDF graph per profile with data
cim diff before/ after/ > change.xml # the change set between two states
cim apply before/ --change change.xml --out after/ # and applying one