Migration API¶
Forward-migrate IDF models across EnergyPlus versions by orchestrating the
Transition-VX-to-VY binaries shipped in PreProcess/IDFVersionUpdater.
migrate¶
idfkit.migration.runner.migrate(model, target_version, *, energyplus=None, migrator=None, on_progress=None, work_dir=None, keep_work_dir=False)
¶
Forward-migrate model to target_version through EnergyPlus transition binaries.
Plans the chain of transition steps between model.version and
target_version, runs each one in sequence via the supplied migrator
(defaulting to a SubprocessMigrator
rooted at the EnergyPlus installation's PreProcess/IDFVersionUpdater
directory), re-parses the final IDF into a fresh
IDFDocument, and returns a structured
MigrationReport.
The input model is never mutated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The document to migrate. Its |
required |
target_version
|
tuple[int, int, int] | str
|
Either a |
required |
energyplus
|
EnergyPlusConfig | None
|
Pre-configured EnergyPlus installation. Ignored when migrator is provided. When neither is supplied, find_energyplus() is used to discover an installation automatically. |
None
|
migrator
|
Migrator | None
|
Custom backend implementing Migrator. Overrides energyplus when provided. |
None
|
on_progress
|
OnMigrationProgress | None
|
Optional callback invoked with MigrationProgress events on every phase transition. |
None
|
work_dir
|
str | Path | None
|
Directory in which to stage per-step work subdirectories.
Defaults to a newly-created temporary directory. The directory is
removed after migration unless keep_work_dir is |
None
|
keep_work_dir
|
bool
|
Set |
False
|
Returns:
| Type | Description |
|---|---|
MigrationReport
|
A MigrationReport whose |
MigrationReport
|
|
MigrationReport
|
equals target) — in that case the caller's original model is the |
MigrationReport
|
result. |
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If either the source or
target version is not in
|
ValueError
|
If target_version is older than |
MigrationError
|
If any transition step fails. The
exception's |
EnergyPlusNotFoundError
|
If migrator is |
Source code in src/idfkit/migration/runner.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
async_migrate¶
idfkit.migration.async_runner.async_migrate(model, target_version, *, energyplus=None, migrator=None, on_progress=None, work_dir=None, keep_work_dir=False)
async
¶
Async counterpart to migrate().
Same semantics as the sync version; the only difference is that each transition step is driven via asyncio.create_subprocess_exec (or a caller-supplied AsyncMigrator), and progress callbacks may be async.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The document to migrate. |
required |
target_version
|
tuple[int, int, int] | str
|
Target version (tuple or dotted string). |
required |
energyplus
|
EnergyPlusConfig | None
|
EnergyPlus installation. Ignored when migrator is set. |
None
|
migrator
|
AsyncMigrator | None
|
Optional AsyncMigrator.
When |
None
|
on_progress
|
OnMigrationProgress | None
|
Optional sync or async callback receiving MigrationProgress events. |
None
|
work_dir
|
str | Path | None
|
Directory in which to stage per-step working directories.
Defaults to a newly-created temporary directory that is removed
after the migration unless keep_work_dir is |
None
|
keep_work_dir
|
bool
|
Preserve intermediate files for inspection. |
False
|
Returns:
| Type | Description |
|---|---|
MigrationReport
|
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
For an unsupported version. |
ValueError
|
If the target is older than |
MigrationError
|
On any transition-step failure; the
exception's |
EnergyPlusNotFoundError
|
If migrator is |
Source code in src/idfkit/migration/async_runner.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
MigrationReport¶
idfkit.migration.report.MigrationReport
dataclass
¶
Result of a full migration run.
Attributes:
| Name | Type | Description |
|---|---|---|
migrated_model |
IDFDocument | None
|
The IDFDocument at
|
source_version |
tuple[int, int, int]
|
The version the model started at. |
target_version |
tuple[int, int, int]
|
The version the model was migrated to. On a partial failure this is the last successfully reached version, which may be earlier than the originally-requested target. |
requested_target |
tuple[int, int, int]
|
The originally-requested target version. |
steps |
tuple[MigrationStep, ...]
|
Ordered record of every transition step that ran. |
diff |
MigrationDiff
|
Structural diff computed after migration. Empty when no steps ran (source == target). |
Source code in src/idfkit/migration/report.py
migrated_model
instance-attribute
¶
source_version
instance-attribute
¶
target_version
instance-attribute
¶
requested_target
instance-attribute
¶
steps = ()
class-attribute
instance-attribute
¶
diff = field(default_factory=MigrationDiff)
class-attribute
instance-attribute
¶
success
property
¶
True when every transition step succeeded (or none ran).
completed_steps
property
¶
Steps that completed successfully, in order.
failed_step
property
¶
The first step that failed, if any.
summary()
¶
Return a short multi-line summary suitable for logs or CLI output.
Source code in src/idfkit/migration/report.py
MigrationStep¶
idfkit.migration.report.MigrationStep
dataclass
¶
Record of a single transition step.
Attributes:
| Name | Type | Description |
|---|---|---|
from_version |
tuple[int, int, int]
|
Source version for this step. |
to_version |
tuple[int, int, int]
|
Target version for this step. |
success |
bool
|
Whether the step completed without error. |
binary |
Path | None
|
Path to the transition binary that was invoked, if any. |
stdout |
str
|
Captured standard output (may be empty). |
stderr |
str
|
Captured standard error (may be empty). |
audit_text |
str | None
|
Contents of the per-step |
runtime_seconds |
float
|
Wall-clock runtime of the step. |
Source code in src/idfkit/migration/report.py
MigrationDiff¶
idfkit.migration.report.MigrationDiff
dataclass
¶
Structural diff between pre- and post-migration documents.
Attributes:
| Name | Type | Description |
|---|---|---|
added_object_types |
tuple[str, ...]
|
Types present after migration but not before. |
removed_object_types |
tuple[str, ...]
|
Types present before migration but not after. |
object_count_delta |
dict[str, int]
|
Per-type signed change in object count. Includes only types with a nonzero delta. |
field_changes |
dict[str, FieldDelta]
|
Per-type schema-level field changes (only types present in both the before and after schemas are included). |
Source code in src/idfkit/migration/report.py
added_object_types = ()
class-attribute
instance-attribute
¶
removed_object_types = ()
class-attribute
instance-attribute
¶
object_count_delta = field(default_factory=_empty_count_delta)
class-attribute
instance-attribute
¶
field_changes = field(default_factory=_empty_field_changes)
class-attribute
instance-attribute
¶
is_empty
property
¶
True when the migration produced no observable structural change.
FieldDelta¶
idfkit.migration.report.FieldDelta
dataclass
¶
Per-object-type summary of field changes introduced by the migration.
Attributes:
| Name | Type | Description |
|---|---|---|
added |
tuple[str, ...]
|
Field names present in to_version schema but not in from_version. |
removed |
tuple[str, ...]
|
Field names present in from_version schema but not in to_version. |
Source code in src/idfkit/migration/report.py
MigrationProgress¶
idfkit.migration.progress.MigrationProgress
dataclass
¶
Progress event emitted during a migration run.
Attributes:
| Name | Type | Description |
|---|---|---|
phase |
MigrationPhase
|
Current migration phase. |
message |
str
|
Short human-readable description of the current step. |
step_index |
int | None
|
0-based index of the current transition step
(only set during the |
total_steps |
int | None
|
Total number of transition steps in the chain (only set once the chain has been planned). |
from_version |
tuple[int, int, int] | None
|
Source version of the current step, if known. |
to_version |
tuple[int, int, int] | None
|
Target version of the current step, if known. |
percent |
float | None
|
Estimated completion percentage ( |
Source code in src/idfkit/migration/progress.py
Migrator¶
idfkit.migration.protocol.Migrator
¶
Bases: Protocol
Protocol implemented by backends that migrate IDF text one version at a time.
Source code in src/idfkit/migration/protocol.py
migrate_step(idf_text, from_version, to_version, *, work_dir)
¶
Migrate idf_text from from_version to to_version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idf_text
|
str
|
The source IDF text. |
required |
from_version
|
tuple[int, int, int]
|
The source version; the migrator should assume the IDF conforms to this version's IDD. |
required |
to_version
|
tuple[int, int, int]
|
The target version; the migrator must emit IDF text that conforms to this version's IDD. |
required |
work_dir
|
Path
|
A clean working directory the backend may use for intermediate files. Caller owns cleanup. |
required |
Returns:
| Type | Description |
|---|---|
MigrationStepResult
|
|
MigrationStepResult
|
for this single step. |
Raises:
| Type | Description |
|---|---|
MigrationError
|
If the migration fails. |
Source code in src/idfkit/migration/protocol.py
AsyncMigrator¶
idfkit.migration.protocol.AsyncMigrator
¶
Bases: Protocol
Async counterpart to Migrator.
Implementations perform a single version-step migration without blocking
the event loop. The default implementation,
AsyncSubprocessMigrator,
uses asyncio.create_subprocess_exec to drive the Transition-VX-to-VY
binaries shipped with EnergyPlus.
Source code in src/idfkit/migration/protocol.py
migrate_step(idf_text, from_version, to_version, *, work_dir)
async
¶
Async counterpart to Migrator.migrate_step.
Source code in src/idfkit/migration/protocol.py
MigrationStepResult¶
idfkit.migration.protocol.MigrationStepResult
dataclass
¶
Result of a single-step migration.
Attributes:
| Name | Type | Description |
|---|---|---|
idf_text |
str
|
The migrated IDF source text. |
stdout |
str
|
Captured standard output (may be empty). |
stderr |
str
|
Captured standard error (may be empty). |
audit_text |
str | None
|
Contents of the per-step |
Source code in src/idfkit/migration/protocol.py
SubprocessMigrator¶
idfkit.migration.subprocess_backend.SubprocessMigrator
dataclass
¶
Migrator backend that shells out to EnergyPlus's transition binaries.
Attributes:
| Name | Type | Description |
|---|---|---|
version_updater_dir |
Path
|
Path to |
step_timeout |
float
|
Maximum wall-clock seconds for a single transition step. |
Source code in src/idfkit/migration/subprocess_backend.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
locate_binary(from_version, to_version)
¶
Return the absolute path to the transition binary for a single step.
Tries the registry-exact name first, then falls back to (major, minor, 0)
for either side -- EnergyPlus's transition binaries are always named with
patch=0 (notably, v9.0.1 uses the V9-0-0 binary name).
Source code in src/idfkit/migration/subprocess_backend.py
migrate_step(idf_text, from_version, to_version, *, work_dir)
¶
Run a single Transition-VX-to-VY binary on idf_text.
Source code in src/idfkit/migration/subprocess_backend.py
AsyncSubprocessMigrator¶
idfkit.migration.async_subprocess_backend.AsyncSubprocessMigrator
dataclass
¶
Async migrator backend built on asyncio.create_subprocess_exec.
Attributes:
| Name | Type | Description |
|---|---|---|
version_updater_dir |
Path
|
Path to |
step_timeout |
float
|
Maximum wall-clock seconds for a single transition step. |
Source code in src/idfkit/migration/async_subprocess_backend.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
locate_binary(from_version, to_version)
¶
Return the absolute path to the transition binary for a single step.
Source code in src/idfkit/migration/async_subprocess_backend.py
migrate_step(idf_text, from_version, to_version, *, work_dir)
async
¶
Run a single Transition-VX-to-VY binary without blocking.
Source code in src/idfkit/migration/async_subprocess_backend.py
plan_migration_chain¶
idfkit.migration.chain.plan_migration_chain(source, target)
¶
Plan the ordered list of transition steps from source to target.
The chain walks forward through ENERGYPLUS_VERSIONS
from source to target, emitting a (from, to) pair for each
consecutive version boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
tuple[int, int, int]
|
The model's current version. Must be in |
required |
target
|
tuple[int, int, int]
|
The desired version. Must be in |
required |
Returns:
| Type | Description |
|---|---|
tuple[TransitionStep, ...]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If source or target is not a supported version. |
ValueError
|
If |
Source code in src/idfkit/migration/chain.py
document_diff¶
idfkit.migration.diff.document_diff(before, after)
¶
Compute a structural diff between before and after.
The diff compares the two documents at three levels:
- Object types present in one document but not the other.
- Per-type signed change in object count.
- Per-type schema-level field renames (computed from each document's
bundled schema — so
afterpicks up fields that only exist in the newer IDD, andbeforemay carry fields that have since been removed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before
|
IDFDocument
|
Document before migration. |
required |
after
|
IDFDocument
|
Document after migration. |
required |
Returns:
| Type | Description |
|---|---|
MigrationDiff
|
A MigrationDiff capturing |
MigrationDiff
|
the observable changes. |