Source default tensor symmetries from the Context#557
Conversation
Builds on #553 ("non-symmetric by default") by making the default tensor symmetries configurable through sequant::Context rather than hardcoding them. - Context gains default `symmetry`, `hermiticity`, and `column_symmetry` (Defaults + Options + accessors + set()). Library defaults are the safest (Nonsymm / NonHermitian / Nonsymm). BraKet symmetry is never a Context knob: it is a derived property, computed per-tensor from the default Hermiticity and base_field, consistent with the removal of Context::braket_symmetry. - Tensor ctors resolve unspecified perm/column/hermiticity against the active Context; the Context is consulted only when something is unspecified, so fully-explicit construction (the hot path) stays lock-free. - The deserializer's default symmetries are sourced from the active Context. - Context::operator== now also compares the symmetry defaults, so scoped/default context switches that differ only in these actually take effect. - mbpt applications (unit-test harness + srcc/stcc integration) opt into the particle-symmetric convention via column = Symm. - Update unit/integration expectations to the resulting (physically correct) symmetries; add tests for the Context-driven defaults and for rejecting braket symmetry on (anti)symmetrization operators.
There was a problem hiding this comment.
Pull request overview
This PR moves the “default tensor symmetry” behavior out of hardcoded defaults and into the active sequant::Context, so that library defaults are conservative (fully non-symmetric / non-Hermitian / non-column-symmetric) while applications can opt into more ergonomic conventions (e.g., particle/column symmetry for MBPT). It also updates deserialization and tests to reflect Context-sourced defaults and the updated canonicalization/ordering behavior.
Changes:
- Add Context-level defaults for
Symmetry,Hermiticity, andColumnSymmetry, and include them inContext::operator==. - Update
Tensorconstruction to resolve unspecified symmetry attributes against the active Context (derivingBraKetSymmetryfromHermiticity+ base field). - Update v1 deserialization to source default symmetries from the active Context, and adjust unit/integration tests to match the new defaults and ordering.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
SeQuant/core/context.hpp |
Adds Context defaults + Options fields + accessors/setters for symmetry/hermiticity/column symmetry. |
SeQuant/core/context.cpp |
Wires new Options fields into construction, adds accessors/setters, and updates operator== to compare new defaults. |
SeQuant/core/expressions/tensor.hpp |
Introduces Context-driven defaulting via resolve_symmetries() and updates constructors accordingly. |
SeQuant/core/io/serialization/v1/deserialize.cpp |
Sources deserializer default symmetries from get_default_context(). |
SeQuant/core/io/serialization/v1/ast_conversions.hpp |
Clarifies reserved (anti)symmetrizer symmetry handling; converts AST symmetries into Tensor construction. |
tests/unit/test_main.cpp |
Sets test default Context to column_symmetry = Symm for MBPT-oriented expectations. |
tests/unit/test_tensor.cpp |
Updates braket/adjoint expectations and adds coverage for Context-driven defaults. |
tests/unit/test_parse.cpp |
Adds tests for rejecting braket symmetry on reserved (anti)symmetrizers. |
tests/unit/test_wick.cpp |
Updates latex expectation due to changed canonical ordering under new defaults. |
tests/unit/test_tensor_network.cpp |
Updates expected index ordering and adjusts a deserialize string to rely on Context defaults. |
tests/unit/test_spin.cpp |
Updates expected serialized symmetry specifiers to match new defaulting/derivation behavior. |
tests/unit/test_mbpt.cpp |
Updates expected strings to reflect Context-driven defaults and explicit symmetry tags. |
tests/unit/test_canonicalize.cpp |
Updates deserialize fixtures to omit now-defaulted braket specifiers for Ŝ where appropriate. |
tests/unit/test_biorthogonalization.cpp |
Removes per-call def_col_symm overrides, relying on Context defaults instead. |
tests/unit/data/sf_r2_direct_real_inc.hpp |
Updates a large expected fixture string to match updated defaulting/serialization behavior. |
tests/integration/srcc.cpp |
Sets MBPT integration Context default column_symmetry = Symm. |
tests/integration/stcc.cpp |
Sets MBPT integration Context default column_symmetry = Symm. |
Comments suppressed due to low confidence (1)
SeQuant/core/io/serialization/v1/ast_conversions.hpp:337
- Deserializing reserved (anti)symmetrization operators (Ŝ/Â) currently inherits the Context-driven default Hermiticity when no explicit braket specifier is provided. If the active Context defaults to Hermitian, this will derive a non-Nonsymm braket symmetry and make plain "Ŝ{...}" / "Â{...}" fail to parse even though the default form should be accepted. These operators should ignore Context braket defaults and remain braket-Nonsymm unless the user explicitly requests otherwise (in which case the ctor should reject it).
if (tensor.name == reserved::antisymm_label()) {
perm_symm = Symmetry::Antisymm;
} else if (tensor.name == reserved::symm_label()) {
column_symm = ColumnSymmetry::Symm;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ss of Context Addresses Copilot review on #557: - A bare "Ŝ{...}"/"Â{...}" previously inherited the Context's default Hermiticity, so under a Hermitian-default Context it would derive a non-Nonsymm braket and fail to construct. Force braket = Nonsymm for these reserved operators when no braket spec is given (an explicit spec is left for the Tensor ctor to reject). Covered by a new test under a Hermitian Context. - Fix a misleading comment in Tensor::resolve_symmetries() about when the resolved Hermiticity is used.
|
Also addressed the low-confidence note on |
Stacked on top of #553 (base branch
default-tensor-symmetry); this PR shows only the incremental changes on top of it.Motivation
#553 makes tensors non-symmetric by default, but hardcodes the defaults and leaves the deserializer's column default (
Nonsymm) inconsistent with theTensorctor's (Symm). That inconsistency made particle-symmetric amplitudes parse as column-Nonsymm(so they canonicalized differently and no longer merged), and broke ~18 unit + 5 integration tests.Approach
Make the default tensor symmetries a property of the active
sequant::Context, so the library default is the safest (fully non-symmetric) while applications fine-tune for ergonomics.Contextgainssymmetry,hermiticity, andcolumn_symmetrydefaults (Defaults + Options + accessors +set()). Library defaults:Nonsymm/NonHermitian/Nonsymm.Hermiticityandbase_field, consistent with the earlier removal ofContext::braket_symmetry(8c4669d).Tensorctors resolve unspecified perm/column/hermiticity against the active Context, reading it only when something is unspecified, so explicit construction (the hot path) stays lock-free.Context::operator==now compares the new symmetry defaults (otherwiseset_scoped_default_contextwould silently refuse to switch a context that differs only in these — a latent bug surfaced by the new tests).srcc/stccintegration) opt into the particle-symmetric convention viacolumn = Symm.Testing
Built with the full debug config (clang-17, AddressSanitizer, Unity, ccache, all eval backends: TiledArray/BTAS/TAPP/Torch).
unit_tests-sequant: 7069 assertions / 70 cases pass.check-sequant: all tests pass exceptsequant/unit/python/basic/run, which aborts at AddressSanitizer init (ASan-instrumented moduledlopened into a non-ASan Python on macOS) — an environment limitation, unrelated to these changes.clang-format-17 --Werror.