Validation
The structural checks cim-kit derives from the CGMES RDFS vocabulary, the full CIM0001–CIM0022 rule catalogue, and where SHACL takes over.
cim-kit performs the checks the RDFS vocabulary can justify: cardinality, datatypes, class membership, reference targets, profile membership, identifier conformance, header structure. The semantic rules ENTSO-E publishes as SHACL shapes are not run here — export with rdf and use a SHACL engine.
use cim_kit::prelude::*;
use cim_kit::ValidateOptions;
fn check(grid: &Dataset) -> bool {
let _defaults = grid.validate();
let _reduced = grid.validate_with(&ValidateOptions::essential()); // only broken data
let report = grid.validate_with(&ValidateOptions::thorough()); // + deprecation
for (rule, count) in report.summary() {
println!("{rule}: {count}");
}
!report.has_errors()
}Rule catalogue#
Codes are stable; filter on them rather than on message text. cim_kit::Rule::ALL enumerates them.
Raised by: read is the LoadReport a load returns (applying a difference model raises these too), check is what validate() produces, apply is applying a change set. A rule raised only on read never appears in a validation report.
| Code | Rule | Raised by | Meaning |
|---|---|---|---|
CIM0001 | UnknownClass | read | An element names a class the schema does not define |
CIM0002 | UnknownAttribute | read · check | A property the schema does not define, or one the object's class does not have |
CIM0003 | InvalidValue | read | A value could not be parsed as its declared type; also an undefined entity reference, kept as text |
CIM0004 | NonConformingMrid | read · check | An identifier is not a UUID, or not written as 61970-552 requires. Opt-in on read — except a repair, which is always reported |
CIM0005 | DuplicateMrid | read | One identifier used by two unrelated classes, or defined twice with rdf:ID in one document; with --single-description, described twice in one document |
CIM0006 | DanglingReference | check | A reference points outside the dataset |
CIM0007 | MissingRequired | check | A mandatory attribute is absent |
CIM0008 | CardinalityExceeded | read · check | An attribute occurs more often than its multiplicity permits; on read, a single-valued one repeated with the same value |
CIM0009 | WrongReferenceTarget | check | A reference points at an object of an unrelated class |
CIM0010 | AttributeNotInProfile | check | A file carries data belonging to a profile its header does not declare |
CIM0011 | AbstractInstantiated | read · check | An abstract class has an instance |
CIM0012 | Deprecated | read · check | A deprecated class or attribute is in use |
CIM0013 | MalformedHeader | check | The md:FullModel header is missing or incomplete |
CIM0014 | UnsatisfiedDependency | check · apply | A header declares a Model.DependentOn that was not loaded; or a change set was refused on apply because the model it supersedes is not held or a precondition does not hold |
CIM0015 | Structure | read · check | A structural problem that did not prevent reading |
CIM0016 | DatatypeMismatch | check | A stored value does not have the shape its attribute declares |
CIM0017 | FixedValueMismatch | check | An attribute the schema pins with cims:isFixed holds something else |
CIM0018 | ConflictingValue | read · check | One single-valued attribute was given two different values: twice in one document (read, an error), or by two loaded files (check) |
CIM0019 | IllegalXmlCharacter | read · check | A value, identifier or reference holds a character XML 1.0 cannot represent in any form |
CIM0020 | UnserializableIdentifier | check | An identifier has no valid rdf:ID or rdf:about form |
CIM0021 | WrongVintage | read | The document is written against a different CIM vintage than the schema reading it |
CIM0022 | UnreadableFile | read | A file or archive entry in the model set could not be read — broken XML, truncated, or an archive that will not open. It contributes nothing |
How some checks judge#
| Rule | Behaviour |
|---|---|
CIM0016 | CIM/XML exchanges no type information; the check types each value from the RDFS (ACLineSegment.r is a float, Terminal.phases a PhaseCode), as ENTSO-E advises importers to do before validating |
CIM0007 | Reported only when the object takes part in a profile that declares the attribute and a loaded file defines the object's class — a Topology file alone is not missing Equipment attributes. Association sides with cims:AssociationUsed = No are never reported |
CIM0010 | A warning; the data is kept. Aggregated per attribute with a count |
CIM0018 | Across files: recorded during assembly, since the discarded value is gone afterwards, and a warning — a change file paired with its old base model produces these by design. Within one document, in one element or two descriptions of the object: an error from the reader, with related_position at the first value |
CIM0002 | Also checks the finished model, including compound fields: a value under an attribute its class does not have would otherwise be dropped on export (or, in a compound, exported into an invalid document) |
CIM0019 | XML 1.0's Char production excludes most of the C0 range, and no escaped form exists. The reader and writer strip such characters; the check names one already held |
CIM0020 | Cannot fire on conforming input. An identifier kept verbatim, such as an absolute IRI, is written as rdf:about; one that is neither an NCName nor an IRI has no valid form and is reported |
Profile coverage#
How much of each profile a model set carries, counted by the same rule the writer uses:
use cim_kit::prelude::*;
fn coverage(grid: &Dataset) {
for cov in cim_kit::validate::profile_coverage(grid) {
println!("{:<6} {:>7} objects {:>9} values", cov.keyword, cov.objects, cov.attributes);
}
}Choosing checks#
use cim_kit::ValidateOptions;
fn options() -> ValidateOptions {
ValidateOptions {
required_attributes: false, // e.g. for a partial model set
deprecation: true,
max_diagnostics: 50_000,
..ValidateOptions::default()
}
}for_profiles(mask) restricts the run to one profile's expectations — for example, to validate a file that claims to be Equipment only.