-
Notifications
You must be signed in to change notification settings - Fork 135
Include map options in road network cache #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
562b342
Add options digest to road network cache
lola831 221b1ca
Add tests for driving network cache
lola831 1182168
clean up
lola831 8f0967c
Test deterministicHash on non-scalars
lola831 11cd3d7
Use deterministic hash for scene compile options
lola831 058930d
Fix optionsDigest hash size to 8 bytes
lola831 09cb0f6
Merge branch 'main' into snet-param-hash
lola831 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,3 +226,100 @@ def checkGroup(group): | |
| assert rev is not maneuver | ||
| assert rev.startLane.road is maneuver.endLane.road | ||
| assert rev.endLane.road is maneuver.startLane.road | ||
|
|
||
|
|
||
| # --- Tests for cached network pickles --- | ||
|
|
||
|
|
||
| def _read_options_digest(pickled_path: Path) -> bytes: | ||
| """Return the optionsDigest bytes from a cached .snet header. | ||
|
|
||
| Header layout: | ||
| - 4 bytes: version | ||
| - 64 bytes: originalDigest | ||
| - 8 bytes: optionsDigest | ||
| """ | ||
| with open(pickled_path, "rb") as f: | ||
| header = f.read(76) # 4 + 64 + 8 | ||
| return header[68:76] # skip version (4) + originalDigest (64) | ||
|
|
||
|
|
||
| def test_dump_pickle_from_pickle(tmp_path, network): | ||
| """dumpPickle/fromPickle should rebuild the Network when digests match""" | ||
| digest = b"x" * 64 # fake original map digest | ||
| options_digest = b"y" * 8 # fake map options digest | ||
| path = tmp_path / "net.snet" | ||
|
|
||
| # Write the cache using the new format. | ||
| network.dumpPickle(path, digest, options_digest) | ||
|
|
||
| # Read it back with matching digests. | ||
| loaded = Network.fromPickle( | ||
| path, | ||
| originalDigest=digest, | ||
| optionsDigest=options_digest, | ||
| ) | ||
|
|
||
| # Sanity checks | ||
| assert isinstance(loaded, Network) | ||
| assert loaded.elements.keys() == network.elements.keys() | ||
|
|
||
|
|
||
| def test_from_pickle_digest_mismatch(tmp_path, network): | ||
| """fromPickle should reject files whose digests don't match.""" | ||
| digest = b"x" * 64 | ||
| options_digest = b"y" * 8 | ||
| path = tmp_path / "net.snet" | ||
|
|
||
| network.dumpPickle(path, digest, options_digest) | ||
|
|
||
| wrong_digest = b"z" * 64 | ||
| wrong_options = b"w" * 8 | ||
|
|
||
| # Wrong originalDigest -> DigestMismatchError. | ||
| with pytest.raises(Network.DigestMismatchError): | ||
| Network.fromPickle( | ||
| path, | ||
| originalDigest=wrong_digest, | ||
| optionsDigest=options_digest, | ||
| ) | ||
|
|
||
| # Wrong optionsDigest -> DigestMismatchError. | ||
| with pytest.raises(Network.DigestMismatchError): | ||
| Network.fromPickle( | ||
| path, | ||
| originalDigest=digest, | ||
| optionsDigest=wrong_options, | ||
| ) | ||
|
|
||
| # No digests supplied -> allowed (standalone .snet use case). | ||
| Network.fromPickle(path) | ||
|
|
||
|
|
||
| def test_cache_regenerated_when_options_change(cached_maps): | ||
| """Changing map options should invalidate and rewrite the cached .snet file.""" | ||
| # Get the temp copy of Town01 from cached_maps. | ||
| xodr_loc = cached_maps[str(mapFolder / "CARLA" / "Town01.xodr")] | ||
| xodr_path = Path(str(xodr_loc)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a future PR: we should switch from |
||
| pickled_path = xodr_path.with_suffix(Network.pickledExt) | ||
|
|
||
| # First load: cache with one tolerance value | ||
| Network.fromFile( | ||
| xodr_path, | ||
| useCache=True, | ||
| writeCache=True, | ||
| tolerance=0.05, | ||
| ) | ||
| options_digest1 = _read_options_digest(pickled_path) | ||
|
|
||
| # Second load: same map, different tolerance. | ||
| Network.fromFile( | ||
| xodr_path, | ||
| useCache=True, | ||
| writeCache=True, | ||
| tolerance=0.123, | ||
| ) | ||
| options_digest2 = _read_options_digest(pickled_path) | ||
|
|
||
| # If the options changed, the cache header should also change. | ||
| assert options_digest1 != options_digest2 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.