Skip to content

Add user-defined Spin Map#1297

Merged
ax3l merged 19 commits intoBLAST-ImpactX:developmentfrom
cemitch99:add_user_spin_map
Mar 7, 2026
Merged

Add user-defined Spin Map#1297
ax3l merged 19 commits intoBLAST-ImpactX:developmentfrom
cemitch99:add_user_spin_map

Conversation

@cemitch99
Copy link
Copy Markdown
Member

@cemitch99 cemitch99 commented Feb 6, 2026

This PR adds an element that applies a user-defined spin map to the spin variables (sx, sy, sz)--a functionality that is similar to that of the user-defined LinearMap element. The LinearMap element is also updated for spin support--it leaves spin unaffected.

Follow-up: Investigate the loss of precision (1e-12 -> 1e-9) that occurs when Python input is used.
See Issue #1342

@ax3l ax3l added component: elements Elements/maps/external fields component: spin tracking Spin tracking labels Feb 6, 2026
Comment thread examples/spin_tracking/run_spin_map.py Fixed
@cemitch99 cemitch99 requested review from ax3l and qianglbl February 6, 2026 22:42
@cemitch99
Copy link
Copy Markdown
Member Author

The Python bindings for the user-facing inputs, which use SmallMatrix type, need support similar to what we used for the LinearMap element.

Comment thread examples/spin_tracking/run_spin_map.py Outdated
@ax3l
Copy link
Copy Markdown
Member

ax3l commented Feb 24, 2026

Added a type for the 3x6 matrix and 3x1 vector in AMReX-Codes/pyamrex#538 now.

@ax3l ax3l self-assigned this Feb 24, 2026
@ax3l ax3l force-pushed the add_user_spin_map branch from cc33445 to 93846c0 Compare March 3, 2026 07:04
ax3l added a commit to AMReX-Codes/pyamrex that referenced this pull request Mar 3, 2026
Matrix & vector type commonly used in accelerator physics w/ spin.

See BLAST-ImpactX/impactx#1297
@ax3l ax3l mentioned this pull request Mar 3, 2026
@ax3l ax3l force-pushed the add_user_spin_map branch from db0a7e4 to 54ba4fd Compare March 3, 2026 16:51
Comment thread docs/source/usage/parameters.rst Outdated
dspinmax = dspin.max()

print("Change in the spin:")
print("||delta s||_max", dspinmax)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see in CI:

Change in the spin:
||delta s||_max 2.2705360483651895e-09
  atol=1.5e-12

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. The version of the test based on the C++ input works within this tolerance. However, the Python version does not (yet). Maybe something is being done in single-precision...?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The macOS and Tooling CI (Ubuntu) runs that show the larger tolerance are also in double precision.

Copy link
Copy Markdown
Member

@ax3l ax3l Mar 3, 2026

Choose a reason for hiding this comment

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

The difference is probably from parallel execution. The failing runs have MPI enabled. So maybe just not converged enough at the current resolution (no. of particles)...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm. The no. of particles should no be relevant in this example, because the change in the spin should be zero (to machine precision) for every particle.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense. Also, bot inputs & py are run with MPI as I just checked, but the inputs pass.

I compared the lattices in both and the Python one forgets to comment in the full lattice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I saw you bumped the tolerance in the end.

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Comment thread examples/spin_tracking/run_spin_map.py Outdated
Comment thread examples/spin_tracking/run_spin_map.py Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 4, 2026

Merging this PR will not alter performance

✅ 37 untouched benchmarks


Comparing cemitch99:add_user_spin_map (166ce89) with development (6c5af13)

Open in CodSpeed

Comment thread examples/spin_tracking/analysis_spin_map.py Outdated
@ax3l ax3l enabled auto-merge (squash) March 7, 2026 00:23
@ax3l ax3l merged commit 65214d3 into BLAST-ImpactX:development Mar 7, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: elements Elements/maps/external fields component: spin tracking Spin tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants