tlpytools 0.2.10__tar.gz → 0.2.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/copilot-instructions.md +3 -3
  2. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/skills/prepare-official-release/SKILL.md +2 -2
  3. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/workflows/deploy.yml +1 -1
  4. {tlpytools-0.2.10 → tlpytools-0.2.12}/CHANGELOG.md +136 -0
  5. {tlpytools-0.2.10 → tlpytools-0.2.12}/DEVELOPER_GUIDE.md +3 -3
  6. {tlpytools-0.2.10 → tlpytools-0.2.12}/PKG-INFO +3 -3
  7. {tlpytools-0.2.10 → tlpytools-0.2.12}/README.md +1 -1
  8. {tlpytools-0.2.10 → tlpytools-0.2.12}/pyproject.toml +2 -2
  9. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/__init__.py +1 -1
  10. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/README.md +140 -35
  11. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/batch_task_runner.py +236 -29
  12. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/cli.py +54 -2
  13. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/orchestrator.py +1234 -473
  14. tlpytools-0.2.12/tests/test_orca_cli_batch_options.py +584 -0
  15. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/test_orca_integration.py +21 -9
  16. tlpytools-0.2.12/tests/test_orca_resume_cloud.py +1418 -0
  17. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/test_orca_unit.py +98 -0
  18. tlpytools-0.2.12/uv.lock +5045 -0
  19. tlpytools-0.2.10/docs/diagrams/README.md +0 -94
  20. tlpytools-0.2.10/docs/diagrams/orca_cloud_workflow.drawio +0 -157
  21. tlpytools-0.2.10/docs/diagrams/orca_detailed_steps.drawio +0 -121
  22. tlpytools-0.2.10/docs/diagrams/orca_file_structure.drawio +0 -88
  23. tlpytools-0.2.10/docs/diagrams/orca_local_workflow.drawio +0 -127
  24. tlpytools-0.2.10/docs/diagrams/orca_main_features.drawio +0 -103
  25. tlpytools-0.2.10/uv.lock +0 -5006
  26. {tlpytools-0.2.10 → tlpytools-0.2.12}/.env.example +0 -0
  27. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/skills/README.md +0 -0
  28. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/workflows/code-formatting-pr.yml +0 -0
  29. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/workflows/code-formatting.yml +0 -0
  30. {tlpytools-0.2.10 → tlpytools-0.2.12}/.github/workflows/test.yml +0 -0
  31. {tlpytools-0.2.10 → tlpytools-0.2.12}/.gitignore +0 -0
  32. {tlpytools-0.2.10 → tlpytools-0.2.12}/.pre-commit-config.yaml +0 -0
  33. {tlpytools-0.2.10 → tlpytools-0.2.12}/.python-version +0 -0
  34. {tlpytools-0.2.10 → tlpytools-0.2.12}/ENVIRONMENT_VARIABLES.md +0 -0
  35. {tlpytools-0.2.10 → tlpytools-0.2.12}/Makefile +0 -0
  36. {tlpytools-0.2.10 → tlpytools-0.2.12}/docs/adls_server.md +0 -0
  37. {tlpytools-0.2.10 → tlpytools-0.2.12}/docs/azure_credential_manager.md +0 -0
  38. {tlpytools-0.2.10 → tlpytools-0.2.12}/docs/unified_logging.md +0 -0
  39. {tlpytools-0.2.10 → tlpytools-0.2.12}/requirements.txt +0 -0
  40. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/examples/batchtask.py +0 -0
  41. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/examples/data_files/example.csv +0 -0
  42. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/examples/mydataproject.py +0 -0
  43. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/examples/readwritedata.py +0 -0
  44. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/examples/unified_logging.py +0 -0
  45. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/adls_server.py +0 -0
  46. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/azure_credential.py +0 -0
  47. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/config.py +0 -0
  48. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/data.py +0 -0
  49. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/data_store.py +0 -0
  50. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/env_config.py +0 -0
  51. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/log.py +0 -0
  52. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/__init__.py +0 -0
  53. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/__main__.py +0 -0
  54. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/orca_model_config_barebone.yaml +0 -0
  55. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/orca/orca_model_config_example.yaml +0 -0
  56. {tlpytools-0.2.10 → tlpytools-0.2.12}/src/tlpytools/sql_server.py +0 -0
  57. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/README.md +0 -0
  58. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/__init__.py +0 -0
  59. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/conftest.py +0 -0
  60. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/run_tests.py +0 -0
  61. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/test_azure_credential.py +0 -0
  62. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/test_basic.py +0 -0
  63. {tlpytools-0.2.10 → tlpytools-0.2.12}/tests/test_core.py +0 -0
@@ -10,7 +10,7 @@
10
10
  - Primary language: Python (source under `src/`).
11
11
  - Build system: `hatchling` via `pyproject.toml`.
12
12
  - Dependency manager used in CI/docs: `uv`.
13
- - Runtime constraint in packaging: Python `>=3.10.0, <3.13` (default: 3.12).
13
+ - Runtime constraint in packaging: Python `>=3.11, <3.14` (default: 3.12).
14
14
  - CI workflows are under `.github/workflows/`:
15
15
  - `test.yml` (core + ORCA tests on Ubuntu/Windows)
16
16
  - `code-formatting.yml` (Black formatting gate)
@@ -98,8 +98,8 @@ Interpretation for agent PRs:
98
98
 
99
99
  Observed result:
100
100
  - Build succeeds and produces:
101
- - `dist/tlpytools-0.2.10.tar.gz`
102
- - `dist/tlpytools-0.2.10-py3-none-any.whl`
101
+ - `dist/tlpytools-0.2.12.tar.gz`
102
+ - `dist/tlpytools-0.2.12-py3-none-any.whl`
103
103
 
104
104
  ### 5) Run
105
105
  - ORCA CLI (module form):
@@ -276,7 +276,7 @@ Note: Review .github/workflows/deploy.yml for the automated deployment process.
276
276
 
277
277
  ### For tlpytools:
278
278
 
279
- - **Python version:** Currently requires Python >=3.12.0, <3.13
279
+ - **Python version:** Currently requires Python >=3.11, <3.14
280
280
  - **Test environment:** Requires `.env` file (copy from `.env.example`)
281
281
  - **ORCA tests:** Require Azure environment variables to be set
282
282
  - **CI/CD:** Uses `uv` for dependency management
@@ -443,7 +443,7 @@ Run all tests in sequence (not parallel) to avoid resource conflicts:
443
443
  **Example 3 - Repository Change:**
444
444
  ```markdown
445
445
  **Update to Repository-Specific Notes:**
446
- - **Python version:** Updated to >=3.12.0, <3.13 as of 2026-06-17
446
+ - **Python version:** Updated to >=3.11, <3.14 for the 0.2.12 release
447
447
  - Previous versions used 3.10
448
448
  - Update affects CI workflows and local development
449
449
  - All dependencies verified compatible with 3.12
@@ -4,7 +4,7 @@ on:
4
4
  workflow_dispatch:
5
5
  inputs:
6
6
  version:
7
- description: 'Version number to release (e.g., 0.2.10)'
7
+ description: 'Version number to release (e.g., 0.2.12)'
8
8
  required: true
9
9
  type: string
10
10
  prerelease:
@@ -2,6 +2,142 @@
2
2
 
3
3
  All notable changes to TLPyTools will be documented in this file.
4
4
 
5
+ ## [0.2.12]
6
+
7
+ ### Added
8
+ - **`full_cloud_sync` option (top-level key in the ORCA model config YAML, default `false`):**
9
+ - Upload: once the model run completes, every sub-component folder is zipped and uploaded as
10
+ `<component>.zip`; the previous cloud zip is renamed `<component>_<YYYYMMDD_HHMMSS>.bak.zip`
11
+ and moved to `.cloud_model_archive/`
12
+ - Download: with the flag set in the user's local YAML, each local sub-component folder is
13
+ renamed `<component>_<YYYYMMDD_HHMMSS>.bak` as the final cloud version is extracted, and the
14
+ final folders are downloaded along with state, outputs and logs (`inputs` is left alone); this
15
+ only happens once the cloud run has completed, since earlier cloud zips are not final
16
+
17
+ ### Fixed
18
+ - **Upload of a scenario with a long folder path failed on Windows:** zipping or extracting a
19
+ sub-component folder that holds paths over 260 characters (for example deep ActivitySim trace
20
+ folders under a long scenario name) failed with `WinError 3`. `zip_directory`,
21
+ `unpack_zip_file` and the component download cleanup now use extended-length paths on Windows
22
+ - **A failed full upload left a cloud scenario that looked valid:** when the run had not started,
23
+ or no cloud copy existed, a failed component or inputs zip still let the state file and outputs
24
+ upload. The upload now stops before uploading outputs, state and config, so the next upload
25
+ starts over as a full upload instead of finding a state file with missing component zips
26
+ - **Repeated `full_cloud_sync` downloads created a new `.bak` each time:** local sub-component
27
+ folders are now replaced only when the cloud run is completed and strictly ahead of the local
28
+ state
29
+ - **A failed full-cloud download could leave a mixed local scenario:** if one component archive
30
+ failed after earlier component folders had been replaced, the local scenario could contain a
31
+ mixture of cloud and pre-existing component data. Full-cloud component replacements are now
32
+ rolled back when any component download or extraction fails, before the sync reports failure
33
+ - **Full-cloud replacement failures could leave stale or mixed local files:** config and state
34
+ files are now downloaded as a pair before either replaces the local copy, and a later config,
35
+ state, or output failure rolls back component replacements and resume output renames
36
+ - **Unsafe cloud paths could escape their target folders:** downloaded `outputs/` and
37
+ `logs/` paths, and paths handled by `download_from_adls_by_pattern()`, are now validated
38
+ against their intended local roots before any file operation; a failed outputs download also
39
+ removes the files it had already written
40
+ - **A failed replacement upload could hide the previous cloud copy:** conflict handling now
41
+ attempts to restore the previous cloud file when the replacement upload fails
42
+ - **Resuming a run on the cloud from a mid-run local scenario could fail:** uploads made after the
43
+ first step only sent outputs and state, and an upload of a mid-run scenario to a cloud folder
44
+ with no remote copy sent only per-step `.cloud_model_archive/` zips, never the main
45
+ `<component>.zip`/`inputs.zip`. Now an upload sends everything while the model run has not
46
+ started, and mid-run sends any sub-component folder (and `inputs`) missing from the cloud in
47
+ addition to new outputs. Whenever a component zip is replaced, the previous cloud copy moves to
48
+ `.cloud_model_archive/<component>_<YYYYMMDD_HHMMSS>.bak.zip` (previously `.cloud_sync_conflict/`),
49
+ matching the `<component>_<YYYYMMDD_HHMMSS>.bak` name used for local component folders. The
50
+ per-step `.cloud_model_archive/<component>_iter<N>.zip` upload, which only occurred on that
51
+ faulty path, is no longer produced
52
+
53
+ ## [0.2.11]
54
+
55
+ ### Added
56
+ - **`run_model` execution granularity (`--execution-options`/`--resume-iteration`/`--resume-step`):**
57
+ - `tlpytools.orca.cli`'s `run_model` action can now run just one step (`one_step`), all remaining
58
+ steps in the current iteration (`one_iteration`), or the full remaining model (`full`, default)
59
+ - `--resume-iteration`/`--resume-step` reset state to a specific point (via `resume_from_step()`)
60
+ before running; `--resume-step` requires `--resume-iteration`
61
+ - `BatchTaskRunner` (`batch_task_runner.py`, both the `main()` CLI and `submit_task`/`run_task`)
62
+ accepts the same options and forwards them to the Azure Batch container's `run_model` command,
63
+ so a single step/iteration can be debugged remotely without running the full model
64
+ - **`OrcaOrchestrator.get_remote_state()`:** public wrapper around the existing ADLS config +
65
+ state-download helpers, returning the scenario's actual cloud state (or `None`) so callers can
66
+ validate local assumptions against cloud progress before triggering Azure Batch operations
67
+ - **`status_callback` for `BatchTaskRunner.run_task()`/`wait_for_task_completion()`:** optional
68
+ `callable(state, message)` invoked during the duplicate check, task creation and after every poll
69
+ with the Batch task state, so a notebook can show live progress instead of a static "submitting"
70
+
71
+ ### Fixed
72
+ - **Duplicate task submission no longer errors on a task that is already in progress:**
73
+ `BatchTaskRunner.run_task()` now attaches to a matching `active`/`preparing`/`running` task
74
+ (newest if several) and reports its status, instead of raising. A successfully completed
75
+ matching task still blocks; `skip_duplicate_check=True` still always submits a new task
76
+ - **Failed Batch tasks were reported as successful:** Azure Batch reports a task whose command
77
+ exited non-zero as state `completed` (with `executionInfo.result = "failure"`), and
78
+ `BatchTaskRunner` only checked the state name. It now treats a failed result or non-zero exit
79
+ code as a failed task (and shows the exit code), so the new "failed cloud sync fails the run"
80
+ behavior actually reaches the caller. The duplicate-task check likewise no longer lets such a
81
+ task block resubmission
82
+ - **Cloud resume left regenerated outputs un-uploaded:** `_backup_affected_outputs()` renamed
83
+ archives only on the Batch VM, so the old canonical blobs stayed in ADLS and the outputs upload
84
+ (which skips existing names) never uploaded the regenerated files. In `cloud_production` mode
85
+ the matching ADLS blobs (including archives that exist only in ADLS) are now renamed to the
86
+ same `_bak` names before the local rename; a failed ADLS rename or listing aborts the resume
87
+ and leaves the local files untouched
88
+ - **Cloud upload blocked after a resume to an earlier point:** a resume rewinds
89
+ `total_steps_completed`, so the upload check saw the cloud state as ahead and refused every
90
+ upload. The state now carries `resume_generation`, incremented by a rewinding resume and
91
+ honored by `OrcaState.compare_states()`, so the rewound state can replace the older cloud copy
92
+ (and a local copy can download a rewound cloud scenario)
93
+ - **`resume_from_step()` ran a whole iteration when `resume_step` was omitted for the current
94
+ iteration,** and did nothing on a completed run. It now only rewinds the state (the caller then
95
+ runs with the chosen granularity); a resume point ahead of current progress or outside the
96
+ `start_at`-based iteration range is rejected, and `total_steps_completed` is computed from
97
+ `start_at`. The `output_archives` registry no longer lists archives renamed by a backup
98
+ - **Backup filename parsing:** archives are matched with an end-anchored pattern and the longest
99
+ matching step name, so a step named `run` no longer captures `run_extended_*` archives
100
+ - **Regenerated outputs skipped by the outputs upload:** files are now compared by path below
101
+ `outputs/` (not basename), and archives created in the current session are always uploaded,
102
+ with any same-named cloud copy moved to `.cloud_sync_conflict/` first; failed output uploads
103
+ now fail the sync instead of being reported as success
104
+ - **Cloud sync failures no longer reported as success:** a failed final upload (`run`) or per-step
105
+ upload (`run_one_step`/`run_one_iteration`) fails the run so the Batch task exits non-zero;
106
+ `status` is set to `completed` before the last step syncs, and `run_one_iteration` syncs the
107
+ completed iteration
108
+ - **Config/state upload success** required only that any file (including logs) uploaded; the
109
+ config and state files must now all upload
110
+ - **Overwrite of the only cloud copy:** `_upload_file_with_conflict_handling()` continued with the
111
+ upload when moving the existing file to `.cloud_sync_conflict/` failed; it now returns failure.
112
+ Conflict backup names have seconds resolution
113
+ - **Incomplete downloads reported as success:** failed component, config/state or output
114
+ downloads now fail `_download_all_from_cloud()`/`_download_state_and_outputs()` (so a cloud run
115
+ does not start on a partial scenario); components are extracted to a staging folder and config
116
+ files are downloaded before the existing ones are replaced, so a failure no longer deletes the
117
+ working copy; nested `outputs/` paths are preserved; a local pre-resume archive is renamed to
118
+ match a cloud resume backup so the regenerated archive downloads
119
+ - **`unpack_zip_file()`** refuses archive members that resolve outside the output folder and
120
+ returns `False` if any member fails to extract
121
+ - **`_execute_step()`** restores the working directory, stops the performance monitor and
122
+ terminates the component process if the step raises; a failed output archive (zip or copy) now
123
+ fails the step and is not registered in the state
124
+ - **State file:** written atomically; an unreadable file is kept as `.corrupt_<timestamp>`
125
+ instead of being silently replaced
126
+ - **`_sync_state_with_config()`** compared the current iteration to the iteration count, which
127
+ was wrong when `start_at` is not 1
128
+ - **`export_detailed_data()`** no longer fails for a bare filename (empty directory part)
129
+ - Remote state cache is cleared after an upload
130
+ - **ADLS connection timeout was ineffective:** `_get_adls_connection_with_timeout()` waited for a
131
+ hung connection to finish when leaving its `ThreadPoolExecutor` block, so the timeout never
132
+ fired. It now uses a daemon thread with a bounded join
133
+ - **`run_one_step()`/`run_one_iteration()` on an already-complete run** now correct a stale
134
+ `status` (for example `error`) to `completed`
135
+
136
+ ### Changed
137
+ - `download_from_adls_by_pattern()` accepts `raise_on_error=True` to raise instead of returning
138
+ `[]`, so a failed listing can be told apart from "no matching files" (used when planning a
139
+ cloud resume backup; the default behavior is unchanged)
140
+
5
141
  ## [0.2.10]
6
142
 
7
143
  ### Fixed
@@ -15,7 +15,7 @@ This guide provides information for developers contributing to and maintaining t
15
15
 
16
16
  ### Prerequisites
17
17
 
18
- - Python 3.12 or higher
18
+ - Python `>=3.11,<3.14`
19
19
  - [uv](https://docs.astral.sh/uv/) (recommended) or pip
20
20
  - Git
21
21
 
@@ -200,7 +200,7 @@ make check-all
200
200
  4. Click **"Run workflow"** button
201
201
  5. Fill in the required information:
202
202
  - **Branch**: Select `main` (or your release branch)
203
- - **Version number**: Enter the new version (e.g., `0.2.10`)
203
+ - **Version number**: Enter the new version (e.g., `0.2.12`)
204
204
  - **Is this a pre-release?**: Check if this is a pre-release version
205
205
 
206
206
  #### 3. Monitor the Release
@@ -219,7 +219,7 @@ After the workflow completes:
219
219
 
220
220
  ```bash
221
221
  # Verify the package is available on PyPI
222
- pip install tlpytools==0.2.10 # Replace with your version
222
+ pip install tlpytools==0.2.12 # Replace with your version
223
223
 
224
224
  # Test installation in a fresh environment
225
225
  python -c "import tlpytools; print(tlpytools.__version__)"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tlpytools
3
- Version: 0.2.10
3
+ Version: 0.2.12
4
4
  Summary: TransLink's Python Tools - A comprehensive toolkit for transportation modeling and forecasting
5
5
  Project-URL: Homepage, https://github.com/TransLinkForecasting/tlpytools
6
6
  Project-URL: Bug Tracker, https://github.com/TransLinkForecasting/tlpytools/issues
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Topic :: Scientific/Engineering
15
15
  Classifier: Topic :: Scientific/Engineering :: GIS
16
- Requires-Python: <3.13,>=3.10.0
16
+ Requires-Python: <3.14,>=3.11
17
17
  Requires-Dist: azure-core>=1.39
18
18
  Requires-Dist: azure-identity-broker>=1.3.0
19
19
  Requires-Dist: azure-identity>=1.25
@@ -75,7 +75,7 @@ TLPyTools provides a suite of utilities and tools designed to support various as
75
75
 
76
76
  ## Installation
77
77
 
78
- > **Note**: TLPyTools requires Python 3.12 or higher. ActivitySim and PopulationSim are available for development installations using uv sync.
78
+ > **Note**: TLPyTools requires Python `>=3.11,<3.14`. ActivitySim and PopulationSim are available for development installations using uv sync.
79
79
 
80
80
  ### Using uv (Recommended)
81
81
 
@@ -8,7 +8,7 @@ TLPyTools provides a suite of utilities and tools designed to support various as
8
8
 
9
9
  ## Installation
10
10
 
11
- > **Note**: TLPyTools requires Python 3.12 or higher. ActivitySim and PopulationSim are available for development installations using uv sync.
11
+ > **Note**: TLPyTools requires Python `>=3.11,<3.14`. ActivitySim and PopulationSim are available for development installations using uv sync.
12
12
 
13
13
  ### Using uv (Recommended)
14
14
 
@@ -4,10 +4,10 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "tlpytools"
7
- version = "0.2.10"
7
+ version = "0.2.12"
8
8
  description = "TransLink's Python Tools - A comprehensive toolkit for transportation modeling and forecasting"
9
9
  readme = "README.md"
10
- requires-python = ">=3.10.0, <3.13"
10
+ requires-python = ">=3.11,<3.14"
11
11
  # license = { file = "LICENSE.txt" }
12
12
  authors = [
13
13
  { name = "Forecasting TransLink", email = "forecasting@translink.ca" }
@@ -2,7 +2,7 @@
2
2
  TLPyTools - A set of tools for building models at the TransLink Forecasting Team
3
3
  """
4
4
 
5
- __version__ = "0.2.10"
5
+ __version__ = "0.2.12"
6
6
 
7
7
  # Core modules that should always be available (minimal dependencies)
8
8
  from . import log
@@ -112,6 +112,15 @@ python -m tlpytools.orca --action run_model \
112
112
  --scenario db_example \
113
113
  --mode cloud_production \
114
114
  --project custom_project
115
+
116
+ # Debugging: run just one step, then stop
117
+ python -m tlpytools.orca --action run_model --scenario db_example --execution-options one_step
118
+
119
+ # Debugging: run just one iteration, then stop
120
+ python -m tlpytools.orca --action run_model --scenario db_example --execution-options one_iteration
121
+
122
+ # Debugging: reset state to iteration 2, step 'quetzal', then run the full remaining model
123
+ python -m tlpytools.orca --action run_model --scenario db_example --resume-iteration 2 --resume-step quetzal
115
124
  ```
116
125
 
117
126
  #### 2. Initialize Scenario (`init_model`)
@@ -148,6 +157,9 @@ python -m tlpytools.orca --action adls_sync --project my_project_folder --scenar
148
157
  | `--scenario` | Name of the scenario | `db_test` |
149
158
  | `--mode` | Execution mode (`local_testing`, `cloud_production`) | `local_testing` |
150
159
  | `--project` | Override ADLS project folder path (see priority below) | From config file |
160
+ | `--execution-options` | `run_model` granularity: `full`, `one_step`, or `one_iteration` (run_model only) | `full` |
161
+ | `--resume-iteration` | Reset state to this iteration before running (run_model only) | None |
162
+ | `--resume-step` | Reset state to this step name before running; requires `--resume-iteration` (run_model only) | None |
151
163
  | `--verbose` | Enable verbose logging | `False` |
152
164
 
153
165
  **ADLS Project Folder Priority:**
@@ -298,6 +310,11 @@ operational_mode:
298
310
  adls_container: "raw"
299
311
  adls_folder: "orca_scenarios"
300
312
 
313
+ # Optional: upload every sub-component folder as a zip when the model run completes, and
314
+ # back up + replace local sub-component folders on download (default false; see
315
+ # "Full Cloud Sync" under Cloud Synchronization Behavior)
316
+ full_cloud_sync: false
317
+
301
318
  # Model metadata (optional - can be set via orchestrator or in config)
302
319
  model_metadata:
303
320
  model_year: 2033
@@ -456,7 +473,7 @@ Logs are written to `orca_YYYYMMDD_HHMMSS.log` in the scenario directory.
456
473
 
457
474
  ## Model Execution and Resume Behavior
458
475
 
459
- The orchestrator uses the configuration file and state file to determine what to run. **All execution parameters (iterations, steps) come from the config file** - there are no CLI overrides for these.
476
+ The orchestrator uses the configuration file and state file to determine what to run. **The total number of iterations and the list of steps come from the config file** - there are no CLI overrides for these totals. The CLI does support overriding *where in that sequence* a run starts or stops, via `--execution-options`/`--resume-iteration`/`--resume-step` (see [Options](#options) above) - useful for debugging a single step or iteration without editing the config file.
460
477
 
461
478
  ### First Run
462
479
  When you run a model for the first time (no state file exists):
@@ -482,11 +499,34 @@ To restart a model from the beginning:
482
499
  1. Delete or rename the state file (`orca_model_state.json`)
483
500
  2. Or delete the entire scenario and reinitialize with `--action init_model`
484
501
 
502
+ ### Restarting From a Specific Iteration/Step
503
+ To re-run from a specific point without discarding everything before it, pass `--resume-iteration`
504
+ (and optionally `--resume-step`) to `run_model`:
505
+
506
+ ```bash
507
+ # Reset state to iteration 2, step 'quetzal', then run the full remaining model
508
+ python -m tlpytools.orca --action run_model --scenario db_example --resume-iteration 2 --resume-step quetzal
509
+ ```
510
+
511
+ - `--resume-step` requires `--resume-iteration`; omit `--resume-step` to resume from the start of
512
+ that iteration. Iterations are numbered from `iterations.start_at` (default 1).
513
+ - A resume only rewinds the scenario to that point; the run that follows (full, one iteration or
514
+ one step) is chosen with `--execution-options`. Resuming at the point the run is already at is
515
+ allowed and changes nothing.
516
+ - A resume point ahead of the current progress is rejected, since the steps in between have no
517
+ outputs yet.
518
+ - Output archives produced by the affected steps/iterations are renamed with a `_bak` suffix
519
+ before being regenerated - they are not deleted, but are not used by subsequent steps either.
520
+ In `cloud_production` mode the same files are also renamed in ADLS before the run starts, so
521
+ the regenerated archives can be uploaded under their original names.
522
+ - Combine with `--execution-options one_step`/`one_iteration` to stop after just the resumed
523
+ step/iteration instead of running to completion.
524
+
485
525
  This design ensures:
486
- - **Predictable behavior**: Config file is the single source of truth
526
+ - **Predictable behavior**: Config file is the single source of truth for iteration/step totals
487
527
  - **Easy resumption**: Just run the same command - it figures out what's needed
488
528
  - **Change flexibility**: Update config file to run more iterations or different steps
489
- - **No confusion**: No CLI parameters that might conflict with saved state
529
+ - **Explicit debugging escape hatch**: `--execution-options`/`--resume-iteration`/`--resume-step` let you deliberately override the resume point without touching the config file, while normal re-runs remain config-driven
490
530
 
491
531
  ## File Management
492
532
 
@@ -529,6 +569,7 @@ scenario_folder/ # Scenario name usually starts with db_
529
569
  ├── outputs/ # Model outputs
530
570
  ├── activitysim/ # Sub-component folder
531
571
  ├── quetzal/ # Sub-component folder
572
+ ├── activitysim_<date>_<time>.bak/ # Local backup made by a full_cloud_sync download (optional)
532
573
  └── .cloud_sync_conflict/ # Conflict resolution
533
574
 
534
575
  # Non-scenario specific logs
@@ -563,15 +604,21 @@ The orchestrator implements intelligent, state-aware synchronization with Azure
563
604
  The orchestrator compares state files to determine sync eligibility:
564
605
 
565
606
  **State Comparison Logic:**
566
- - Compares `total_steps_completed`, `current_iteration`, and `current_step_index`
607
+ - Compares `resume_generation` first (a higher generation is ahead), then `total_steps_completed`, `current_iteration`, and `current_step_index`
567
608
  - Returns: `state1_ahead`, `state2_ahead`, `equal`, or `incomparable`
568
609
 
569
610
  **Upload Rules:**
570
611
  - ❌ Barebone configs are never uploaded (used to download model run from cloud)
571
612
  - ✅ Upload only if local state is ahead of or equal to remote state
572
613
  - ❌ Upload blocked if remote state is ahead (prevents overwriting newer data)
573
- - If remote doesn't exist: Upload everything (inputs, components, outputs, config, state)
574
- - If remote exists: Upload only state and new outputs files
614
+ - ✅ A state rewound by a resume has a higher `resume_generation` and is allowed to replace the remote state
615
+ - If the model run has not started (no completed steps), or the remote doesn't exist: Upload everything (inputs, components, outputs, config, state), even when a cloud copy already exists
616
+ - If the model run is in progress and the remote exists: Upload state, new outputs files and logs, plus any sub-component zip (and `inputs.zip`) missing in the cloud, so a scenario resumed from a checkpoint can start on a fresh cloud node. Zips already in the cloud are not replaced
617
+ - If the run has completed and `full_cloud_sync: true` is set in the YAML: also upload every sub-component folder as `<component>.zip`
618
+ - When a component zip is replaced, the previous cloud zip is renamed `<component>_<YYYYMMDD_HHMMSS>.bak.zip` and moved to `.cloud_model_archive/` (mirrors the local `<component>_<YYYYMMDD_HHMMSS>.bak` folder rename used on download)
619
+ - If a full upload (remote missing, or run not started) fails to zip or upload a component or `inputs`, the sync returns failure and does not upload outputs, state or config, so the incomplete cloud copy is not mistaken for a usable scenario; the next upload starts over as a full upload
620
+ - Outputs already present in the cloud are skipped, except archives regenerated in the current session: the cloud copy is moved to `.cloud_sync_conflict/` and the new file is uploaded
621
+ - A failed upload (outputs, or config/state) makes the sync return failure; if the existing cloud file cannot be moved to `.cloud_sync_conflict/` (or `.cloud_model_archive/` for component zips), it is never overwritten
575
622
 
576
623
  **Download Rules:**
577
624
  - ✅ Barebone configs always allow download (will be overwritten completely)
@@ -579,29 +626,49 @@ The orchestrator compares state files to determine sync eligibility:
579
626
  - ❌ Download blocked if local state is ahead (prevents overwriting local progress)
580
627
  - If local is barebone or empty: Download everything from remote
581
628
  - If local exists: Download only state and new outputs files
629
+ - If local exists, `full_cloud_sync: true` is set in the local YAML, and the cloud run is completed and strictly ahead of local: each local sub-component folder is renamed `<component>_<YYYYMMDD_HHMMSS>.bak` and the final sub-component folders are downloaded along with state, outputs and logs (`inputs` is not touched). While the cloud run is in progress, or when local already matches the cloud, local sub-component folders are left alone
630
+ - A failed component, config/state or output download makes the sync return failure (re-run to fetch what is missing). During a full cloud sync, if any component archive, config/state, or output operation fails after earlier replacements, component replacements and resume output renames are rolled back so the local scenario is not left with mixed data.
631
+ - Config and state files are downloaded as a pair; neither replaces the local copy until both are available, and if replacing either fails both previous files are restored.
632
+ - Downloaded paths (`outputs/`, `logs/`, and generic pattern downloads) are checked to stay within their intended local folders; unsafe cloud paths are rejected. A failed outputs download removes the files it already wrote.
633
+ - If a replacement upload fails after the existing cloud file was archived, the sync attempts to restore the previous canonical cloud copy.
634
+
635
+ #### Full Cloud Sync (`full_cloud_sync`)
636
+
637
+ An optional top-level key in the model config YAML, default `false` (also `false` when the key is missing):
638
+
639
+ ```yaml
640
+ full_cloud_sync: true
641
+ ```
642
+
643
+ - Upload: once the model run completes, every sub-component folder in `sub_components` is zipped and uploaded as `<component>.zip`; previous cloud zips go to `.cloud_model_archive/` as `<component>_<YYYYMMDD_HHMMSS>.bak.zip`
644
+ - Download: local sub-component folders are backed up as `<component>_<YYYYMMDD_HHMMSS>.bak` and replaced by the final cloud folders (conditions above)
645
+ - Only a boolean `true` (or the strings "true"/"yes"/"1") enables it; a quoted `"false"` is read as false
582
646
 
583
647
  #### Selective File Synchronization
584
648
 
585
- **When Remote Doesn't Exist (Initial Upload):**
649
+ **When Remote Doesn't Exist, or the Model Run Has Not Started (Full Upload):**
586
650
  - Sub-component folders (zipped before upload)
587
651
  - Inputs directory (zipped before upload)
588
652
  - All outputs files
589
653
  - Configuration and state files
590
654
  - Logs subdirectory files (performance CSVs and other logs)
591
655
 
592
- **When Both Local and Remote Exist:**
656
+ **When Both Local and Remote Exist and the Model Run Is in Progress:**
593
657
  - Only state files (to synchronize progress tracking)
594
658
  - Only new outputs files (model results from completed steps)
595
659
  - Logs subdirectory files (performance data with timestamps)
596
- - Sub-component folders are NOT re-uploaded (assumed to be consistent across iterations)
597
- - This design assumes sub-components can run iterations using files from inputs/outputs
660
+ - Sub-component folders (and `inputs`) that are missing in the cloud, so resumed runs can execute from a fresh node; sub-component zips already in the cloud are not re-uploaded, unless `full_cloud_sync` applies at completion
661
+
662
+ **Long Paths:**
663
+ - Zipping and extracting use extended-length paths on Windows, so sub-component folders with paths over 260 characters (for example deep trace folders) are supported even when Windows long paths are disabled
598
664
 
599
665
  **Download Behavior:**
600
- - Component zip files are extracted after download
601
- - Config files are downloaded individually with conflict handling
666
+ - Component zip files are extracted into a staging folder and swapped in, so a corrupt archive never replaces a working component
667
+ - Config and state files are downloaded to a staging folder before replacing the existing files
602
668
  - Logs subdirectory files are downloaded (performance data and logs)
669
+ - Outputs keep their path below `outputs/`; an existing local file is kept, except that a local pre-resume archive is renamed to match a cloud resume backup (`<name>_<timestamp>_bak.<ext>`) so the regenerated archive downloads
603
670
  - Conflict files are moved to `.cloud_sync_conflict/` folder
604
- - Files in `.cloud_sync_conflict/` are always skipped during sync
671
+ - Files in `.cloud_sync_conflict/` and `.cloud_model_archive/` are always skipped during sync
605
672
 
606
673
  #### Barebone Scenario Handling
607
674
  Barebone configs are minimal configurations created when default templates are unavailable:
@@ -636,18 +703,26 @@ The orchestrator maintains execution state in `orca_model_state.json`:
636
703
  - `project_name`: Project identifier for cloud synchronization (from config or --project override)
637
704
  - `scenario_name`: Model run identifier (always derived from local folder basename)
638
705
  - `total_steps_completed`: Cumulative steps across all iterations (used for state comparison)
639
- - `current_iteration`: Current iteration number (1-based)
706
+ - `current_iteration`: Current iteration number (numbered from `start_at`, default 1)
640
707
  - `current_step_index`: Index of current step within iteration (0-based)
641
708
  - `completed_steps`: Steps completed in current iteration (resets each iteration)
709
+ - `resume_generation`: Incremented each time a resume rewinds progress (0 if never resumed)
710
+ - `output_archives`: Registry of the output archive file for each step/archive/iteration
642
711
 
643
712
  ### State Comparison
644
713
 
645
714
  The `OrcaState.compare_states()` method determines which state is further ahead:
646
715
  1. First checks project/scenario name compatibility
647
- 2. Compares `total_steps_completed` (primary metric)
648
- 3. If equal, compares `current_iteration`
649
- 4. If equal, compares `current_step_index`
650
- 5. Returns: `state1_ahead`, `state2_ahead`, `equal`, or `incomparable`
716
+ 2. Compares `resume_generation`: the higher generation is ahead, because a resume deliberately
717
+ rewinds progress and the rewound state must be able to replace the older one
718
+ 3. For equal generations, compares `total_steps_completed` (primary progress metric)
719
+ 4. If equal, compares `current_iteration`
720
+ 5. If equal, compares `current_step_index`
721
+ 6. Returns: `state1_ahead`, `state2_ahead`, `equal`, or `incomparable`
722
+
723
+ The state file is written atomically (temp file, then replace). An unreadable state
724
+ file is kept as `orca_model_state.json.corrupt_<timestamp>` and a default state is started, so
725
+ the damaged file can be inspected instead of being overwritten.
651
726
 
652
727
  ## Performance Monitoring
653
728
 
@@ -871,6 +946,10 @@ python -m tlpytools.orca --action init_model \
871
946
  - Or manually resolve by backing up and choosing which state to keep
872
947
  - **Debug**: Check `total_steps_completed` in both local and remote state files
873
948
 
949
+ 6a. **Upload fails with `Failed to create zip for <component>` or `Component or inputs upload failed`**:
950
+ - **Cause**: A full upload (no cloud copy, or the run has not started) could not zip or upload a sub-component folder or `inputs`. When this happens the state, config and outputs are deliberately not uploaded, so the cloud copy is not mistaken for a complete scenario
951
+ - **Solution**: Read the error above it in `{scenario}/logs/` (for example a locked or unreadable file), fix it, and upload again; the next upload repeats the full upload. Folder paths over 260 characters on Windows are handled automatically (`WinError 3` on a zip means something else is wrong with the path)
952
+
874
953
  7. **Barebone config upload blocked**:
875
954
  - **Error**: `Barebone config detected - upload not allowed`
876
955
  - **Cause**: Attempting to upload incomplete/minimal configuration
@@ -1026,22 +1105,29 @@ For more details about the Azure credential manager, see [docs/azure_credential_
1026
1105
 
1027
1106
  #### Basic Usage
1028
1107
  ```bash
1029
- python batch_task_runner.py --job-id job_large --project my_project --scenario my_scenario
1108
+ python -m tlpytools.orca.batch_task_runner --job-id job_large --project my_project --scenario my_scenario
1030
1109
  ```
1031
1110
 
1032
1111
  #### Full Example with All Options
1033
1112
  ```bash
1034
- python batch_task_runner.py \
1113
+ python -m tlpytools.orca.batch_task_runner \
1035
1114
  --job-id job_large \
1036
1115
  --project orca_optimization \
1037
1116
  --scenario db_test \
1038
- --python-command orca/orchestrator.py \
1039
- --python-env orca \
1040
1117
  --docker-image orca/orca:develop \
1041
1118
  --max-retry-count 2 \
1042
1119
  --max-wall-clock-time PT8H \
1043
1120
  --poll-interval 45 \
1044
- --max-polls 15
1121
+ --timeout-minutes 480
1122
+ ```
1123
+
1124
+ #### Debugging a Single Step or Resume Point
1125
+ ```bash
1126
+ # Run just one step, then stop
1127
+ python -m tlpytools.orca.batch_task_runner --job-id job_large --project my_project --scenario my_scenario --execution-options one_step
1128
+
1129
+ # Reset state to iteration 2, step 'quetzal', then run the full remaining model
1130
+ python -m tlpytools.orca.batch_task_runner --job-id job_large --project my_project --scenario my_scenario --resume-iteration 2 --resume-step quetzal
1045
1131
  ```
1046
1132
 
1047
1133
  ### Command Line Arguments
@@ -1051,38 +1137,56 @@ python batch_task_runner.py \
1051
1137
  | `--job-id` | Yes | - | Batch job ID where the task will be submitted |
1052
1138
  | `--project` | Yes | - | Project name (used in task ID generation) |
1053
1139
  | `--scenario` | Yes | - | Scenario name for the ORCA task |
1054
- | `--python-command` | No | `orca/orchestrator.py` | Python script to execute |
1055
- | `--python-env` | No | `orca` | Conda environment name |
1140
+ | `--override-python-env` | No | Docker image default | Python environment path inside the container |
1141
+ | `--override-python-command` | No | Docker image default | Python command/script to run inside the container |
1142
+ | `--override-python-options` | No | Default orca `run_model` options | Full command-line options string; if set, `--execution-options`/`--resume-iteration`/`--resume-step` below are ignored |
1143
+ | `--execution-options` | No | `full` | `run_model` granularity: `full`, `one_step`, or `one_iteration` |
1144
+ | `--resume-iteration` | No | - | Reset state to this iteration before running |
1145
+ | `--resume-step` | No | - | Reset state to this step name before running (requires `--resume-iteration`) |
1056
1146
  | `--docker-image` | No | `orca/orca:develop` | Docker image to use |
1057
1147
  | `--max-retry-count` | No | `0` | Maximum number of task retries |
1058
1148
  | `--max-wall-clock-time` | No | `PT6H` | Maximum wall clock time (ISO 8601) |
1059
1149
  | `--poll-interval` | No | `30` | Polling interval in seconds |
1060
- | `--max-polls` | No | `10` | Maximum number of polling attempts |
1150
+ | `--timeout-minutes` | No | `360` | Maximum minutes to monitor before giving up (task keeps running on Azure Batch regardless) |
1061
1151
  | `--skip-duplicate-check` | No | `False` | Skip duplicate task detection (use with caution) |
1152
+ | `--log-file` | No | Auto-generated | Log file path |
1153
+ | `--log-level` | No | `INFO` | Logging level (`DEBUG`, `INFO`, `WARNING`, `ERROR`) |
1062
1154
 
1063
1155
  ### How It Works
1064
1156
 
1065
1157
  1. **Duplicate Detection**: Checks for existing tasks with the same project and scenario name
1066
- - Prevents duplicate submissions when tasks are active, running, or completed
1067
- - Allows resubmission only when previous tasks have failed
1158
+ - A task that is already `active`, `preparing` or `running` is monitored instead of resubmitted
1159
+ (the newest one, if several); requested execution/resume options are NOT applied to it
1160
+ - A successfully `completed` task blocks submission (it would overwrite finished results)
1161
+ - Allows resubmission when previous tasks have failed
1068
1162
  - Provides clear user-facing messages with guidance on how to proceed
1069
1163
  - Can be bypassed with `--skip-duplicate-check` flag if needed
1070
1164
  2. **Task Submission**: Creates a unique task ID and submits it to the specified Azure Batch job
1071
1165
  3. **Status Monitoring**: Polls the task status at regular intervals
1072
- 4. **Early Exit**: Stops polling when the task reaches 'running' or 'completed' state
1073
- 5. **Timeout Handling**: Fails if the task doesn't start within the specified timeout
1166
+ 4. **Early Exit**: Stops polling when the task reaches the 'completed' state, or fails
1167
+ 5. **Failure Detection**: Azure Batch reports a task whose command exited non-zero as `completed`
1168
+ with `executionInfo.result = "failure"`. The runner treats that (or any non-zero `exitCode`)
1169
+ as a failed task, prints the exit code, and `run_task()` raises `RuntimeError` / the CLI exits
1170
+ non-zero. This includes a run whose final save to ADLS failed.
1171
+ 6. **Timeout Handling**: Fails if the task doesn't finish within the specified timeout
1172
+
1173
+ `run_task()` and `wait_for_task_completion()` accept an optional `status_callback(state, message)`
1174
+ that is called during the duplicate check (`CHECKING`), task creation (`SUBMITTING`) and after each
1175
+ poll with the Batch state (`active`, `running`, `completed`), for live progress displays.
1074
1176
 
1075
1177
  ### Duplicate Task Detection
1076
1178
 
1077
- The batch task runner includes automatic duplicate detection to prevent accidental resubmission of tasks:
1179
+ The batch task runner includes automatic duplicate detection to prevent accidental resubmission of tasks.
1180
+ If a matching task is still queued or running, `run_task()` (and the CLI) attach to it and report its
1181
+ status until it finishes. The block below is shown only when the matching task already completed:
1078
1182
 
1079
- **When a duplicate is detected:**
1183
+ **When a completed duplicate is detected:**
1080
1184
  ```
1081
1185
  ======================================================================
1082
1186
  [WARNING] DUPLICATE TASK DETECTED
1083
1187
  ======================================================================
1084
1188
 
1085
- Found 1 existing task(s) with matching project/scenario: task_id (running).
1189
+ Found 1 existing task(s) with matching project/scenario: task_id (completed).
1086
1190
  Cannot submit duplicate task while previous task is still active, running, or completed.
1087
1191
 
1088
1192
  [INFO] A task with the same project and scenario name already exists.
@@ -1101,8 +1205,9 @@ Cannot submit duplicate task while previous task is still active, running, or co
1101
1205
  ```
1102
1206
 
1103
1207
  **Behavior:**
1104
- - Tasks with same project/scenario in states `active`, `preparing`, `running`, or `completed` block new submissions
1105
- - Tasks in `failed` state allow automatic resubmission
1208
+ - Tasks with same project/scenario in state `active`, `preparing` or `running` are monitored, not resubmitted
1209
+ - Tasks in state `completed` (successful exit) block new submissions
1210
+ - Tasks in `failed` state, and `completed` tasks whose command exited non-zero, allow automatic resubmission
1106
1211
  - Use `--skip-duplicate-check` flag to bypass detection (use with caution)
1107
1212
 
1108
1213
  ### Task ID Format