Skip to content

Allow users to specify location of temp file#231

Open
ppinchuk wants to merge 23 commits intomainfrom
pp/temp_file
Open

Allow users to specify location of temp file#231
ppinchuk wants to merge 23 commits intomainfrom
pp/temp_file

Conversation

@ppinchuk
Copy link
Copy Markdown
Collaborator

@ppinchuk ppinchuk commented Mar 8, 2026

In some cases (i.e. Kestrel) it is important for users (specifically from Python) to be able to specify the location of the temp swap storage. This allows users to select the most performant hardware and also potentially save the file after execution to be able to examine the routing layers. This PR allows Python to pass down a temp dir for the swap file and also allows python CLI users to request that the routing layer file is stored as an output.

@ppinchuk ppinchuk added this to the Long-term plans milestone Mar 8, 2026
@ppinchuk ppinchuk self-assigned this Mar 8, 2026
@ppinchuk ppinchuk added the enhancement Update to logic or general code improvements label Mar 8, 2026
Copilot AI review requested due to automatic review settings March 8, 2026 19:35
@ppinchuk ppinchuk added the topic-rust-general Issues/pull requests related to rust label Mar 8, 2026
@ppinchuk ppinchuk requested a review from castelao as a code owner March 8, 2026 19:35
@ppinchuk ppinchuk added p-medium Priority: medium topic-python-general Issues/pull requests related to python code labels Mar 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends reVRt’s Rust routing swap/routing-layer storage so callers (notably Python and the Python CLI) can control where the routing-layer Zarr cache is written, and optionally persist that cache as an inspectable output artifact.

Changes:

  • Add an optional routing_layer_out_fp/swap_fp path plumbed from Python → PyO3 → Rust routing → Rust dataset swap store.
  • Add CLI support for save_routing_layer, persisting routing-layer outputs under out_dir/extra_outputs.
  • Add tests covering routing-layer persistence and argument passthrough; add python-slugify dependency for stable filenames.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/rust/integration_tests.rs Updates Rust integration tests for new resolve argument ordering and swap_fp=None.
tests/python/unit/test_rust_bindings.py Adds unit test ensuring RouteFinder writes routing-layer Zarr to a requested path and is readable/consistent.
tests/python/unit/routing/test_routing_base.py Adds test verifying routing_layer_out_fp is passed through to RouteFinder from BatchRouteProcessor.
tests/python/unit/routing/cli/test_routing_cli_point_to_point.py Adds test for compute_lcp_routes(..., save_routing_layer=True) producing a saved .zarr output.
tests/python/unit/routing/cli/test_routing_cli_point_to_feature.py Adds analogous test for point-to-feature CLI routing-layer persistence.
tests/python/integration/test_rust_bindings_integration.py Adds integration test validating routing-layer output persistence for LayeredFile inputs.
revrt/routing/cli/utilities.py New helper/context manager to create temp routing-layer directories and persist them with coordinates/CRS.
revrt/routing/cli/point_to_point.py Adds save_routing_layer option and passes it through to the shared routing runner.
revrt/routing/cli/point_to_feature.py Adds save_routing_layer option and passes it through to the shared routing runner.
revrt/routing/cli/base.py Wires save_routing_layer into run_lcp and routes routing-layer temp/persist handling via the new utility.
revrt/routing/base.py Extends BatchRouteProcessor.process() / routing execution to pass routing_layer_out_fp into Rust RouteFinder.
pyproject.toml Adds runtime dependency on python-slugify for deterministic output naming.
pixi.lock Updates lockfile to include python-slugify and text-unidecode.
crates/revrt/src/routing/scenario.rs Threads optional swap_fp into Scenario::new() and dataset creation.
crates/revrt/src/routing/mod.rs Threads optional swap_fp into Routing::new() and ParRouting::new().
crates/revrt/src/lib.rs Updates resolve / generator plumbing for swap_fp; adjusts internal tests/bench calls.
crates/revrt/src/ffi/mod.rs Exposes routing_layer_out_fp in find_paths and RouteFinder PyO3 signatures; forwards to Rust core.
crates/revrt/src/dataset/mod.rs Supports swap storage at a user-provided filesystem path; improves swap dataset metadata (dimension names).
crates/cli/src/main.rs Updates native CLI invocation of resolve for the new signature and swap_fp=None.
Comments suppressed due to low confidence (2)

revrt/routing/cli/point_to_point.py:318

  • Docstring uses single-backtick inline literals for parameter names (e.g., system_mem_limit_gb, memory_utilization_limit). In reST/Sphinx, parameter names/literals should use double backticks (system_mem_limit_gb) for consistent monospace rendering (matches the rest of this docstring).
        Fraction of `system_mem_limit_gb` to utilize for routing. Should
        be a value between 0 and 1. By default, ``0.9``.
    system_mem_limit_gb : int or float, default=5
        Maximum amount of system memory (in GB) to utilize for routing.
        This is used in conjunction with `memory_utilization_limit` to
        determine the memory limit for routing. By default, ``5`` GB.

revrt/routing/cli/point_to_feature.py:435

  • Docstring uses single-backtick inline literals for parameter names (e.g., system_mem_limit_gb, memory_utilization_limit). In reST/Sphinx, parameter names/literals should use double backticks (system_mem_limit_gb) for consistent monospace rendering (matches the rest of this docstring).
        Fraction of `system_mem_limit_gb` to utilize for routing. Should
        be a value between 0 and 1. By default, ``0.9``.
    system_mem_limit_gb : int or float, default=5
        Maximum amount of system memory (in GB) to utilize for routing.
        This is used in conjunction with `memory_utilization_limit` to
        determine the memory limit for routing. By default, ``5`` GB.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 78.78788% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.63%. Comparing base (31e49a9) to head (c130e5e).

Files with missing lines Patch % Lines
revrt/routing/cli/utilities.py 76.40% 16 Missing and 5 partials ⚠️

❌ Your patch status has failed because the patch coverage (78.78%) is below the target coverage (93.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #231      +/-   ##
==========================================
- Coverage   99.34%   98.63%   -0.72%     
==========================================
  Files          25       26       +1     
  Lines        2764     2857      +93     
  Branches      320      331      +11     
==========================================
+ Hits         2746     2818      +72     
- Misses          9       25      +16     
- Partials        9       14       +5     
Flag Coverage Δ
unittests 98.63% <78.78%> (-0.72%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@castelao castelao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppinchuk , I'm so sorry that I missed this review before. I have just a couple of suggestions. Using a builder could be a another Rust-style approach.

"Initializing a temporary swap dataset at {:?}",
tmp_path.path()
);
let tmp_path = tempfile::TempDir::new()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this go within the None? If the path is specified, we don't need the TempDir, so no problem if it is not created, right? Oh, but in that case, tmp_path would go out of scope by the end of the swap_fp and hence dropped before it could be used? Was that the reason?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's exactly right

}

impl Dataset {
pub(super) fn open<P: AsRef<std::path::Path>>(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can't silently skip variables with optional as we do in Python, what about having a variation of this command that requires a path and another that doesn't? What do we expect to be the most common, the temporary or with path defined?

One option would be open_with_path(..., path), and open(...) which creates the TmpDir and calls open_with_path(). With that we keep the current signature, DRY, and open the option for a path defined.

}

impl Scenario {
pub(super) fn new<P: AsRef<std::path::Path>>(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agreed with the other suggestion, it would make sense the same here. Something like new_with_path.

@castelao
Copy link
Copy Markdown
Member

castelao commented Apr 6, 2026

Also, we should do a patch upgrade after this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Update to logic or general code improvements p-medium Priority: medium topic-python-general Issues/pull requests related to python code topic-rust-general Issues/pull requests related to rust

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants