Skip to content

Commit a7eff6d

Browse files
authored
Handling improvements (#9)
* A variable to tell you what strings have been send to and from MAD-NG * Allow debug to not just go to the stdout * Change how the ctrl-c is handled. Previous way led to the process hanging. * Update test names to be more typical * Rename most variables to make it clearer * Prepare version update * Modernise workflows (#8) (#10) * Version bumps * Remove EOL python * Change workflow to use editable install - May revert * Update to use Pathlib and do check for binary first * Update test-pymadng.yml to MAD 0.9.8 * Remove speed test (Useless - slowdown caused by history feature) * Update python-publish.yml for next release --------- Co-authored-by: jgray-19 <[email protected]>
1 parent 09c90d0 commit a7eff6d

File tree

16 files changed

+365
-260
lines changed

16 files changed

+365
-260
lines changed

.github/workflows/python-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ jobs:
3737
- name: Get MAD Binaries
3838
run: |
3939
mkdir src/pymadng/bin
40-
curl http://madx.web.cern.ch/madx/releases/madng/madng-linux-latest -o src/pymadng/bin/mad_Linux
41-
curl http://madx.web.cern.ch/madx/releases/madng/madng-macos-latest -o src/pymadng/bin/mad_Darwin
40+
curl https://madx.web.cern.ch/madx/releases/madng/0.9/mad-linux-0.9.9 -o src/pymadng/bin/mad_Linux
41+
curl https://madx.web.cern.ch/madx/releases/madng/0.9/mad-macos-0.9.9 -o src/pymadng/bin/mad_Darwin
4242
chmod +x src/pymadng/bin/mad_Linux src/pymadng/bin/mad_Darwin
4343
- name: Build package
4444
run: python -m build

.github/workflows/test-pymadng.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
jobs:
1616
build:
1717
runs-on: ${{ matrix.os }}
18+
defaults:
19+
run:
20+
shell: bash
1821
strategy:
1922
fail-fast: false
2023
matrix:
@@ -29,14 +32,14 @@ jobs:
2932
python-version: ${{ matrix.python-version }}
3033
- name: Get MAD Binaries
3134
run: |
32-
mkdir src/pymadng/bin
33-
curl http://madx.web.cern.ch/madx/releases/madng/madng-linux-latest -o src/pymadng/bin/mad_Linux
34-
curl http://madx.web.cern.ch/madx/releases/madng/madng-macos-latest -o src/pymadng/bin/mad_Darwin
35-
chmod +x src/pymadng/bin/mad_Linux src/pymadng/bin/mad_Darwin
35+
mkdir ./src/pymadng/bin
36+
curl https://madx.web.cern.ch/madx/releases/madng/0.9/mad-linux-0.9.8 -o ./src/pymadng/bin/mad_Linux
37+
curl https://madx.web.cern.ch/madx/releases/madng/0.9/mad-macos-0.9.8 -o ./src/pymadng/bin/mad_Darwin
3638
- name: Install dependencies
3739
run: |
3840
python -m pip install --upgrade pip
3941
python -m pip install -e .[tfs]
4042
- name: Test with python
4143
run: |
44+
chmod +x ./src/pymadng/bin/mad_Linux ./src/pymadng/bin/mad_Darwin
4245
python -m unittest tests/*

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
0.5.0 (2024/10/30)
2+
3+
Add `history` method to get the history of communication of strings to MAD-NG. \
4+
Rename a significant amount of the code to be more readable. \
5+
Allow debug mode to be set to a string, which will be the file that the debug information is written to. \
6+
Remove support for Python EOL, now only supporting Python 3.9 and above. \
7+
Change how ctrl-c is handled, now it will raise a KeyboardInterrupt error and delete the MAD process. \
8+
19
0.4.6 (2024/01/17)
210

311
No change, releasing with MAD 0.9.8-1

examples/ex-benchmark-and-fork/ex-benchmark-and-fork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
# METHOD 2
7676
mad["circum", "lcell"] = 60, 20
7777
mad["deferred"] = mad.MAD.typeid.deferred
78-
mad["v"] = mad.deferred(f = "lcell/math.sin(math.pi/4)/4", k = "1/v.f")
78+
mad["v"] = mad.create_deferred_expression(f = "lcell/math.sin(math.pi/4)/4", k = "1/v.f")
7979

8080
mad["qf"] = mad.quadrupole("knl:={0, v.k}", l = 1)
8181
mad["qd"] = mad.quadrupole("knl:={0, -v.k}", l = 1)

examples/ex-fodo/ex-fodos.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mad.load("MADX", "seq")
1818
mad.seq.beam = mad.beam()
1919
mad["mtbl", "mflw"] = mad.twiss(sequence=mad.seq, method=4, implicit=True, nslice=10, save="'atbody'")
20-
cols = mad.py_strs_to_mad_strs(["name", "s", "beta11", "beta22", "mu1", "mu2", "alfa11", "alfa22"])
20+
cols = mad.quote_strings(["name", "s", "beta11", "beta22", "mu1", "mu2", "alfa11", "alfa22"])
2121
mad.mtbl.write("'twiss_py.tfs'", cols)
2222
for x in mad.seq:
2323
print(x.name, x.kind)
@@ -30,7 +30,7 @@
3030
mad["circum", "lcell"] = 60, 20
3131

3232
mad.load("math", "sin", "pi")
33-
mad["v"] = mad.deferred(k="1/(lcell/sin(pi/4)/4)")
33+
mad["v"] = mad.create_deferred_expression(k="1/(lcell/sin(pi/4)/4)")
3434

3535
mad["qf"] = mad.quadrupole("knl:={0, v.k}", l=1)
3636
mad["qd"] = mad.quadrupole("knl:={0, -v.k}", l=1)
@@ -44,7 +44,7 @@
4444
""", refer="'entry'", l=mad.circum,)
4545
mad.seq.beam = mad.beam()
4646
mad["mtbl", "mflw"] = mad.twiss(sequence=mad.seq, method=4, implicit=True, nslice=10, save="'atbody'")
47-
cols = mad.py_strs_to_mad_strs(["name", "s", "beta11", "beta22", "mu1", "mu2", "alfa11", "alfa22"])
47+
cols = mad.quote_strings(["name", "s", "beta11", "beta22", "mu1", "mu2", "alfa11", "alfa22"])
4848
mad.mtbl.write("'twiss_py.tfs'", cols)
4949

5050
plt.plot(mad.mtbl.s, mad.mtbl["beta11"])

examples/ex-lhc-couplingLocal/lhc-couplingLocal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"'invalid number of elements %d in LHCB1 (6694 expected)'", "#lhcb1")
2222

2323
mad.lhcb1.beam = mad.beam(particle="'proton'", energy=mad.nrj)
24-
mad.MADX_env_send("""
24+
mad.evaluate_in_madx_environment("""
2525
ktqx1_r2 = -ktqx1_l2 ! remove the link between these 2 vars
2626
kqsx3_l2 = -0.0015
2727
kqsx3_r2 = +0.0015

examples/ex-ps-twiss/ps-twiss.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
mad["srv", "mflw"] = mad.survey(sequence=mad.ps)
1919

2020
mad.srv.write("'PS_survey_py.tfs'",
21-
mad.py_strs_to_mad_strs(["name", "kind", "s", "l", "angle", "x", "y", "z", "theta"]),
21+
mad.quote_strings(["name", "kind", "s", "l", "angle", "x", "y", "z", "theta"]),
2222
)
2323

2424
mad["mtbl", "mflw"] = mad.twiss(sequence=mad.ps, method=6, nslice=3, chrom=True)
2525

2626
mad.load("MAD.gphys", "melmcol")
2727
#Add element properties as columns
2828
mad.melmcol(mad.mtbl,
29-
mad.py_strs_to_mad_strs(
29+
mad.quote_strings(
3030
["angle", "tilt", "k0l", "k1l", "k2l", "k3l", "k4l", "k5l", "k6l", "k0sl",
3131
"k1sl", "k2sl", "k3sl", "k4sl", "k5sl", "k6sl", "ksl", "hkick", "vkick" ]),
3232
)
3333

3434
mad.mtbl.write("'PS_twiss_py.tfs'",
35-
mad.py_strs_to_mad_strs(
35+
mad.quote_strings(
3636
["name", "kind", "s", "x", "px", "beta11", "alfa11", "beta22", "alfa22","dx",
3737
"dpx", "mu1", "mu2", "l", "angle", "k0l", "k1l", "k2l", "k3l", "hkick", "vkick"]
3838
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88
name = "pymadng"
99
dynamic = ["version"]
1010
authors = [
11-
{ name="Joshua Gray", email="[email protected]" },
11+
{ name="Joshua Gray" },
1212
]
1313
description = "A python interface to MAD-NG running as subprocess"
1414
readme = "README.md"

src/pymadng/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .madp_object import MAD
22

33
__title__ = "pymadng"
4-
__version__ = "0.4.6"
4+
__version__ = "0.5.0"
55

66
__summary__ = "Python interface to MAD-NG running as subprocess"
77
__uri__ = "https://github.com/MethodicalAcceleratorDesign/MADpy"

0 commit comments

Comments
 (0)