Expand description
A Rust implementation of the IEC Common Information Model for power systems.
cim-kit reads, navigates, validates and writes CIM grid models in both profile sets
European transmission system operators use: CGMES 3.0
(IEC TS 61970-600-1/-2:2021) and CGMES 2.4.15.
Each vintage is a module behind a feature of the same name — cgmes3 (default) and
cgmes2 — holding its schema tables, typed views and named constants. Identifiers
are per-vintage and cannot be mixed by accident.
§What this crate models
A CGMES grid model is a set of profile files (Equipment, Steady State Hypothesis,
Topology, State Variables, …) describing the same objects: a SynchronousMachine
gets its ratings from EQ and its dispatch from SSH, under one identifier.
Dataset merges each object’s attributes across files, remembers which file
contributed what, and writes a model set back out as the file set it came from. Merging
is order-independent except where two files give one single-valued attribute different
values; those are kept in Dataset::merge_conflicts and reported by validate()
as CIM0018.
§Getting started
Dataset::open is the shortest path in: it detects the vintage from the documents’
namespaces and takes a directory, a zip archive or a single file. Name the schema
explicitly, as below, when a program handles only one vintage.
use cim_kit::prelude::*;
use cim_kit::cgmes3::views::ACLineSegment;
// Assemble a model from its profile files (`Dataset::load_dir` takes a directory).
let ds = Dataset::load(
cim_kit::cgmes3::SCHEMA,
["model_EQ.xml", "model_SSH.xml", "model_TP.xml", "model_SV.xml"],
)?;
// Navigate it with typed views.
for line in ds.view::<ACLineSegment>() {
println!("{:?}: r={:?} x={:?}", line.name(), line.r(), line.x());
}
// Check it, structurally, against the schema.
for d in ds.validate().iter() {
println!("{d}");
}§Design
Objects are stored sparsely (only attributes present are kept), with typed access
through generated zero-cost views rather than a struct per class.
Everything model-specific is generated from the official RDFS; everything else is
written against the schema interface, so a new CIM vintage is a regeneration. The
guide explains the design.
§Changing a model, not resending it
IEC 61970-552’s dm:DifferenceModel is the incremental form of exchange.
Dataset::difference_to (diff) computes one from a before and an after, and
Dataset::apply_difference applies it; applying a computed difference to its base
reproduces the target (tested against the published conformity models).
§Leaving for the wider RDF world
CIM/XML looks like RDF/XML and is not, and carries no datatype information. rdf
writes N-Triples or Turtle with urn:uuid: subjects and every literal typed from the
profile, ready for any RDF toolchain and ENTSO-E’s SHACL shapes.
§Conformance
- Serialization follows IEC 61970-552:
rdf:ID/rdf:aboutidentity,md:FullModelheaders,rdf:parseType="Resource"compounds,dm:difference models, for reading and writing; a model set re-exports as the files it came from. - Every document written is well-formed XML (checked over the published corpus with a
strict parser). A value must hold only characters XML can represent (
CIM0019) and an identifier must have anrdf:IDorrdf:aboutform (CIM0020); seexml. validate()performs the structural checks the RDFS justifies: cardinality, value datatypes, fixed values, reference targets, profile membership, identifier form. ENTSO-E’s SHACL rules are out of scope: export withrdfand use a SHACL engine.- A read succeeds only for a whole, well-formed document — truncated input is
Error::Truncated, broken XMLError::Xml— and a read that fails leaves the dataset as it was. - Reading is tolerant by default (
ReadOptions::lenient); every deviation becomes aDiagnosticwith a stable rule code (CIM0001–CIM0022) and, from parsing, a byte offset (line_and_columnturns it into a line).ReadOptions::max_diagnosticsbounds the report, andReadOptions::max_input_bytes(8 GiB by default) the input. - Identifiers are compared by the UUID they denote, not by spelling
(a hyphenless
_1fa19c281c8f…and its hyphenated form, or an absolute IRI, are one object); the spelling is kept for re-export. SeeMridForm. - Numbers are compared by value and written as they arrived (
2.62637E-05,250.000000):Realkeeps the spelling beside the number.
§A command line
The cli feature builds cim, a tool over this same API: cim info, validate,
export, rdf, diff, apply and schema over a model set given as files, archives
or directories. cargo install cim-kit --features cli.
§Further reading
The guide (CGMES background, one page per task, the full rule catalogue) is at https://hupe1980.github.io/cim-kit/.
Re-exports§
pub use dataset::Dataset;pub use dataset::InverseIndex;pub use dataset::LinkPolicy;pub use dataset::MergeConflict;pub use dataset::ObjectId;pub use diff::DiffOptions;pub use diff::DiffReport;pub use error::Diagnostic;pub use error::Error;pub use error::Report;pub use error::Result;pub use error::Rule;pub use error::Severity;pub use error::line_and_column;pub use header::DifferenceModel;pub use header::HeaderProperty;pub use header::HeaderValue;pub use header::ModelHeader;pub use header::ModelKind;pub use header::Statement;pub use header::StatementValue;pub use load::LoadReport;pub use load::SaveReport;pub use load::instance_files;pub use mrid::Mrid;pub use mrid::MridForm;pub use object::Compound;pub use object::Object;pub use object::Slot;pub use rdf::RdfOptions;pub use rdf::Syntax;pub use reader::ReadOptions;pub use reader::Strictness;pub use schema::AttrId;pub use schema::AttrKind;pub use schema::ClassId;pub use schema::Mult;pub use schema::Primitive;pub use schema::ProfileId;pub use schema::ProfileMask;pub use schema::Schema;pub use validate::ValidateOptions;pub use validate::validate;pub use validate::validate_with;pub use value::Real;pub use value::Value;pub use view::TypedRef;pub use view::TypedView;pub use writer::HeaderSource;pub use writer::IdStyle;pub use writer::WriteOptions;pub use xml::IdentifierForm;
Modules§
- cgmes2
- CGMES 2.4.15.
- cgmes3
- CGMES 3.0 (IEC TS 61970-600-1/-2:2021).
- dataset
- The dataset: a set of CIM objects assembled from one or more instance files.
- diff
- Computing a difference model from two model states.
- error
- Errors and structured diagnostics.
- header
- Model headers:
md:FullModelanddm:DifferenceModel(IEC 61970-552). - load
- Loading and saving whole models.
- mrid
- Master resource identifiers.
- object
- Objects: the storage unit of a CIM model.
- prelude
- The imports most programs need.
- rdf
- Standard RDF output: the profile-enriched graph, in N-Triples or Turtle.
- reader
- Streaming reader for CIM/XML instance documents (IEC 61970-552).
- schema
- Runtime schema metadata.
- validate
- Structural validation derived from the schema.
- value
- Attribute values.
- view
- Typed views over stored objects.
- writer
- Writer for CIM/XML instance documents (IEC 61970-552).
- xml
- What XML and RDF/XML can actually represent.
Statics§
- VINTAGES
- Every schema vintage compiled into this build, in feature order.