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.

CodeRuleRaised byMeaning
CIM0001UnknownClassreadAn element names a class the schema does not define
CIM0002UnknownAttributeread · checkA property the schema does not define, or one the object's class does not have
CIM0003InvalidValuereadA value could not be parsed as its declared type; also an undefined entity reference, kept as text
CIM0004NonConformingMridread · checkAn identifier is not a UUID, or not written as 61970-552 requires. Opt-in on read — except a repair, which is always reported
CIM0005DuplicateMridreadOne identifier used by two unrelated classes, or defined twice with rdf:ID in one document; with --single-description, described twice in one document
CIM0006DanglingReferencecheckA reference points outside the dataset
CIM0007MissingRequiredcheckA mandatory attribute is absent
CIM0008CardinalityExceededread · checkAn attribute occurs more often than its multiplicity permits; on read, a single-valued one repeated with the same value
CIM0009WrongReferenceTargetcheckA reference points at an object of an unrelated class
CIM0010AttributeNotInProfilecheckA file carries data belonging to a profile its header does not declare
CIM0011AbstractInstantiatedread · checkAn abstract class has an instance
CIM0012Deprecatedread · checkA deprecated class or attribute is in use
CIM0013MalformedHeadercheckThe md:FullModel header is missing or incomplete
CIM0014UnsatisfiedDependencycheck · applyA 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
CIM0015Structureread · checkA structural problem that did not prevent reading
CIM0016DatatypeMismatchcheckA stored value does not have the shape its attribute declares
CIM0017FixedValueMismatchcheckAn attribute the schema pins with cims:isFixed holds something else
CIM0018ConflictingValueread · checkOne single-valued attribute was given two different values: twice in one document (read, an error), or by two loaded files (check)
CIM0019IllegalXmlCharacterread · checkA value, identifier or reference holds a character XML 1.0 cannot represent in any form
CIM0020UnserializableIdentifiercheckAn identifier has no valid rdf:ID or rdf:about form
CIM0021WrongVintagereadThe document is written against a different CIM vintage than the schema reading it
CIM0022UnreadableFilereadA 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#

RuleBehaviour
CIM0016CIM/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
CIM0007Reported 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
CIM0010A warning; the data is kept. Aggregated per attribute with a count
CIM0018Across 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
CIM0002Also 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)
CIM0019XML 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
CIM0020Cannot 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.