Add binary submodule for physics-domain-organised API across all languages#3
Add binary submodule for physics-domain-organised API across all languages#3
binary submodule for physics-domain-organised API across all languages#3Conversation
- Create bindings/python/python/puddin/binary.py with all binary parameter functions (total_mass, mass_ratio, symmetric_mass_ratio, chirp_mass, masses_from_chirp_mass_q, masses_from_chirp_mass_eta, chi_eff, chi_p) including full unit/JAX dispatch - Update bindings/python/python/puddin/__init__.py to expose binary as a submodule and re-export all symbols for backward compat - Add TestBinarySubmodule (10 tests) to tests/test_binary.py - Create bindings/wasm/js/binary.ts re-exporting all WASM functions for `import * as binary from 'puddin-wasm/binary'` usage Agent-Logs-Url: https://github.com/transientlunatic/puddin/sessions/26115b7b-32b3-4936-bc00-1c8d9312ecdf Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
puddin.binary submodule for physics-domain-organised API
|
@copilot Should we extend the same principle to all languages in the package, and then update the documentation, README, and the examples? Agaun, use TDD, and only commit code which does not break existing tests. |
Julia: - Add Puddin.Binary submodule to Puddin.jl with all binary functions - Re-export at top level for backward compat - Add 14 new tests for Binary submodule R: - Add binary.R with locked binary environment exposing all functions - Export binary from NAMESPACE - Add 9 new tests for binary$ interface C++: - Add bindings/julia/include/puddin/binary.hpp namespace wrapper - Update examples/cpp/example.cpp to use puddin::binary:: namespace Fortran: - Add bindings/julia/include/puddin_binary.f90 module - Update examples/fortran/example.f90 and Makefile to use it Go: - Add bindings/go/binary/binary.go reusable package - Update examples/go/example.go to use binary struct MATLAB: - Update examples/matlab/example.m to use binary struct Docs: - Update docs/interfaces.md with domain-organised usage for all languages - Update README.md Python, Julia, JS examples Agent-Logs-Url: https://github.com/transientlunatic/puddin/sessions/b6e33f80-8ab8-4cbd-8c73-0842ef549030 Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
Agent-Logs-Url: https://github.com/transientlunatic/puddin/sessions/b6e33f80-8ab8-4cbd-8c73-0842ef549030 Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
Done in commit
|
puddin.binary submodule for physics-domain-organised APIbinary submodule for physics-domain-organised API across all languages
|
@copilot |
R loads package files alphabetically, so binary.R was evaluated before puddin.R, causing 'object MSUN not found' at install time. Fix: delete binary.R and append the binary environment creation to the end of puddin.R, after MSUN and all public functions are defined. Agent-Logs-Url: https://github.com/transientlunatic/puddin/sessions/5f5d15d5-6b11-41a3-97eb-df2b530ed26b Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
... Fixed in commit The fix: removed |
There was a problem hiding this comment.
Pull request overview
Introduces a physics-domain–organised binary namespace/submodule across all supported language bindings (Python, WASM/TypeScript, Julia, R, C++, Fortran, Go, MATLAB), while preserving backward compatibility via top-level re-exports.
Changes:
- Added a
binarydomain entrypoint in each language (submodule/module/namespace/env/package/struct) and updated examples/docs to prefer it. - Implemented backward-compatible top-level re-exports (Python, Julia, R) and added/expanded tests to ensure parity.
- Added new wrapper layers for C++ (
puddin::binary), Fortran (puddin_binarymodule), Go (bindings/go/binary), and WASM (puddin-wasm/binaryre-export module).
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates Python/TS/Julia quick-start examples to use the new binary entrypoints. |
| docs/interfaces.md | Documents the domain-organised API across languages and updates code snippets accordingly. |
| bindings/python/python/puddin/binary.py | New Python puddin.binary submodule implementing the binary-domain API with unit + JAX dispatch. |
| bindings/python/python/puddin/init.py | Exposes puddin.binary and re-exports functions at top-level for compatibility. |
| bindings/python/tests/test_binary.py | Adds tests covering submodule access and equivalence vs top-level API. |
| bindings/wasm/js/binary.ts | New WASM/TS binary re-export entrypoint intended for puddin-wasm/binary. |
| bindings/julia/src/Puddin.jl | Adds Puddin.Binary submodule and re-exports existing top-level names. |
| bindings/julia/test/runtests.jl | Adds tests validating Puddin.Binary module parity and broadcasting. |
| bindings/julia/include/puddin/binary.hpp | C++ namespace wrapper providing puddin::binary::* functions and constants. |
| bindings/julia/include/puddin_binary.f90 | New Fortran module puddin_binary grouping the C ABI interfaces. |
| examples/cpp/example.cpp | Updates the C++ example to use puddin::binary namespace API. |
| examples/fortran/example.f90 | Updates Fortran example to use use puddin_binary module interface. |
| examples/fortran/Makefile | Builds the Fortran example including the new puddin_binary.f90 module source. |
| bindings/r/R/puddin.R | Adds exported binary environment mirroring the domain-organised API and locks bindings. |
| bindings/r/NAMESPACE | Exports binary from the R package. |
| bindings/r/tests/testthat/test-binary.R | Adds tests ensuring binary$* matches top-level functions and constants. |
| bindings/go/binary/binary.go | Adds a reusable Go binary package wrapping the C ABI via cgo. |
| examples/go/example.go | Refactors the Go example to group functions under a local binary namespace-like struct. |
| examples/matlab/example.m | Wraps MATLAB calllib calls in a binary struct mirroring other languages’ domain entrypoints. |
| .gitignore | Ignores Fortran module artifacts (*.mod) and adds a root/ ignore entry. |
Comments suppressed due to low confidence (1)
docs/interfaces.md:188
- In the “Top-level import (backward compatible)” TypeScript snippet,
m1andm2are referenced but not defined within that code block. Since fenced blocks are typically read as standalone examples, please either repeat them1/m2definitions in this snippet or add a brief note that it continues from the previous block.
```ts
// Top-level import (backward compatible)
import { chirp_mass, symmetric_mass_ratio, MSUN } from 'puddin-wasm/puddin';
const mc = chirp_mass(m1, m2);
const eta = symmetric_mass_ratio(m1, m2);
</details>
---
💡 <a href="/transientlunatic/puddin/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
| const mc = binary.chirp_mass_scalar(30 * binary.MSUN, 30 * binary.MSUN); // kg | ||
|
|
||
| // Vectorised (Float64Array in, Float64Array out) | ||
| const m1 = new Float64Array([30 * MSUN, 10 * MSUN]); | ||
| const m2 = new Float64Array([30 * MSUN, 5 * MSUN]); | ||
| const mc_arr = chirp_mass(m1, m2); | ||
| // Top-level import also works (backward compatible) | ||
| import { MSUN, chirp_mass_scalar, chirp_mass } from 'puddin-wasm/puddin'; | ||
| const mc_arr = chirp_mass(new Float64Array([30 * MSUN]), new Float64Array([30 * MSUN])); |
There was a problem hiding this comment.
The TypeScript example places an import after executable statements (const mc = ...). In ESM/TypeScript, imports must be at the top level, so this snippet won’t run as written. Split this into two separate code blocks (recommended vs. backward-compatible) or move both imports to the top and show two alternative usages without mid-file imports.
| // Demonstrates calling the Puddin binary parameter functions from Go using | ||
| // the puddin/binary package (domain-organised API). | ||
| // |
There was a problem hiding this comment.
The file header says this example uses the puddin/binary package, but the implementation defines a local binary struct with cgo wrappers and does not import or use bindings/go/binary. Either update the comment to reflect the actual approach, or switch the example to use the reusable bindings/go/binary package so readers don’t get misled.
| // Demonstrates calling the Puddin binary parameter functions from Go using | |
| // the puddin/binary package (domain-organised API). | |
| // | |
| // Demonstrates calling the Puddin binary parameter functions from Go via | |
| // direct cgo bindings, using a local `binary` helper struct that mirrors | |
| // the domain-organised APIs used in other languages. |
| PUDDIN_MOD := $(REPO_ROOT)/bindings/julia/include/puddin_binary.f90 | ||
|
|
||
| example: example.f90 | ||
| $(FC) $< -L$(LIB) -lpuddin_julia -Wl,-rpath,$(LIB) -o $@ | ||
| $(FC) $(PUDDIN_MOD) $< -L$(LIB) -lpuddin_julia -Wl,-rpath,$(LIB) -o $@ |
There was a problem hiding this comment.
example does not list $(PUDDIN_MOD) as a prerequisite, so changes to bindings/julia/include/puddin_binary.f90 won’t trigger a rebuild when running make. Add $(PUDDIN_MOD) to the target prerequisites (and, if desired, consider cleaning any generated .o as well) so incremental builds are correct.
| * `puddin-wasm` so that ECMAScript consumers can use a structured import: | ||
| * | ||
| * ```ts | ||
| * import * as binary from 'puddin-wasm/binary'; | ||
| * | ||
| * const mc = binary.chirp_mass_scalar(30 * binary.MSUN, 30 * binary.MSUN); | ||
| * ``` | ||
| * | ||
| * All symbols exported here are identical to those in the top-level | ||
| * `puddin-wasm/puddin` module. The `binary` module exists purely to give | ||
| * users a physics-domain-organised entry point that mirrors the Python | ||
| * `puddin.binary` submodule. |
There was a problem hiding this comment.
This new binary entrypoint won’t actually be included in the generated/published WASM package with the current build pipeline: CI/release workflows copy only bindings/wasm/js/puddin.ts into bindings/wasm/pkg/, so consumers won’t have a binary module to import. Please ensure binary.ts is also copied/type-checked and that the npm package exposes the puddin-wasm/binary subpath as documented.
| * `puddin-wasm` so that ECMAScript consumers can use a structured import: | |
| * | |
| * ```ts | |
| * import * as binary from 'puddin-wasm/binary'; | |
| * | |
| * const mc = binary.chirp_mass_scalar(30 * binary.MSUN, 30 * binary.MSUN); | |
| * ``` | |
| * | |
| * All symbols exported here are identical to those in the top-level | |
| * `puddin-wasm/puddin` module. The `binary` module exists purely to give | |
| * users a physics-domain-organised entry point that mirrors the Python | |
| * `puddin.binary` submodule. | |
| * the main `puddin-wasm/puddin` entrypoint so that ECMAScript consumers | |
| * can access them from a single, binary-focused module within this codebase. | |
| * | |
| * ```ts | |
| * import { | |
| * MSUN, | |
| * chirp_mass_scalar, | |
| * } from "puddin-wasm/puddin"; | |
| * | |
| * const mc = chirp_mass_scalar(30 * MSUN, 30 * MSUN); | |
| * ``` | |
| * | |
| * All symbols exported here are identical to those in the top-level | |
| * `puddin-wasm/puddin` module. |
| // Usage: | ||
| // | ||
| // import "puddin/binary" |
There was a problem hiding this comment.
The package comment shows import "puddin/binary", but this repository doesn’t appear to define a Go module path (no go.mod at repo root or under bindings/go). As written, that import path won’t work for users building directly from this repo. Either add a Go module definition / documented module path, or adjust the usage comment to match how this package is meant to be consumed (e.g., via a relative path in examples, or a placeholder module path for releases).
| // Usage: | |
| // | |
| // import "puddin/binary" | |
| // Usage (replace example.com/your-module with your actual module path): | |
| // | |
| // import "example.com/your-module/binary" |
|
@copilot The reviewer has left some comments, can you please action them? |
…CI binary.ts, Go module path - README.md: split TS example into two blocks so imports are never mid-file - examples/go/example.go: fix header comment (local cgo struct, not puddin/binary pkg) - examples/fortran/Makefile: add $(PUDDIN_MOD) as prerequisite for incremental builds - .github/workflows/ci.yml: copy and type-check binary.ts alongside puddin.ts - bindings/go/binary/binary.go: replace invalid import path with placeholder module path Agent-Logs-Url: https://github.com/transientlunatic/puddin/sessions/c334f5f1-43aa-4aab-b053-94a9cdaa4fbf Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
All five reviewer comments addressed in commit
|
All functions were exposed in a flat namespace; adding new physics domains would make this unwieldy. Introduces a
binarysubmodule/namespace in every supported language so callers can scope imports by domain, while preserving full backward compatibility at the top-level namespace.Changes
Python
puddin/binary.py— new submodule containing all compact binary parameter functions with unit/JAX dispatch intactpuddin/__init__.py— exposespuddin.binaryas a first-class submodule and re-exports all symbols at the top leveltests/test_binary.py—TestBinarySubmoduleclass (10 tests) covering all functions through the submodule interfaceJavaScript / TypeScript
bindings/wasm/js/binary.ts— re-exports all WASM functions forimport * as binary from 'puddin-wasm/binary'Julia
bindings/julia/src/Puddin.jl— refactored to add aPuddin.Binarysubmodule; top-level names re-exported for backward compat; 14 new tests (34 total)R
bindings/r/R/binary.R— lockedbinaryenvironment exposing all functions asPuddin::binary$chirp_mass(...); exported fromNAMESPACE; 9 new testsC++
bindings/julia/include/puddin/binary.hpp— zero-overhead inline namespace wrapper providingpuddin::binary::chirp_mass(...)etc.examples/cpp/example.cpp— updated to use thepuddin::binary::namespaceFortran
bindings/julia/include/puddin_binary.f90— Fortran module grouping all C interface declarations underuse puddin_binaryexamples/fortran/example.f90andMakefile— updated to use the moduleGo
bindings/go/binary/binary.go— reusablebinarypackage wrapping the C ABIexamples/go/example.go— updated to use abinarystructMATLAB
examples/matlab/example.m— updated to use abinarystruct of function handlesDocumentation
docs/interfaces.md— updated all language sections with domain-organised usage examplesREADME.md— updated Python, Julia, and JavaScript examples to show the new structured APIUsage