Skip to content

Commit b4ff24d

Browse files
authored
Lint and tweak beams (#110)
* first autolint set * new round for dict, list, tuple * some more for optional, union * fix implicit optionals * refix many imports rules * fix use of literal dicts * propagate error change here * fix trailing whitespaces * miscellaneous * fix error messages not declared before raising * fix magic values use in comparisons * miscellaneous * place *args correctly * miscellaneous * use dict literal * miscellaneous * no implicit namespace * correctly propagate kwargs * clean up logic * message outside raise * message outside raise * trade map for list comprehension * cleaner checks * format and last lints * no mypy * no interrogate * rename to nemitt_[xy], accept old and let user override npart and sigma_e * formatting * remove trailing whitespaces * pytest parametrize expects tuples * dict membership test does not need .keys() * mpl * names * unecessary list comprehensions * fixtures want lists of tuples * provide 'match' argument to every pytest.raises, normalize error messages * minimal linting here * remove old helper functions * bump version for minor release * release 1.6.0 file * added to this list
1 parent fc5754e commit b4ff24d

File tree

100 files changed

+1092
-1066
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1092
-1066
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ format:
8484
@python -m isort examples && black -l 95 examples
8585

8686
install: format clean
87-
@echo "Installing with $(D)pip$(E) in the current environment."
88-
@python -m pip install . -v
87+
@echo "Installing (editable) with $(D)pip$(E) in the current environment."
88+
@python -m pip install --editable . -v
8989

9090
lines: format
9191
@tokei .
@@ -113,5 +113,7 @@ alltests:
113113

114114
# Catch-all unknow targets without returning an error. This is a POSIX-compliant syntax.
115115
.DEFAULT:
116-
@echo "Make caught an invalid target! See help output below for available targets."
116+
@echo "Make caught an invalid target."
117+
@echo "See help output below for available targets."
118+
@echo ""
117119
@make help

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"sphinx.ext.coverage", # Collect doc coverage stats
126126
"sphinx.ext.doctest", # Test snippets in the documentation
127127
"sphinx.ext.githubpages", # Publish HTML docs in GitHub Pages
128-
"sphinx.ext.intersphinx", # Link to other projects documentation
128+
"sphinx.ext.intersphinx", # Link to other projects' documentation
129129
"sphinx.ext.mathjax", # Render math via JavaScript
130130
"sphinx.ext.napoleon", # Support for NumPy and Google style docstrings
131131
"sphinx.ext.todo", # Support for todo items
@@ -214,7 +214,7 @@
214214
#
215215
html_static_path = ["_static"]
216216

217-
# A dictionary of values to pass into the template engines context for all
217+
# A dictionary of values to pass into the template engine's context for all
218218
# pages. Single values can also be put in this dictionary using the
219219
# -A command-line option of sphinx-build.
220220
html_context = {

docs/release.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ Release Notes
33

44
The full list of releases can be found in the GitHub repository's `releases page <https://github.com/fsoubelet/PyhDToolkit/releases>`_.
55

6+
Version 1.6.0
7+
-------------
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
12+
releases/v1.6.0
13+
614
Version 1.5.0
715
-------------
816

docs/releases/v1.6.0.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _release_1.6.0:
2+
3+
1.6.0
4+
-----
5+
6+
Release `1.6.0` brings a few changes, and a great amount of maintenance fixes to the package.
7+
8+
Enhancements
9+
~~~~~~~~~~~~
10+
11+
* The `pyhdtoolkit.cpymadtools.lhc.make_lhc_beams` function now accepts the user providing values for `npart` and `sige`. The previously hard-coded values are now used as defaults.
12+
13+
Changes
14+
~~~~~~~
15+
16+
* The `pyhdtoolkit.cpymadtools.lhc.make_lhc_beams` function now expects `nemitt_[xy]` arguments instead of the previous `emittance_[xy]`. Providing the previous name is still accepted but will raise a warning.
17+
18+
Maintenance
19+
~~~~~~~~~~~
20+
21+
* A great amount of linting has been done to ensure best practices in every line of code.
22+
* Switched all relevant type hints to use the latest practices.
23+
* Fixed the `__all__` exports in the `__init__.py` files.
24+
* Moved type-hint relevant imports in a `TYPE_CHECKING` block to lighten import times.
25+
26+
See `v1.6.0 release notes on GitHub <https://github.com/fsoubelet/PyhDToolkit/releases/tag/1.6.0>`_ and the `full changes since v1.5.0 <https://github.com/fsoubelet/PyhDToolkit/compare/1.5.0...1.6.0>`_.

examples/demo_acd_tracking_spectra.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
AC Dipole Driven Tracking Spectrum
77
==================================
88
9-
This example shows how to use the `~.lhc.install_ac_dipole_as_kicker` and
10-
`~.track.track_single_particle` function to track a particle with the
9+
This example shows how to use the `~.lhc.install_ac_dipole_as_kicker` and
10+
`~.track.track_single_particle` function to track a particle with the
1111
``TRACK`` command of ``MAD-X``, and visualise its coordinates and spectrum.
1212
13-
In this example we will use the LHC lattice to illustrate the ACD tracking
13+
In this example we will use the LHC lattice to illustrate the ACD tracking
1414
workflow when using `~pyhdtoolkit.cpymadtools`.
1515
1616
.. note::
17-
This is very similar to the :ref:`free tracking example <demo-free-tracking>`
18-
with the difference that there is special care to take to install the AC Dipole
19-
element. It is recommended to read that tutorial first as this one will focus
17+
This is very similar to the :ref:`free tracking example <demo-free-tracking>`
18+
with the difference that there is special care to take to install the AC Dipole
19+
element. It is recommended to read that tutorial first as this one will focus
2020
on the specificities of the AC Dipole setup.
2121
2222
.. important::
@@ -33,7 +33,6 @@
3333
import matplotlib.pyplot as plt
3434
import numpy as np
3535
import pandas as pd
36-
3736
from cpymad.madx import Madx
3837

3938
from pyhdtoolkit.cpymadtools import lhc, matching, track
@@ -45,7 +44,7 @@
4544

4645
###############################################################################
4746
# Let's start by setting up the LHC in ``MAD-X``, in this case at top energy.
48-
# To understand the function below have a look at the :ref:`lhc setup example
47+
# To understand the function below have a look at the :ref:`lhc setup example
4948
# <demo-lhc-setup>`.
5049

5150
madx: Madx = lhc.prepare_lhc_run3(

examples/demo_aperture.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Accelerator Aperture
77
====================
88
9-
This example shows how to use the `~.plotting.aperture.plot_aperture` and
9+
This example shows how to use the `~.plotting.aperture.plot_aperture` and
1010
`~.plotting.aperture.plot_physical_apertures` functions to visualise the
1111
available aperture in your machine, with the LHC used for this example.
1212
@@ -23,7 +23,6 @@
2323
"""
2424

2525
import matplotlib.pyplot as plt
26-
2726
from cpymad.madx import Madx
2827

2928
from pyhdtoolkit.cpymadtools import lhc
@@ -35,7 +34,7 @@
3534
plt.rcParams.update(_SPHINX_GALLERY_PARAMS) # for readability of this tutorial
3635

3736
###############################################################################
38-
# Let's start by setting up the LHC in ``MAD-X``, in this case at injection
37+
# Let's start by setting up the LHC in ``MAD-X``, in this case at injection
3938
# optics and energy. To understand the function below have a look at the
4039
# :ref:`lhc setup example <demo-lhc-setup>`.
4140

@@ -86,7 +85,7 @@
8685

8786

8887
###############################################################################
89-
# We can also go for a different type of aperture plot, which tries to give
88+
# We can also go for a different type of aperture plot, which tries to give
9089
# the elements' real physical apertures, with the `~.plotting.aperture.plot_physical_apertures`
9190
# function:
9291

examples/demo_beam_enveloppe.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# sphinx_gallery_thumbnail_number = 1
1515
import matplotlib.pyplot as plt
1616
import numpy as np
17-
1817
from cpymad.madx import Madx
1918

2019
from pyhdtoolkit.plotting.envelope import plot_beam_envelope
@@ -59,7 +58,7 @@
5958
madx.input(
6059
f"""
6160
circum = {circumference};
62-
n_cells = {n_cells}; ! Number of cells
61+
n_cells = {n_cells}; ! Number of cells
6362
lcell = {l_cell};
6463
lq = {l_quad}; ! Length of a quadrupole
6564
ldip = {l_bend};
@@ -71,14 +70,14 @@
7170
mb: sbend, l=ldip, angle=2.0*pi/(4*n_cells), apertype=ellipse, aperture={{{h_gap_dipole}, {v_gap_dipole}}};
7271
f = {f_m};
7372
74-
! Define quadrupoles as multipoles
75-
qf: multipole, knl:={{0,1/f+qtrim_f}};
73+
! Define quadrupoles as multipoles
74+
qf: multipole, knl:={{0,1/f+qtrim_f}};
7675
qd: multipole, knl:={{0,-1/f+qtrim_d}};
77-
qf: quadrupole, l=lq, K1:=1/f/lq + qtrim_f/lq, apertype=ellipse, aperture={{{r_quadrupole}, {r_quadrupole}}};
76+
qf: quadrupole, l=lq, K1:=1/f/lq + qtrim_f/lq, apertype=ellipse, aperture={{{r_quadrupole}, {r_quadrupole}}};
7877
qd: quadrupole, l=lq, K1:=-1/f/lq + qtrim_d/lq, apertype=ellipse, aperture={{{r_quadrupole}, {r_quadrupole}}};
7978
8079
! Define the sextupoles as multipole
81-
! ATTENTION: must use knl:= and NOT knl= to match later!
80+
! ATTENTION: must use knl:= and NOT knl= to match later!
8281
lsex = 0.00001; ! dummy length, only used in the sequence
8382
msf: multipole, knl:={{0,0,ksf}};
8483
msd: multipole, knl:={{0,0,ksd}};

examples/demo_ir_errors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
to assign magnet errors in the Insertion Region magnets of the LHC.
1111
1212
.. warning::
13-
The implementation of this function makes it valid only for LHC IP IRs, which are
13+
The implementation of this function makes it valid only for LHC IP IRs, which are
1414
1, 2, 5 and 8. Other IRs have different layouts that are incompatible.
1515
1616
.. important::
@@ -27,7 +27,6 @@
2727
# sphinx_gallery_thumbnail_number = 1
2828
import matplotlib.pyplot as plt
2929
import numpy as np
30-
3130
from cpymad.madx import Madx
3231

3332
from pyhdtoolkit.cpymadtools import lhc, matching
@@ -38,7 +37,7 @@
3837
plt.rcParams.update(_SPHINX_GALLERY_PARAMS) # for readability of this tutorial
3938

4039
###############################################################################
41-
# Let's start by setting up the LHC in ``MAD-X``, in this case at injection
40+
# Let's start by setting up the LHC in ``MAD-X``, in this case at injection
4241
# optics and energy. To understand the function below have a look at the
4342
# :ref:`lhc setup example <demo-lhc-setup>`.
4443

examples/demo_lattice.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
of several parameters to control the plot on the example case of the LHC.
1414
"""
1515
import matplotlib.pyplot as plt
16-
1716
from cpymad.madx import Madx
1817

1918
from pyhdtoolkit.cpymadtools import lhc, matching

examples/demo_lhc_crossing_schemes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
This is very LHC-specific and will not work with other machines.
1414
"""
1515
import matplotlib.pyplot as plt
16-
1716
from cpymad.madx import Madx
1817

1918
from pyhdtoolkit.cpymadtools import lhc
@@ -35,7 +34,7 @@
3534

3635
###############################################################################
3736
# Let's explicitely re-cycle both sequences to avoid having IR1 split at beginning
38-
# and end of lattice. Note that it is important to re-cycle both sequences from
37+
# and end of lattice. Note that it is important to re-cycle both sequences from
3938
# the same points for the plots later on.
4039

4140
lhc.re_cycle_sequence(madx, sequence="lhcb1", start="IP3")

0 commit comments

Comments
 (0)