Skip to main content

hcx

Project description

hcx

hcx defines typed, runtime-usable contracts for hydrological model batches, forecasts, output specifications, models, and model factories.

The contract specification is normative. Public docstrings and this README are explanatory summaries of that specification.

The distribution combines three parts: the normative specification, an inline-typed Python contract marked with py.typed, and a standalone conformance harness. Independent model packages can import the same contract and prove their behavior without an application, training engine, or external dataset.

Authoring a model package

  1. Add hcx as a runtime dependency of the model package.

  2. Implement a torch.nn.Module whose forward(batch: Batch) -> Forecast behavior satisfies ForecastModel, including the normative shape, dtype/device, and metadata identity rules.

  3. Implement a callable matching ModelFactory. It accepts a model-specific dict[str, object] and the keyword-only ordered dynamic_inputs and static_inputs, resolved input_size, static_size, and output_size, and a resolved OutputSpecification[object]. It returns the module. Preserve name order; the sizes are resolved from the first batch.

  4. Declare the factory in the model package's pyproject.toml:

    [project.entry-points.'hcx.models']
    my_model = "my_model_package.factory:create_model"
    
  5. Exercise the complete contract with synthetic data:

    from importlib.metadata import entry_points
    
    from hcx import Point, assert_conforms, make_synthetic_batch
    
    batch = make_synthetic_batch()
    assert batch.scalar_dynamic is not None
    assert batch.scalar_static is not None
    
    factory = entry_points(group="hcx.models", name="my_model")[0].load()
    dynamic_inputs = [
        f"dynamic_{index}" for index in range(batch.scalar_dynamic.shape[-1])
    ]
    static_inputs = [
        f"static_{index}" for index in range(batch.scalar_static.shape[-1])
    ]
    model = factory(
        {},
        dynamic_inputs=dynamic_inputs,
        static_inputs=static_inputs,
        input_size=batch.scalar_dynamic.shape[-1],
        static_size=batch.scalar_static.shape[-1],
        output_size=batch.target.shape[-1],
        output_specification=Point(),
    )
    assert_conforms(model, batch)
    

The factory can also be imported and called directly in this smoke test. hcx packages scalar_lstm as a reference entry point, not as a required base class. Entry-point names are consumer-facing identifiers and should remain stable and unique within an environment.

See the normative factory and entry-point clauses and the changelog for version history.

Releases

Maintainers bump the version with bump-my-version and update the changelog in the same commit. A human then creates and publishes the GitHub Release, which creates the vX.Y.Z tag. The GitHub Actions workflow builds distributions with uv build and publishes them through OIDC trusted publishing. Prereleases and manual workflow dispatches target TestPyPI; published non-prereleases target PyPI. Local publishing and hand-made tags are forbidden.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hcx-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hcx-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file hcx-0.1.0.tar.gz.

File metadata

  • Download URL: hcx-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.0

File hashes

Hashes for hcx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 333a5229f08d2f04a98e4bf0a119e6f8e7c3ca8724ddb3ba97215497c850ebf2
MD5 920c07a648d4b12970f840bd5a6b47f4
BLAKE2b-256 6030194728c0efa3ddac16829388d0e74257c1fef7498003ab9c0baa4faa6728

See more details on using hashes here.

File details

Details for the file hcx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hcx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.0

File hashes

Hashes for hcx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4bd28683c83b07d0596facae64bd365a2d670e8b34b83d5911b68bc056b8a04
MD5 20af69a5c2111cf87e6aff5f3e99ce63
BLAKE2b-256 dd5816d846105c9068935abd7d934fee6c0ff4e3ad4293f9acdd884be4c06bf8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page