Skip to content

Conversation

@ax3l
Copy link
Member

@ax3l ax3l commented Oct 15, 2025

5hr vibe pair coded in Cursor. Maybe should have just done it manually instead of holding its hand xD

I guided/instructed, reviewed and adjusted the logic throughout. If you like to review this PR, please just look at the user-facing logic and if you like the test, to safe time.

# Filter by element type
drift_elements = lattice.select(kind="Drift")
quad_elements = lattice.select(kind=elements.Quad)

# Filter by regex pattern
all_quads = lattice.select(kind=r".*Quad")  # matches Quad, ChrQuad, ExactQuad

# Filter by name
specific_elements = lattice.select(name="quad1")

# Chain filters (AND logic)
drift_named_d1 = lattice.select(kind="Drift").select(name="drift1")

# Modify original elements through references
drift_elements[0].ds = 2.0  # modifies original lattice

Follow-Up Ideas

  • filter by position / position range in s Element Selection Syntax: Position #1183
  • return boolean masks and filter by them, too
  • filter by provided element attributes: give me all elements that have a k property, are thin/thick, etc.
  • scale an attribute of selection result elements (e.g., multiply/add the .k property of every element in the selection): can be done in a simple 2-liner loop already

5hr vibe pair coded in Cursor. Maybe should have just done it xD
@ax3l ax3l added component: elements Elements/external fields component: python Python bindings labels Oct 15, 2025
@ax3l ax3l requested review from EZoni and cemitch99 October 15, 2025 07:34
@ax3l ax3l force-pushed the topic-lattice-select branch from a7630f2 to 23ccb7b Compare October 15, 2025 07:41
@ax3l ax3l force-pushed the topic-lattice-select branch from 23ccb7b to dfd8dca Compare October 15, 2025 07:42
@ax3l ax3l mentioned this pull request Oct 15, 2025
5 tasks
ax3l added 2 commits October 15, 2025 01:18
@ax3l ax3l force-pushed the topic-lattice-select branch from a20a915 to 7093c8a Compare October 15, 2025 08:24
@ax3l ax3l added this to the Advanced Methods (SciDAC-5) milestone Oct 15, 2025
Copy link
Member

@cemitch99 cemitch99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature, which will no doubt be widely used. Works for me on some local tests.

@ax3l ax3l merged commit ad19aa2 into BLAST-ImpactX:development Oct 15, 2025
16 checks passed
@ax3l ax3l deleted the topic-lattice-select branch October 15, 2025 18:22
ax3l added a commit to ax3l/impactx that referenced this pull request Oct 17, 2025
* [pre-commit.ci] pre-commit autoupdate (BLAST-ImpactX#1161)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.13.1 → v0.13.2](astral-sh/ruff-pre-commit@v0.13.1...v0.13.2)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (BLAST-ImpactX#1165)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.13.2 → v0.13.3](astral-sh/ruff-pre-commit@v0.13.2...v0.13.3)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Gauss 3D: Fix Push Constants (BLAST-ImpactX#1168)

This fixes the push constants for non-equal x,y,z and
adds an end-point correction for the integration. It
also changes the number of integration points by default
to 101 instead of 401.

Co-authored-by: Ji Qiang <[email protected]>

* [pre-commit.ci] pre-commit autoupdate (BLAST-ImpactX#1174)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.13.3 → v0.14.0](astral-sh/ruff-pre-commit@v0.13.3...v0.14.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Bump stefanzweifel/git-auto-commit-action from 6 to 7 (BLAST-ImpactX#1175)

Bumps [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) from 6 to 7.
- [Release notes](https://github.com/stefanzweifel/git-auto-commit-action/releases)
- [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md)
- [Commits](stefanzweifel/git-auto-commit-action@v6...v7)

---
updated-dependencies:
- dependency-name: stefanzweifel/git-auto-commit-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github/codeql-action from 3 to 4 (BLAST-ImpactX#1176)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3 to 4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v3...v4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix `BeamMonitor`: Delay Open (BLAST-ImpactX#1178)

`BeamMonitor` opens the openPMD series now on first output. This
simplifies usage dramatically, now allowing to:

* create the lattice (monitor elements) before the `sim` is even
  initialized
* creating a monitor element and not using it in a lattice

* CMake `pip_install`: Package Examples (BLAST-ImpactX#1179)

Ensure the `examples/` directory is part of the `pip` wheels
we build, e.g., on `cmake --build build -j 6 --target pip_install`

* Envelope: Silence Warning w/o Space-Charge (BLAST-ImpactX#1173)

Consistent with the other two tracking modes, we only
print options upfront and do not warn every simulation
step if space charge is not used.

* Release 25.10 (BLAST-ImpactX#1180)

* Update Stub Files

* AMReX/ABLASTR/WarpX: development (BLAST-ImpactX#1177)

* ABLASTR/WarpX: development

Update the ABLASTR dependency to the latest development branch.

* pyAMReX: `development`

* Python: Improve `KnownElementsList` (BLAST-ImpactX#1181)

Add per-element by-reference access for manipulation.

* Update Stub Files

* Element Selection Syntax (BLAST-ImpactX#1182)

* Implementation

5hr vibe pair coded in Cursor. Maybe should have just done it xD

* Doc

* Fix Type Hints

* `select`: Fix All-Selected Path

Avoid implicit return of `None`

* Cleanup

* Update Stub Files

* Fix Python import errors (BLAST-ImpactX#1186)

* Update Stub Files

* Fix RFCavity edge case (BLAST-ImpactX#1185)

* Fix RFCavity edge case.

* Remove extra semicolon.

* Fix el typing (BLAST-ImpactX#1190)

* Fix `KnownElementsList` Stubs

Avoid importing `typing` for type hints, because pybind11-stubgen
forgets the import when generating `pyi` files...

* Update Stubs

* Update PALS to 0.2.0 (BLAST-ImpactX#1184)

* Update PALS version

* Fix missing imports in KnownElementsList.pyi

* Fix FODO example script

* Revert changes to stub file

* fix some math issues in examle documentation (BLAST-ImpactX#1191)

* "Starting step" Print: Spaces (BLAST-ImpactX#1187)

- newline before new step
- no space before `++++ Starting step`

* Element Names: All, `None` (BLAST-ImpactX#1189)

It is easier for user-facing workflows if `.name` exists
for all elements, even `Empty`.

In Python, instead of throwing an exception we return the
`None` value for elements without a user-provided name,
which simplifies user-logic. In this case `.has_name` is
`False`.

* Update Stub Files

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Axel Huebl <[email protected]>
Co-authored-by: Ji Qiang <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: ax3l <[email protected]>
Co-authored-by: Edoardo Zoni <[email protected]>
Co-authored-by: Richard Pausch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: elements Elements/external fields component: python Python bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants