Container#

class GpfCase(*, ic=0, sbase=100.0, rev=33, xfrrat=0.0, nxfrat=0.0, basfrq=60.0, title1='', title2='', buses=<factory>, loads=<factory>, generators=<factory>, branches=<factory>, transformers=<factory>, system_switching_devices=<factory>, fixed_shunts=<factory>, areas=<factory>, zones=<factory>, owners=<factory>, switched_shunts=<factory>, inter_areas=<factory>, two_terminal_dc=<factory>, vsc_dc_lines=<factory>, multi_terminal_dc=<factory>, facts_devices=<factory>, multi_section_lines=<factory>, impedance_corrections=<factory>, rating_names=<factory>, solver_defaults=None, system_wide_extras=<factory>)#

Bases: BaseModel

Complete case data.

classmethod from_matpower(path)#

Parse a MATPOWER .m case file into a GpfCase.

Parameters:

path -- Filesystem path to the .m file.

Returns:

The parsed GpfCase, tagged with MATPOWER conventions so that solve_power_flow() applies them.

classmethod from_raw(path, *, allow_unmodeled_sections=False)#

Parse a RAW text file.

Parameters:
  • path -- Filesystem path to the RAW file.

  • allow_unmodeled_sections -- Forwarded to parse_raw(). When False (default), nonempty GNE / induction-machine / substation sections raise; pass True to drop them silently.

classmethod from_rawx(path)#

Parse a RAWX (JSON) case file into a GpfCase.

Parameters:

path -- Filesystem path to the .rawx (or .json) file.

Returns:

The parsed GpfCase. Parsing does not validate the data; call validate_schema() if you need schema validation.

get_bus(ibus)#

Look up bus by number. O(n) scan; build a dict for bulk lookups.

model_post_init(context, /)#

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that's what pydantic-core passes when calling it.

Parameters:
  • self -- The BaseModel instance.

  • context -- The context.

solve_power_flow(**kwargs)#

Solve power flow for this case.

Convenience wrapper around solve_power_flow(); see that function for the full option set. Returns a SolvedCase.

Example

>>> case = GpfCase.from_raw("ieee39.raw")
>>> sol = case.solve_power_flow(backend="cpu")
>>> print(sol.summary())
summary()#

Return a brief summary of the case.

to_raw(path, version=33, *, options=None)#

Serialize this case to a RAW text file.

Supports RAW v33 and v34. self.rev is ignored: the writer emits records shaped for the target version, and the header reports the version it actually wrote.

Parameters:

options -- Optional v34+ writer policy. Ignored when version=33. None keeps the default policy (emit system-wide preamble plus @! column headers).

to_rawx(path, version=33)#

Serialize this case to a RAWX (JSON) file.

Only v33 is supported. Branch r/x/b are emitted as the canonical rpu/xpu/bpu columns. v34+ model fields (branch.name/rate4..rate12, generator.nreg, load.dgenp/dgenq/dgenf, transformer.rate{1,2,3}_4..12, transformer.zcod/nod{1,2,3}) are not emitted by the v33 RAWX writer. MTDC records are emitted as four flat tables joined on the line name (ntermdc / ntermdcconv / ntermdcbus / ntermdclink).

validate_schema()#

Validate all records against Pydantic schemas.

Parsing skips validation for speed; call this method afterward to validate the records if needed.

Raises:

ValidationError -- If any record fails schema validation.