Skip to content

[ad-04] expose fixed-boundary and free-DOF masks #5

Description

@krystophny

Stage: State layout API
Source language: Fortran, Python
Difficulty: easy
Runner tier: easy
Labels: difficulty:easy, stack:enzyme-ad, enhancement
Manuals to read first:

  • docs/user/theory.md, boundary conditions in radial direction
  • src/base/sbase.F90, boundary-condition descriptors
  • src/pygvec/state.F90, public f90wrap routines
    Depends on: [ad-03] expose flat q layout metadata #4

Goal

Expose masks that identify boundary design variables and interior/free variables for fixed-boundary optimization.

Files to edit

  • src/pygvec/state.F90: add routines returning integer index arrays or logical masks.
  • python/gvec/core/state.py: add boundary_dofs and interior_dofs properties.
  • test-CI/unit-pygvec/test_ad_layout.py: add boundary partition tests.

Syntax or behavior to implement

  • REQ-AD04-001: Given fixed-boundary GVEC input, the boundary mask includes the outer radial coefficient of X1 and X2 modes.
  • REQ-AD04-002: Given the same input, the LA outer radial coefficient remains in the interior/free mask.
  • REQ-AD04-003: When masks are combined, every active q index is either boundary or interior, never both.

Scaffold

boundary = []
for name in ("X1", "X2"):
    slc, shape = layout[name].slice, layout[name].shape
    boundary.extend(last_radial_indices(slc, shape))
interior = np.setdiff1d(np.arange(nq), boundary)

Positive fixtures to add

  • test_boundary_mask_x1_x2: outer X1 and X2 indices are boundary DOFs.
  • test_lambda_boundary_free: outer LA indices are interior DOFs.

Negative fixtures to add

  • Do not classify all last radial blocks as boundary. That freezes LA incorrectly.

Makefile target

No Makefile target. Use the existing pytest configuration.

Success criteria

uv run pytest test-CI/unit-pygvec/test_ad_layout.py -q

Non-goals

  • Do not implement equilibrium sensitivities in this PR.
  • Do not add free-boundary GVEC semantics.

Verification

uv run pytest test-CI/unit-pygvec/test_ad_layout.py -q

Reference

VMEC++ fixed the same partition issue in proximafusion/vmecpp#585.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty:easySmall, low-risk implementation issueenhancementNew feature or requeststack:enzyme-adGVEC differentiable equilibrium PR stack

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions