Skip to content

Add 128-bit genome encoding layer#2

Open
Spbd1 wants to merge 1 commit into
codex/create-initial-python-package-structure-for-pishiegenfrom
codex/implement-128-bit-genome-encoding-layer
Open

Add 128-bit genome encoding layer#2
Spbd1 wants to merge 1 commit into
codex/create-initial-python-package-structure-for-pishiegenfrom
codex/implement-128-bit-genome-encoding-layer

Conversation

@Spbd1

@Spbd1 Spbd1 commented May 7, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a compact, deterministic 128-bit integer representation for digital genomes with stable named bit fields and deterministic decoding.
  • Offer safe utilities for reading and updating bit fields and enforce the valid raw range 0 <= raw < 2**128 to avoid silent corruption.
  • Allow reproducible random generation of 128-bit genomes for experiments and tests while preserving backward-compatible callable behavior for existing package-level random_genome call sites.

Description

  • Add pishiegen/genome/schema.py containing FieldSpec, FIELD_SPECS, FIELD_ORDER, and constants GENOME_BITS, GENOME_MIN, and GENOME_MAX, with inclusive bit-range docstrings for each named field.
  • Add pishiegen/genome/encoding.py implementing extract_bits, set_bits, validate_raw_genome, and a frozen Genome(raw: int) dataclass with validate(), get_field(), set_field(), and to_dict() methods and full validation.
  • Add pishiegen/genome/decoder.py with decode_genome() that accepts either a Genome instance or a raw integer and returns the deterministic dictionary of decoded fields.
  • Add pishiegen/genome/random_genome.py providing a seedable generator that returns a Genome with GENOME_BITS random bits and a small module-wrapper to keep from pishiegen.genome import random_genome call sites callable for legacy code that expects the older gene-list generator.
  • Add tests/test_genome_encoding.py covering valid range checks, field extraction correctness, non-corrupting set_field, and reproducible random genomes with a seed, plus docstrings in new modules describing bit ranges and intent.

Testing

  • Ran the full test suite with python -m pytest -q and PYTHONPATH=. pytest -q, and the test runs completed successfully (all tests passed).
  • Added and executed tests/test_genome_encoding.py, which passed and verifies range validation, extraction/setting semantics, and seeded reproducibility.
  • The repository test suite was exercised after integration and all automated tests succeeded.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant