Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend FloorPlot #50

Merged
merged 3 commits into from
Jan 30, 2025
Merged

Extend FloorPlot #50

merged 3 commits into from
Jan 30, 2025

Conversation

giadarol
Copy link
Member

Note that this PR can be merged only after xtrack v0.73.1 is released.

The following modifications and extensions are introduced:

  • Plotting the XY projection is now supported.
  • The FloorPlot is now generated from the survey table alone without requiring access to the line. This allows plotting the survey after the corresponding line has been modified or deleted. For this purpose additional columns (length, isthick and element_type have been added to the survey table in xtrack v0.73.1.
  • The type of magnet is inferred from the element type and not from the strengths. This is to support the common use case in beam-line design, in which one defines a lattice geometry and wants to visualize the positions of the elements before defining the magnetic strengths. A side effect of this modification is that thin elements are all shown as multipoles and in the same color (we could think of doing something more sophisticated in the future, if required by users).

Examples including horizontal and vertical bends are available at https://github.com/xsuite/xplt/blob/extend_floorplot/examples/line_cases.ipynb

image image image image image image

@giadarol giadarol marked this pull request as draft January 18, 2025 21:18
@giadarol giadarol requested a review from eltos January 18, 2025 21:18
@giadarol giadarol marked this pull request as ready for review January 19, 2025 16:11
@eltos eltos changed the base branch from main to dev January 20, 2025 10:13
@eltos eltos force-pushed the dev branch 3 times, most recently from 0a6aade to 159677f Compare January 20, 2025 11:10
@eltos
Copy link
Member

eltos commented Jan 20, 2025

Aside from CI failures:

The type of magnet is inferred from the element type and not from the strengths. This is to support the common use case in beam-line design, in which one defines a lattice geometry and wants to visualize the positions of the elements before defining the magnetic strengths. A side effect of this modification is that thin elements are all shown as multipoles and in the same color (we could think of doing something more sophisticated in the future, if required by users).

This was already the idea, therefore it was using order from survey data (MAD-X had this), falling back to "nominal_order(element)" which would check for nominal strength even if not yet set, as opposed to "effective_order" which would check for actual strength values. Adding element type to survey is very good. However, since multipole handling is a major regression, let's keep the option to pass in the line object, and if done so, then use that extra information to colour the multipoles and other elements properly with the existing function. Let's not intentionally break what used to work before.

Examples including horizontal and vertical bends are available at https://github.com/xsuite/xplt/blob/extend_floorplot/examples/line_cases.ipynb

I think this can be reduced to one line with both, H and V bends, with two examples plots for two projections, and included in the main line.ipynb

@eltos
Copy link
Member

eltos commented Jan 21, 2025

@giadarol I noticed that some CI tests were never performed due to a mistake I made. I have fixed CI tests on dev branch with cde8527. If you could please rebase your PR onto current dev?

@eltos eltos marked this pull request as draft January 21, 2025 16:25
@giadarol
Copy link
Member Author

@giadarol I noticed that some CI tests were never performed due to a mistake I made. I have fixed CI tests on dev branch with cde8527. If you could please rebase your PR onto current dev?

This is now done

@giadarol
Copy link
Member Author

Aside from CI failures:

The type of magnet is inferred from the element type and not from the strengths. This is to support the common use case in beam-line design, in which one defines a lattice geometry and wants to visualize the positions of the elements before defining the magnetic strengths. A side effect of this modification is that thin elements are all shown as multipoles and in the same color (we could think of doing something more sophisticated in the future, if required by users).

This was already the idea, therefore it was using order from survey data (MAD-X had this), falling back to "nominal_order(element)" which would check for nominal strength even if not yet set, as opposed to "effective_order" which would check for actual strength values. Adding element type to survey is very good. However, since multipole handling is a major regression, let's keep the option to pass in the line object, and if done so, then use that extra information to colour the multipoles and other elements properly with the existing function. Let's not intentionally break what used to work before.

Examples including horizontal and vertical bends are available at https://github.com/xsuite/xplt/blob/extend_floorplot/examples/line_cases.ipynb

I think this can be reduced to one line with both, H and V bends, with two examples plots for two projections, and included in the main line.ipynb

The line can now be provided an optional argument, in which case knl is used to extract order for Multipole elements.
I didn't want to pollute the very clear line example with multipoles/vertical bends. The additional notebook is a bit more of a test than an example, aiming at covering the different scenarios for checks and debugging. Feel free to remove it or modify if you like.

@eltos eltos force-pushed the dev branch 2 times, most recently from 16ce015 to 0fb49fb Compare January 24, 2025 14:31
@giadarol
Copy link
Member Author

The Xtrack version with the additional columns in the survey is now released.
@eltos We can go ahead and merge this PR whenever you are ready

@eltos eltos marked this pull request as ready for review January 25, 2025 08:33
@eltos
Copy link
Member

eltos commented Jan 25, 2025

I'll review and merge asap

@giadarol
Copy link
Member Author

I'll review and merge asap

No rush :-)

giadarol and others added 2 commits January 30, 2025 14:19
Update nb
Update notebook
Remove duplicated notebook
Update notebook
Extract order from knl for multipoles, if line is provided
Update notebooks
Clean up
Missing plot
Add more examples in notebook
Add some straight magnets in example
Complete example
Remove redundant
ZX ZY and XZ seem ok
Refactored horizontal
example
The FloorPlot is made without passing the line
Working on refactoring
Examples with thin and thick elements
XY plot
- add vertical bend example to line.ipynb
- fix XZ projection for vertical bends not working due to rouding error
- restore features if passing line object (e.g. custom label formatting)
- use getter methods for survey data
- trigonometric calculations on arrays instead of loop to improve performance
@eltos
Copy link
Member

eltos commented Jan 30, 2025

Had to do some changes to get tests running, and did some refactoring in the process for better performance and maintainability. Also included your v-bend example in the docs.

@eltos eltos merged commit 570b001 into dev Jan 30, 2025
13 checks passed
@eltos
Copy link
Member

eltos commented Jan 30, 2025

Will be available on PyPI as pre-release 0.11.3-rc6 soon. I have recently updated the CI workflows to allow for pre-releases. PyPI and the version picker on the sphinx docs page reflects this. This means we can publish new features more quickly, while keeping the release cycle of "stable" versions (with possibly breaking changes, and for which docs are kept long-term) to every couple months.

However, if you agree and tested it on your end, we could promote this RC version to stable 0.11.4, and continue development in the 0.12.* cycle @giadarol?

grafik
grafik

@giadarol
Copy link
Member Author

giadarol commented Feb 2, 2025

@eltos, all good on my side. For me we can can go ahead.

@eltos eltos deleted the extend_floorplot branch February 15, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants