Validation¶
validate_document() checks a document against the epJSON schema: required
fields, value types, numeric ranges, enum choices, and reference integrity. It
also checks what EnergyPlus would stop on that the schema does not say: compact
schedules it cannot read, schedule values outside their limits, window
constructions, upside-down floors and roofs, and objects with no entries.
| Code | Severity | Reported for |
|---|---|---|
E001 |
error | A required field, or the name, is missing |
E002 |
error | A value matches none of the field's accepted types |
E003 |
error | A value of the wrong type, or NaN or infinity |
E004 |
error | A choice the field does not list |
E005, E006 |
error | A number below the minimum, or not above an exclusive one |
E007, E008 |
error | A number above the maximum, or not below an exclusive one |
E009 |
error | A reference to a name that does not exist, or that belongs to the wrong type |
E010 |
error | More than one instance of a singleton type |
E011 |
error | A compact schedule EnergyPlus cannot read |
E012 |
error | A schedule value outside the limits of its ScheduleTypeLimits |
E013 |
error | A window or glass door whose construction has only opaque layers |
W001 |
warning | No schema available, so schema validation was skipped |
W002 |
warning | An object type the schema does not have |
W003 |
warning | A field the object type does not have |
W004 |
warning | An object such as OutdoorAir:NodeList that holds only extensible entries and has none |
W005 |
warning | A floor that faces up, or a roof or ceiling that faces down |
W006 |
warning | A reference to a missing ScheduleTypeLimits, which EnergyPlus only warns about |
Each issue carries the object it was found on in ValidationError.obj, which
is how to tell apart issues on objects of a type with no Name field.
On-demand validation system for IDF documents.
Provides validation against EpJSON schema without requiring eager validation during parsing.
logger = logging.getLogger(__name__)
module-attribute
¶
ValidationError
dataclass
¶
Represents a validation issue.
Attributes:
| Name | Type | Description |
|---|---|---|
severity |
Severity
|
Issue severity (ERROR, WARNING, INFO) |
obj_type |
str
|
Object type where issue was found |
obj_name |
str
|
Object name where issue was found |
field |
str | None
|
Field name where issue was found (if applicable) |
message |
str
|
Human-readable description |
code |
str
|
Machine-readable error code |
obj |
IDFObject | None
|
The object the issue was found on, or |
Source code in idfkit/validation.py
ValidationResult
dataclass
¶
Result of document validation.
Attributes:
| Name | Type | Description |
|---|---|---|
errors |
list[ValidationError]
|
List of validation errors |
warnings |
list[ValidationError]
|
List of validation warnings |
info |
list[ValidationError]
|
List of informational messages |
Source code in idfkit/validation.py
field_value_error(obj, field_name, value, schema)
¶
The finding value would raise as obj's field_name, or None when the schema accepts it.
The type, choice and range checks add() applies to each value, for one value about to be
assigned. A blank value clears the field and is not checked, nor is a field the schema does not
know: whether a name is a field is the caller's question (strict mode, or update()).
Source code in idfkit/validation.py
name_error(obj, value, schema)
¶
The finding renaming obj to value would raise, or None when the schema accepts the name.
A blank or whitespace name on a type whose schema requires one is refused, as add() refuses it.
Source code in idfkit/validation.py
validate_document(doc, schema=None, check_references=True, check_required=True, check_types=True, check_ranges=True, check_singletons=True, object_types=None, check_geometry=True)
¶
Validate an IDF document against schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
The document to validate |
required |
schema
|
EpJSONSchema | None
|
Schema to validate against (uses doc's schema if not provided) |
None
|
check_references
|
bool
|
Check reference integrity ( |
True
|
check_required
|
bool
|
Check required fields, and report a group-only object such as
|
True
|
check_types
|
bool
|
Check field types |
True
|
check_ranges
|
bool
|
Check numeric ranges |
True
|
check_singletons
|
bool
|
Check singleton (maxProperties) constraints |
True
|
object_types
|
list[str] | None
|
Only validate these types (None = all) |
None
|
check_geometry
|
bool
|
Warn about a floor whose vertices make it face up, or a roof or
ceiling that faces down ( |
True
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Examples:
Validate a model before running a simulation:
>>> from idfkit import new_document, validate_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> result = validate_document(model)
>>> result.is_valid
True
>>> result.total_issues
0
Validate only material and construction definitions:
>>> result = validate_document(model, object_types=["Material", "Construction"])
>>> result.is_valid
True
Source code in idfkit/validation.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
validate_object(obj, schema, *, check_required=True, check_types=True, check_ranges=True, check_unknown=True)
¶
Validate a single object against schema.
This is a public API for validating individual objects, useful for checking objects at creation time with the validate=True option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
IDFObject
|
The IDFObject to validate |
required |
schema
|
EpJSONSchema
|
The EpJSON schema to validate against |
required |
check_required
|
bool
|
Check that required fields are present |
True
|
check_types
|
bool
|
Check that field values match expected types |
True
|
check_ranges
|
bool
|
Check that numeric values are within bounds |
True
|
check_unknown
|
bool
|
Check for unknown fields (not in schema) |
True
|
Returns:
| Type | Description |
|---|---|
list[ValidationError]
|
List of ValidationError objects describing any issues found |
Examples:
Check a newly created zone for schema violations:
>>> from idfkit import new_document, validate_object, get_schema, LATEST_VERSION
>>> model = new_document()
>>> zone = model.add("Zone", "Perimeter_ZN_1")
>>> errors = validate_object(zone, get_schema(LATEST_VERSION))
>>> len(errors)
0