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

OP knobs #85

Merged
merged 20 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ They are organised as follows.
### Documentation

The `documentation` workflow triggers on any push to master, builds the documentation and pushes it to the `gh-pages` branch (if the build is successful).
It runs on `ubuntu-latest` and the lowest supported Python version, `Python 3.7`.
It runs on `ubuntu-latest` and `Python 3.9`.

### Testing Suite

Expand All @@ -16,7 +16,7 @@ Tests run on a matrix of all supported operating systems for all supported Pytho
### Test Coverage

Test coverage is calculated in the `coverage` wokflow, which triggers on pushes to `master` and any push to a `pull request`.
It runs on `ubuntu-latest` & the lowest supported Python version (`Python 3.7`), and reports the coverage results of the test suite to `Codecov`.
It runs on `ubuntu-latest` and `Python 3.9`, and reports the coverage results of the test suite to `Codecov`.


### Regular Testing
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix: # only lowest supported python on ubuntu-latest
os: [ubuntu-latest]
python-version: [3.7]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9, 3.x] # crons should always run latest python hence 3.x
os: [ubuntu-18.04, ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9, "3.10", 3.x] # crons should always run latest python hence 3.x
exclude:
- os: windows-latest
python-version: "3.10"
- os: windows-latest
python-version: "3.x"
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix: # only lowest supported python on ubuntu-latest
os: [ubuntu-latest]
python-version: [3.7]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix: # only lowest supported python on ubuntu-latest
os: [ubuntu-latest]
python-version: [3.7]
python-version: [3.9]


steps:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04, macos-latest, windows-latest]
os: [ubuntu-18.04, ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
exclude:
- os: windows-latest
python-version: "3.10"
fail-fast: false

steps:
Expand Down
15 changes: 15 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ Release Notes

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

.. _release_0.19.1:

0.19.1
------

Maintenance
~~~~~~~~~~~

* The `~pyhdtoolkit.cpymadtools.lhc.get_lhc_tune_and_chroma_knobs` function now can has a new boolean argument, `run3`, to determine if the standard `_op` knobs should be returned.
* The functions in the `~pyhdtoolkit.cpymadtools.matching` module now also have the `run3` argument, and will call the Run 3 `_op` knobs if this argument is set to `True` and the `LHC` accelerator is passed.
* Fixes have been provided to the various Github Actions workflow of the repository.

See `v0.19.1 release notes on GitHub <https://github.com/fsoubelet/PyhDToolkit/releases/tag/0.19.1>`_ and the `full changes since v0.18.0 <https://github.com/fsoubelet/PyhDToolkit/compare/0.19.0...0.19.1>`_.


.. _release_0.19.0:

0.19.0
Expand Down
10 changes: 8 additions & 2 deletions pyhdtoolkit/cpymadtools/lhc.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def get_lhc_bpms_list(madx: Madx) -> List[str]:


def get_lhc_tune_and_chroma_knobs(
accelerator: str, beam: int = 1, telescopic_squeeze: bool = True
accelerator: str, beam: int = 1, telescopic_squeeze: bool = True, run3: bool = False
) -> Tuple[str, str, str, str]:
"""
Gets names of knobs needed to match tunes and chromaticities as a tuple of strings,
Expand All @@ -682,6 +682,7 @@ def get_lhc_tune_and_chroma_knobs(
beam (int): Beam to use, for the knob names. Defaults to 1.
telescopic_squeeze (bool): if set to `True`, returns the knobs for Telescopic
Squeeze configuration. Defaults to `True` to reflect run III scenarios.
run3 (bool): if set to `True`, returns the Run 3 `*_op` knobs.

Returns:
A `tuple` of strings with knobs for ``(qx, qy, dqx, dqy)``.
Expand All @@ -698,7 +699,12 @@ def get_lhc_tune_and_chroma_knobs(
('kqtf.b2_sq', 'kqtd.b2_sq', 'ksf.b2_sq', 'ksd.b2_sq')
"""
beam = 2 if beam == 4 else beam
suffix = "_sq" if telescopic_squeeze else ""
if run3:
suffix = "_op"
elif telescopic_squeeze:
suffix = "_sq"
else:
suffix = ""

if accelerator.upper() not in ("LHC", "HLLHC"):
logger.error("Invalid accelerator name, only 'LHC' and 'HLLHC' implemented")
Expand Down
16 changes: 12 additions & 4 deletions pyhdtoolkit/cpymadtools/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def match_tunes_and_chromaticities(
dq2_target: float = None,
varied_knobs: Sequence[str] = None,
telescopic_squeeze: bool = True,
run3: bool = False,
step: float = 1e-7,
calls: int = 100,
tolerance: float = 1e-21,
Expand Down Expand Up @@ -81,7 +82,8 @@ def match_tunes_and_chromaticities(
could be ``["kqf", "ksd", "kqf", "kqd"]`` as they are common names used for quadrupole and sextupole
strengths (focusing / defocusing) in most examples.
telescopic_squeeze (bool): ``LHC`` specific. If set to `True`, uses the ``(HL)LHC`` knobs for Telescopic
Squeeze configuration. Defaults to `True` as of run III.
Squeeze configuration. Defaults to `True` since `v0.9.0`.
run3 (bool): if set to `True`, uses the `LHC` Run 3 `*_op` knobs. Defaults to `False`.
step (float): step size to use when varying knobs.
calls (int): max number of varying calls to perform.
tolerance (float): tolerance for successfull matching.
Expand Down Expand Up @@ -120,7 +122,7 @@ def match_tunes_and_chromaticities(
if accelerator and not varied_knobs:
logger.trace(f"Getting knobs from default {accelerator.upper()} values")
lhc_knobs = get_lhc_tune_and_chroma_knobs(
accelerator=accelerator, beam=int(sequence[-1]), telescopic_squeeze=telescopic_squeeze
accelerator=accelerator, beam=int(sequence[-1]), telescopic_squeeze=telescopic_squeeze, run3=run3
)
tune_knobs, chroma_knobs = lhc_knobs[:2], lhc_knobs[2:] # first two, last two

Expand Down Expand Up @@ -171,6 +173,7 @@ def match_tunes(
q2_target: float = None,
varied_knobs: Sequence[str] = None,
telescopic_squeeze: bool = True,
run3: bool = False,
step: float = 1e-7,
calls: int = 100,
tolerance: float = 1e-21,
Expand All @@ -195,7 +198,8 @@ def match_tunes(
q2_target (float): vertical tune to match to.
varied_knobs (Sequence[str]): the variables names to ``VARY`` in the ``MAD-X`` ``MATCH`` routine.
telescopic_squeeze (bool): ``LHC`` specific. If set to `True`, uses the ``(HL)LHC`` knobs for Telescopic
Squeeze configuration. Defaults to `True` as of run III.
Squeeze configuration. Defaults to `True` since `v0.9.0`.
run3 (bool): if set to `True`, uses the `LHC` Run 3 `*_op` knobs. Defaults to `False`.
step (float): step size to use when varying knobs. Defaults to `1E-7`.
calls (int): max number of varying calls to perform. Defaults to `100`.
tolerance (float): tolerance for successfull matching. Defaults to `1E-21`.
Expand Down Expand Up @@ -236,6 +240,7 @@ def match_tunes(
dq2_target=None,
varied_knobs=varied_knobs,
telescopic_squeeze=telescopic_squeeze,
run3=run3,
step=step,
calls=calls,
tolerance=tolerance,
Expand All @@ -250,6 +255,7 @@ def match_chromaticities(
dq2_target: float = None,
varied_knobs: Sequence[str] = None,
telescopic_squeeze: bool = True,
run3: bool = False,
step: float = 1e-7,
calls: int = 100,
tolerance: float = 1e-21,
Expand All @@ -274,7 +280,8 @@ def match_chromaticities(
q2_target (float): vertical tune to match to.
varied_knobs (Sequence[str]): the variables names to ``VARY`` in the ``MAD-X`` ``MATCH`` routine.
telescopic_squeeze (bool): ``LHC`` specific. If set to `True`, uses the ``(HL)LHC`` knobs for Telescopic
Squeeze configuration. Defaults to `True` as of run III.
Squeeze configuration. Defaults to `True` since `v0.9.0`.
run3 (bool): if set to `True`, uses the `LHC` Run 3 `*_op` knobs. Defaults to `False`.
step (float): step size to use when varying knobs. Defaults to `1E-7`.
calls (int): max number of varying calls to perform. Defaults to `100`.
tolerance (float): tolerance for successfull matching. Defaults to `1E-21`.
Expand Down Expand Up @@ -315,6 +322,7 @@ def match_chromaticities(
dq2_target=dq2_target,
varied_knobs=varied_knobs,
telescopic_squeeze=telescopic_squeeze,
run3=run3,
step=step,
calls=calls,
tolerance=tolerance,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyhdtoolkit"
version = "0.19.0"
version = "0.19.1"
description = "An all-in-one toolkit package to ease my Python work in my PhD."
authors = ["Felix Soubelet <felix.soubelet@cern.ch>"]
license = "MIT"
Expand Down
12 changes: 9 additions & 3 deletions tests/test_cpymadtools/test_lhc.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,16 @@ def test_vary_independent_ir_quads_raises_on_wrong_quads(self, _non_matched_lhc_

@pytest.mark.parametrize("beam", [1, 2, 3, 4])
@pytest.mark.parametrize("telescopic_squeeze", [False, True])
def test_lhc_tune_and_chroma_knobs(self, beam, telescopic_squeeze):
@pytest.mark.parametrize("run3", [False, True])
def test_lhc_tune_and_chroma_knobs(self, beam, telescopic_squeeze, run3):
expected_beam = 2 if beam == 4 else beam
expected_suffix = "_sq" if telescopic_squeeze else ""
assert get_lhc_tune_and_chroma_knobs("LHC", beam, telescopic_squeeze) == (
if run3:
expected_suffix = "_op"
elif telescopic_squeeze:
expected_suffix = "_sq"
else:
expected_suffix = ""
assert get_lhc_tune_and_chroma_knobs("LHC", beam, telescopic_squeeze, run3) == (
f"dQx.b{expected_beam}{expected_suffix}",
f"dQy.b{expected_beam}{expected_suffix}",
f"dQpx.b{expected_beam}{expected_suffix}",
Expand Down