Skip to content

GridLAB-D models to CIM and back

cimhub-gridlabd reads a GridLAB-D .glm model, writes it as .cimtbl text, and builds an IEC CIM model (cim18v17) from that text. It also reads a CIM model and writes a .glm that GridLAB-D solves.

Quick start What converts Developer docs

from cimhub_gridlabd.exporter.cim_to_glm import cim_to_glm
from cimhub_gridlabd.glm_reader import GlmReader
from cimhub_gridlabd.importer.glm_to_cimtbl import glm_to_cim

model = GlmReader("cimhub_gridlabd/tests/decks/IEEE/IEEE13_cdpsm.glm", defines={"VSOURCE": "66395.28"}).read_all()  # .glm -> typed records
network = glm_to_cim(model, name="IEEE13_cdpsm")                                   # records -> .cimtbl -> CIM
cim_to_glm(network, "out/IEEE13_cdpsm.glm", name_source="name")                    # CIM -> .glm

glm_to_cim writes the model as .cimtbl text and builds the CIM network from that text, so the text you can read and diff (pass artifact_dir= to keep it) is exactly what the model was built from. Values keep the units the .glm wrote, and the unit is in the column header. cim_to_glm reads the network back through the CIMHub core getters, which convert once to the unit GridLAB-D expects.

  • User guide


    Install it, convert the IEEE 13-node feeder both ways, then import, export, players and schedules, round-trip checks and the list of GLM classes that convert.

    User guide

  • Conversion reference


    For each group of GLM classes, what each one becomes in CIM, how its properties map and where the two models differ.

    Conversion reference

  • Developer docs


    The map of the code: reader and writer, importer, exporter, the LinkML schema, the tests and the rules a change keeps.

    Developer docs

  • Schema reference


    Every GLM class and property the reader knows, generated from the LinkML schema.

    Schema reference

What the package does

Step Call Result
Read GlmReader(path, defines=...).read_all() a GlmModel of typed records, with #includes followed and ${NAME} macros expanded
Import glm_to_cim(model, name=...) a cim18v17 network, built from .cimtbl text
Export GlmExporter().to_model(network) a GlmModel again, from the CIM objects
Write GlmWriter().write(model, path) a .glm (and its player files) that the reader, the importer and GridLAB-D read

Only the reader and the writer read and write model files: GlmImporter.to_cimtbl and GlmExporter.to_model touch none. The quick start runs each step on a real model.

  • Nothing is guessed. An unknown property, an expression the importer cannot read, an unmapped value or an unresolved reference raises with the name of the GLM object. A GLM class no mapper reads is listed by count in the master .cimtbl, so it never disappears silently.
  • Units are not converted by hand. Import copies values in the units the .glm wrote; export reads each quantity through a core getter, which converts once to the unit GridLAB-D fixes for that property.
  • Players and schedules carry time series. Their points go to a dict of Arrow tables beside the model, not into the CIM objects. See Players and schedules.

CIMHub GridLAB-D is one package of CIMHub. The other converters, and the landing page for all of them, are at CIMHub. The shared layer under every converter is CIMHub core.