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, cache=True)
¶
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
|
AnyIDFDocument
|
The document to migrate. Its |
required |
target_version
|
tuple[int, int, int] | str | type[AnyIDFDocument[Any]]
|
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
|
cache
|
bool
|
Reuse the result of an earlier migration of the same IDF
content along the same steps with the same EnergyPlus install,
kept in memory for this process (see
idfkit.migration.cache). The transition
binaries take seconds per step, so this is what makes repeated
|
True
|
Returns:
| Type | Description |
|---|---|
MigrationReport[AnyIDFDocument[Any]]
|
A MigrationReport whose |
MigrationReport[AnyIDFDocument[Any]]
|
|
MigrationReport[AnyIDFDocument[Any]]
|
migration (source equals target) no step runs and it is a copy of |
MigrationReport[AnyIDFDocument[Any]]
|
model, so |
MigrationReport[AnyIDFDocument[Any]]
|
whatever doc's version. |
MigrationReport[AnyIDFDocument[Any]]
|
The migrated document has no |
MigrationReport[AnyIDFDocument[Any]]
|
read from a scratch file in the work directory, and the source's path |
MigrationReport[AnyIDFDocument[Any]]
|
would make a bare |
MigrationReport[AnyIDFDocument[Any]]
|
another version. Save it to an explicit path, e.g. |
MigrationReport[AnyIDFDocument[Any]]
|
|
MigrationReport[AnyIDFDocument[Any]]
|
|
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If the target version is
not in |
TypeError
|
If target_version is a type that names no single release,
such as |
ValueError
|
If target_version is older than |
MigrationError
|
If any transition step fails. The
exception's |
EnergyPlusNotFoundError
|
If migrator is |
Source code in idfkit/migration/runner.py
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 146 147 148 149 150 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 | |
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, cache=True)
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
|
AnyIDFDocument
|
The document to migrate. |
required |
target_version
|
tuple[int, int, int] | str | type[AnyIDFDocument[Any]]
|
Target version: a tuple, a dotted string, or the target release's document type, which also types the report, as for migrate(). |
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
|
cache
|
bool
|
Reuse an earlier migration of the same content, shared with
migrate(); |
True
|
Returns:
| Type | Description |
|---|---|
MigrationReport[AnyIDFDocument[Any]]
|
A MigrationReport. As with |
MigrationReport[AnyIDFDocument[Any]]
|
migrate, the migrated document has no |
MigrationReport[AnyIDFDocument[Any]]
|
|
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
For an unsupported target, or a model whose version names no supported release. |
TypeError
|
If target_version is a type that names no single release. |
ValueError
|
If the target is older than |
MigrationError
|
On any transition-step failure; the
exception's |
EnergyPlusNotFoundError
|
If migrator is |
Source code in idfkit/migration/async_runner.py
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 146 147 148 149 150 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 | |
MigrationReport¶
idfkit.migration.report.MigrationReport
dataclass
¶
Bases: Generic[DocumentT_co]
Result of a full migration run.
Generic in the type of migrated_model. migrate
given a document type as its target, such as IDFDocumentV24_1 from
idfkit.versioned, returns a report typed for that release;
given a version tuple or string, whose release a type checker cannot know,
it returns one typed with AnyIDFDocument, as a bare MigrationReport
annotation also is.
Attributes:
| Name | Type | Description |
|---|---|---|
migrated_model |
DocumentT_co
|
The new document, 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). |
from_cache |
bool
|
|
Source code in idfkit/migration/report.py
completed_steps
property
¶
Steps that completed successfully, in order.
diff = field(default_factory=MigrationDiff)
class-attribute
instance-attribute
¶
failed_step
property
¶
The first step that failed, if any.
from_cache = False
class-attribute
instance-attribute
¶
migrated_model
instance-attribute
¶
requested_target
instance-attribute
¶
source_version
instance-attribute
¶
steps = ()
class-attribute
instance-attribute
¶
success
property
¶
True when every transition step succeeded (or none ran).
target_version
instance-attribute
¶
summary()
¶
Return a short multi-line summary suitable for logs or CLI output.
Source code in 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 idfkit/migration/report.py
audit_text = None
class-attribute
instance-attribute
¶
binary = None
class-attribute
instance-attribute
¶
from_version
instance-attribute
¶
runtime_seconds = 0.0
class-attribute
instance-attribute
¶
stderr = ''
class-attribute
instance-attribute
¶
stdout = ''
class-attribute
instance-attribute
¶
success
instance-attribute
¶
to_version
instance-attribute
¶
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 idfkit/migration/report.py
added_object_types = ()
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.
object_count_delta = field(default_factory=_empty_count_delta)
class-attribute
instance-attribute
¶
removed_object_types = ()
class-attribute
instance-attribute
¶
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 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 idfkit/migration/progress.py
from_version = None
class-attribute
instance-attribute
¶
message
instance-attribute
¶
percent = None
class-attribute
instance-attribute
¶
phase
instance-attribute
¶
step_index = None
class-attribute
instance-attribute
¶
to_version = None
class-attribute
instance-attribute
¶
total_steps = None
class-attribute
instance-attribute
¶
Migrator¶
idfkit.migration.protocol.Migrator
¶
Bases: Protocol
Protocol implemented by backends that migrate IDF text one version at a time.
Source code in 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 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 idfkit/migration/protocol.py
migrate_step(idf_text, from_version, to_version, *, work_dir)
async
¶
Async counterpart to Migrator.migrate_step.
Source code in 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 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 idfkit/migration/subprocess_backend.py
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 146 147 148 149 | |
cache_key
property
¶
What the output depends on besides the input: the transition binaries' directory.
Lets migrate() reuse an earlier migration of the same content (see idfkit.migration.cache). The synchronous and async backends share it, as they run the same binaries.
step_timeout = DEFAULT_STEP_TIMEOUT
class-attribute
instance-attribute
¶
version_updater_dir
instance-attribute
¶
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 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 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 idfkit/migration/async_subprocess_backend.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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
cache_key
property
¶
What the output depends on besides the input: the transition binaries' directory.
Lets migrate() reuse an earlier migration of the same content (see idfkit.migration.cache). The synchronous and async backends share it, as they run the same binaries.
step_timeout = DEFAULT_STEP_TIMEOUT
class-attribute
instance-attribute
¶
version_updater_dir
instance-attribute
¶
locate_binary(from_version, to_version)
¶
Return the absolute path to the transition binary for a single step.
Source code in 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 idfkit/migration/async_subprocess_backend.py
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 146 | |
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, |
required |
target
|
tuple[int, int, int]
|
The desired version, resolved to its release as source is
( |
required |
Returns:
| Type | Description |
|---|---|
tuple[TransitionStep, ...]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no supported release shares source's or target's major and minor. |
ValueError
|
If |
Examples:
Source code in 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
|
AnyIDFDocument
|
Document before migration. |
required |
after
|
AnyIDFDocument
|
Document after migration. |
required |
Returns:
| Type | Description |
|---|---|
MigrationDiff
|
A MigrationDiff capturing |
MigrationDiff
|
the observable changes. |
Source code in idfkit/migration/diff.py
resolve_source_version¶
idfkit.migration.chain.resolve_source_version(version)
¶
Resolve a model's version to the supported release a migration starts from.
An IDF file states its version with two components, so a document loaded from
a file headed Version, 9.0; carries (9, 0, 0) while the release is
9.0.1. The rest of idfkit (schema selection, as_version) matches the
version to its release line; a migration does the same, with
find_release. Unlike schema selection, a
version newer than every supported release is not snapped to the latest: a
model of an unknown release cannot be migrated from a neighbouring one.
Examples:
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no supported release has version's major and minor. |
Source code in idfkit/migration/chain.py
Migration cache¶
idfkit.migration.cache
¶
In-process memo of finished migrations.
Each Transition-VX-to-VY binary spends seconds loading its two IDDs, so a
migration across several releases takes tens of seconds even for a tiny model.
migrate() and
async_migrate() remember the migrated IDF
text of their last MAX_ENTRIES
migrations, keyed by the hash of the source IDF text, the chain of steps and
the migrator's cache_key (for the bundled backends, the
IDFVersionUpdater directory they run). Migrating the same content again,
as simulate(..., auto_migrate=True) does for every run of one model, then
only re-parses the result. Concurrent identical migrations run the binaries
once: later callers wait for the first and reuse its result.
A migrator without a cache_key attribute (or with None) is never
cached, so a custom backend opts in by exposing a string that changes when
its output would.
CacheKey = tuple[str, tuple[TransitionStep, ...], str]
module-attribute
¶
MAX_ENTRIES = 32
module-attribute
¶
CachedMigration
dataclass
¶
cache_key(idf_text, chain, migrator)
¶
The memo key for migrating idf_text along chain with migrator, or None.
None when migrator has no cache_key: its output cannot be assumed
to depend only on the input text.
cached_progress_event(chain)
¶
The transitioning event of a migration whose result is reused from the cache.
clear_migration_cache()
¶
get(key)
¶
The memoized migration for key, marking it most recently used.
in_flight(key)
¶
Hold the lock for key, so one thread migrates a content while the others wait for it.
in_flight_async(key)
async
¶
Async counterpart of in_flight, per event loop.
put(key, entry)
¶
Remember entry under key, dropping the least recently used beyond MAX_ENTRIES.