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 not one file. It is a set of profile files — Equipment (EQ),
Steady State Hypothesis (SSH), Topology (TP), State Variables (SV) and others — that
describe the same objects from different angles. A SynchronousMachine gets its
ratings from EQ and its dispatch from SSH, under one identifier.
Dataset is built around that fact: loading several files merges each object’s
attributes rather than producing duplicates, and writing filters attributes back down
to a single profile. Which file contributed a value is remembered, so a model set
written back out is the file set it came from.
Merging is order-independent for everything except a genuine contradiction — two files
giving one single-valued attribute two different values. Resolving that means
discarding one of them, so it is recorded rather than swallowed:
Dataset::merge_conflicts, reported by validate() as CIM0018.
§Getting started
Dataset::open is the shortest path in: it reads the vintage out of the document’s own
namespace declarations, so a directory, a zip archive or a single file loads without the
caller knowing whether it is CGMES 3.0 or 2.4.15. Name the schema explicitly — as below —
when a program only ever handles one vintage.
use cim_kit::prelude::*;
use cim_kit::cgmes3::views::ACLineSegment;
// Assemble a model from its profile files. A model set is a directory in practice, so
// [`Dataset::load_dir`] is usually the call; [`Dataset::merge`] combines datasets built
// separately, for assembling one in parallel.
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 actually present are kept — because a
Terminal has around thirty possible attributes and a Steady State Hypothesis file sets
exactly one. Typed access comes from generated zero-cost views rather
than a struct per class, which keeps profile merging natural and compile times low.
Everything model-specific is generated from the official RDFS vocabularies; everything
else is written against the schema interface, so a new CIM vintage is a regeneration
rather than a rewrite. Three facts about CGMES shape the I/O layer — attributes are
declared far more widely than they are used, one file serves several profiles at once,
and the form of a document is a property of the class within the profile. The
guide explains each.
§Changing a model, not resending it
IEC 61970-552 defines dm:DifferenceModel as the incremental form of exchange: the
statements to retract, then the statements to assert. diff computes one from a
before and an after — Dataset::difference_to — and Dataset::apply_difference
applies it. Applying a computed difference to its base reproduces the target exactly;
that is a test against the published conformity models, not a claim.
§Leaving for the wider RDF world
CIM/XML looks like RDF/XML and is not, and it carries no datatype information at
all — every value is element text, so 1 could be an integer, a float or a string.
That is why a CGMES file cannot simply be handed to a triple store or to the SHACL
shapes ENTSO-E publishes beside the RDFS.
rdf closes that: it writes the model as ordinary N-Triples or Turtle with
urn:uuid: subjects and every literal typed from the profile. The result loads in any
RDF toolchain and validates against ENTSO-E’s shapes as it stands.
§Conformance
- Serialization follows IEC 61970-552:
rdf:ID/rdf:aboutidentity,md:FullModelheaders,rdf:parseType="Resource"compounds,dm:difference models. Both reading and writing are covered, and a model set re-exports as the files it came from. - Every document written is well-formed XML, checked over the whole published corpus
with namespace resolution, duplicate-attribute detection and XML 1.0’s character
range — a tolerant reader accepting its own output proves nothing about anyone else’s
parser. Two constraints of the output syntax that the object model cannot express are
enforced at the writer and reported by
validate(): 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 vocabulary justifies: cardinality, value datatypes, fixed values, reference targets, profile membership, identifier form. The datatype check is not redundant with parsing — CIM/XML exchanges no type information at all, so a value’s type is only decidable against the profile. Semantic rules ENTSO-E publishes as SHACL shapes are out of scope: export withrdfand run them with a SHACL engine.- Reading is tolerant by default (
ReadOptions::lenient), because published models carry vendor extensions and identifier deviations. Nothing is silently dropped: every deviation becomes aDiagnosticwith a stable rule code (CIM0001–CIM0022) and, from parsing, a byte offset thatline_and_columnturns into a line. The report grows with how broken the input is, soReadOptions::max_diagnosticsbounds it and the reader says when it stopped. - Identifiers are compared by the UUID they denote, not by how a producer spelled it.
Published CGMES 2.4.15 files write
rdf:ID="_1fa19c281c8f4e1eaad9e1cab70f923e", and references as absolute IRIs; read as opaque text, such an object loses itsurn:uuid:name in RDF and splits in two against a file that spells the same UUID conventionally. The spelling is remembered so re-export reproduces the document; the identity does not depend on it. SeeMridForm. - Numbers are compared by value and written as they arrived. Published models write
2.62637E-05and250.000000, and re-rendering anf64returns neither;Realcarries the spelling beside the number, so a re-export is the file that was read and a difference never reports a reformatting as a change.
§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
This page is orientation and the rest of these docs are the reference. The guide — CGMES background, one page per task, and 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.