Skip to content

replace openmatrix with h5py - #87

Open
jpn-- wants to merge 5 commits into
ActivitySim:mainfrom
driftlesslabs:codex/replace-openmatrix-with-h5py
Open

replace openmatrix with h5py#87
jpn-- wants to merge 5 commits into
ActivitySim:mainfrom
driftlesslabs:codex/replace-openmatrix-with-h5py

Conversation

@jpn--

@jpn-- jpn-- commented Aug 7, 2026

Copy link
Copy Markdown
Member

This pull request removes the use of the openmatrix package throughout the codebase and replaces it with direct usage of the h5py library for reading and writing OMX (Open Matrix) HDF5 files. The change simplifies dependencies, updates documentation and examples, and refactors code to use h5py APIs. Additionally, improvements are made to shared memory handling, including support for custom array storage order and better memory management.

Dependency and Documentation Updates:

  • Removed openmatrix from all dependency files (envs/development.yml, envs/testing.yml, pyproject.toml, .github/workflows/run-tests.yml) and updated code, documentation, and examples to use h5py directly for OMX file operations. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Code Refactoring:

  • Refactored all code that previously used openmatrix to use h5py, including in sharrow/example_data.py, sharrow/omx.py, and sharrow/tests/test_datasets.py. This includes updating file reading/writing logic and dataset creation. [1] [2] [3] [4] [5]

OMX File Handling Improvements:

  • Rewrote the split_omx function in sharrow/omx.py to use h5py for splitting OMX files, added helper functions for copying metadata and datasets, and improved output file organization and lookup management.

Shared Memory Enhancements:

  • Added support for specifying custom array storage order (e.g., "last-axis-first") in shared memory, improved buffer initialization to be more memory efficient, and enhanced cleanup logic for memory-mapped arrays in sharrow/shared_memory.py. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

API and Type Annotations:

  • Updated function signatures and docstrings to reflect the removal of openmatrix and clarify the use of h5py objects, especially in sharrow/omx_reader.py. [1] [2]

jpn-- added 5 commits August 5, 2026 23:33
Reopen compatible OMX wrappers through h5py while preserving caller ownership.

Add coverage for 2D, 3D, and reload workflows.
Add configurable worker support while preserving last-source precedence and serial fallbacks. Validate worker settings and cover parallel reload behavior.
@jpn--
jpn-- requested a balanced review from Copilot August 11, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Replaces OpenMatrix with direct h5py-based OMX handling and adds optimized eager, shared-memory, and memory-mapped loading.

Changes:

  • Refactors OMX reading, writing, splitting, and Zarr conversion.
  • Adds parallel loading and configurable shared-memory array ordering.
  • Removes OpenMatrix dependencies and updates tests and documentation.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
uv.lock Removes OpenMatrix and PyTables dependencies.
sharrow/translate.py Uses the shared OMX reader for Zarr conversion.
sharrow/tests/test_omx.py Adds OMX splitting and conversion tests.
sharrow/tests/test_datasets.py Migrates tests to h5py and covers loading modes.
sharrow/shared_memory.py Adds array ordering and memmap cleanup.
sharrow/omx.py Reimplements OMX splitting with h5py.
sharrow/omx_reader.py Narrows filename handling to h5py inputs.
sharrow/example_data.py Reads example OMX data with h5py.
sharrow/dataset.py Adds h5py-based loading and parallel storage modes.
pyproject.toml Removes the OpenMatrix development dependency.
envs/testing.yml Removes OpenMatrix from testing dependencies.
envs/development.yml Removes OpenMatrix from development dependencies.
docs/walkthrough/loading-skims.ipynb Updates the OMX walkthrough to h5py.
.github/workflows/run-tests.yml Removes OpenMatrix from CI installation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sharrow/dataset.py
if load == "shared":
result.shm.release_shared_memory()
else:
result.shm.delete_shared_memory_files(key)
Comment thread sharrow/omx.py
Comment on lines +60 to +67
output_paths = []
for number, matrix_name in enumerate(matrix_names):
output_path = destination / chunk_names[number % len(chunk_names)]
output_paths.append(output_path)
logger.info(f"writing {matrix_name} to {output_path}")
with h5py.File(output_path, "a") as target:
_initialize_omx_file(source, target)
_copy_dataset(source["data"], target["data"], matrix_name)
" omx_file.create_carray(\"/lookup\", \"taz\", obj=zones)\n",
" omx_file.root._v_attrs.SHAPE = np.array([len(zones), len(zones)])"
" omx_file.create_dataset(\"lookup/taz\", data=zones)\n",
" omx_file.attrs[\"SHAPE\"] = np.array([len(zones), len(zones)])"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants