Skip to content

Pattern equality should normalize bond labels (or document the limitation) #73

@wshlavacek

Description

@wshlavacek

Location: bionetgen/modelapi/pattern.py:626

Original marker:

# TODO: try to decide if A(b!1).B(a!1) is the same
# as A(b!2).B(a!2), if so, the bond check is much harder

Component.__eq__ (and through it, Molecule/Pattern equality) compares bonds as raw label tokens. Two BNGL patterns that differ only in the labels of their bonds are semantically identical — A(b!1).B(a!1) and A(b!2).B(a!2) represent the same complex — but the equality check returns False. The author's commented-out attempt to compare bonds as sets sits below the marker.

Recent context: 421bac9 (Fix Pattern/Molecule equality and mutable defaults) addressed the worst case (mutable defaults causing unrelated patterns to compare equal). This issue is the remaining correctness gap.

What would unblock this: decide between two resolutions:

  1. Normalize bond labels. Relabel each pattern's bonds in canonical order before comparing. Adds correctness but means equality is no longer a string-identity check.
  2. Document the limitation. Keep the current label-sensitive equality, add a docstring explaining that callers should canonicalize first.

If a current consumer depends on label-normalized equality (e.g. structural pattern dedup in the simulator bridge), please note it on this issue so the resolution scope is clear.

Discovered during: non-Atomizer TODO/FIXME triage sweep, 2026-05-08.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions