Writing from sandbox to machine - initial code

This commit is contained in:
2025-06-12 17:42:08 +02:00
committed by Sven
parent 91e3c5ccae
commit d8693e5529
8 changed files with 146 additions and 19 deletions

View File

@@ -605,7 +605,10 @@
{
"Script": "Scripts/switchyard.madx"
}
]
],
"User": {
"LEAKDISP": 0.0
}
},
"Athos Diagnostics": {
"Variable": [

View File

@@ -41,7 +41,7 @@ CONSTRAINT, SEQUENCE=swissfel, RANGE=satsy01$end, X<10;
LMDIF, CALLS=1000, TOLERANCE=1.E-21;
ENDMATCH;
!satsy01.mqua280.k1 = satsy01.mqua280.k1*1.3;
satsy01.mqua280.k1 = satsy01.mqua280.k1*(1+leakdisp);
!------------------------------------------
! close vertical dispersion

View File

@@ -12,9 +12,10 @@ def MatchReference(loc,twiss,limit=None): # limit 1 -> smaller than, 2 -> large
return match
def MatchParameter(var0,tar0):
return {'Variable':var0,'Target':tar0}
def MatchParameter(var0,tar0,user0=None):
if user0 is None:
return {'Variable':var0,'Target':tar0}
return {'Variable':var0,'Target':tar0,'User':user0}
path ="MatchingConfig/"
label='Reference'
@@ -138,7 +139,9 @@ var=['SATSY01-MQUA020','SATSY01-MQUA040','SATSY01-MQUA070','SATSY01-MQUA090','SA
'SATSY01-MQUA300','SATSY02-MQUA010','SATSY02-MQUA110','SATSY02-MQUA120','SATSY02-MQUA230','SATSY03-MQUA010','SATSY03-MQUA040','SATSY03-MQUA070',
'SATSY03-MQUA100','SATSY03-MQUA130','SATCL01-MQUA120','SATCL01-MQUA130','SATCL01-MQUA180','SATCL01-MQUA190']
tar=[{'Script':'Scripts/switchyard.madx'}]
parameter['Switchyard']=MatchParameter(var, tar)
uservar = {'LEAKDISP':0.0}
parameter['Switchyard']=MatchParameter(var, tar,uservar)
var=['SATDI01-MQUA025','SATDI01-MQUA080','SATDI01-MQUA220','SATDI01-MQUA230']
tar = [reference['HERO']]

View File

@@ -1,4 +1,4 @@
1) if plotting window is closed, reopen it
2) make matching targets editable
4) export elegant lattice
5) support of other reference files -> fill up the selection list

View File

@@ -41,6 +41,10 @@ class Model:
def getVariableInfo(self,varlist):
variable = {}
for var in varlist:
if isinstance(var,dict):
for key in var.keys():
variable[key] = {'Val':var[key],'Max':None}
continue
ele = self.om.getElement(var.replace('-','.'))
if ele is None:
variable[var]={'Val':0,'Max':None}
@@ -251,8 +255,8 @@ class Model:
return
if 'Script' in target.keys():
res,twiss,err = self.madx.callScript(script = target['Script'],sequence=sequence, start=start, end=end,init=itwiss,var=var)
print(var)
res,twiss,err = self.madx.callScript(script = target['Script'],sequence=sequence, start=start, end=end,init=itwiss,var=var,preset=True)
self.updateModelFromMatching(res)
self.parent.reference.updateMatchPoint(ID, err)
if self.matchplot:

View File

@@ -1,6 +1,8 @@
import json
import copy
from PyQt5 import QtCore, QtGui, QtWidgets
from numpy.ma.core import floor_divide
#from fontTools.misc.cython import returns
CBeige = QtGui.QColor(250, 240, 200)
@@ -18,6 +20,7 @@ class ReferenceManager:
self.reference={}
self.save={}
self.label=None
self.matchfile=''
self.twisswidget={'betax':self.parent.UIBetax,'betay':self.parent.UIBetay,
'alphax':self.parent.UIAlphax,'alphay':self.parent.UIAlphay,
@@ -62,6 +65,7 @@ class ReferenceManager:
def loadReference(self, filename):
with open(filename) as f:
self.settings = json.load(f)
self.matchfile=filename
self.order={ele['MatchID']:i for i,ele in enumerate(self.settings['Order'])}
self.reference=self.settings['Reference'] # this are fixed points in the lattice
self.label=self.settings['Label']
@@ -77,6 +81,24 @@ class ReferenceManager:
self.save[ID]={'betax':twiss.betx[0],'betay':twiss.bety[0],'alphax':twiss.alfx[0],'alphay':twiss.alfy[0]}
print('saving twissvalue for',ID,':',self.save[ID])
def updateUserVariables(self):
ID = str(self.parent.UIMatchLabel.text())
print(self.settings['Parameter'][ID])
return
# ncol = table.columnCount()
# nrow = table.rowCount()
# content={}
# for irow in range(nrow):
# tag = str(table.item(irow,0).text())
# content[tag]={}
# for icol in range(1,ncol):
# fld = str(table.item(irow,icol).text())
# content[tag][icol]=fld
# return content
def getMatchingPoint(self):
idx = self.parent.UIMatchOrder.currentRow()
if idx < 0:
@@ -112,6 +134,9 @@ class ReferenceManager:
varlist = self.parameter[ID]['Variable']
variable = self.parent.model.getVariableInfo(varlist)
if 'User' in self.parameter[ID]:
for key in self.parameter[ID]['User'].keys():
variable[key]={'Val':self.parameter[ID]['User'][key],'Max':None}
cond = {}
targets = self.parameter[ID]['Target']

View File

@@ -416,9 +416,11 @@ class Ui_OpticsGUI(object):
self.label_17.setObjectName("label_17")
self.gridLayout_5.addWidget(self.label_17, 1, 0, 1, 1)
self.UIMatchSequence = QtWidgets.QLineEdit(self.tab_2)
self.UIMatchSequence.setReadOnly(True)
self.UIMatchSequence.setObjectName("UIMatchSequence")
self.gridLayout_5.addWidget(self.UIMatchSequence, 3, 1, 1, 1)
self.UIMatchLabel = QtWidgets.QLineEdit(self.tab_2)
self.UIMatchLabel.setReadOnly(True)
self.UIMatchLabel.setObjectName("UIMatchLabel")
self.gridLayout_5.addWidget(self.UIMatchLabel, 0, 1, 1, 1)
self.label_11 = QtWidgets.QLabel(self.tab_2)
@@ -428,12 +430,14 @@ class Ui_OpticsGUI(object):
self.label_16.setObjectName("label_16")
self.gridLayout_5.addWidget(self.label_16, 0, 0, 1, 1)
self.UIMatchStart = QtWidgets.QLineEdit(self.tab_2)
self.UIMatchStart.setReadOnly(True)
self.UIMatchStart.setObjectName("UIMatchStart")
self.gridLayout_5.addWidget(self.UIMatchStart, 1, 1, 1, 1)
self.label_12 = QtWidgets.QLabel(self.tab_2)
self.label_12.setObjectName("label_12")
self.gridLayout_5.addWidget(self.label_12, 2, 0, 1, 1)
self.UIMatchEnd = QtWidgets.QLineEdit(self.tab_2)
self.UIMatchEnd.setReadOnly(True)
self.UIMatchEnd.setObjectName("UIMatchEnd")
self.gridLayout_5.addWidget(self.UIMatchEnd, 2, 1, 1, 1)
self.verticalLayout_7.addLayout(self.gridLayout_5)
@@ -481,6 +485,8 @@ class Ui_OpticsGUI(object):
self.menuFile.setObjectName("menuFile")
self.menuHelp = QtWidgets.QMenu(self.menubar)
self.menuHelp.setObjectName("menuHelp")
self.menuMatching = QtWidgets.QMenu(self.menubar)
self.menuMatching.setObjectName("menuMatching")
OpticsGUI.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(OpticsGUI)
self.statusbar.setObjectName("statusbar")
@@ -503,7 +509,6 @@ class Ui_OpticsGUI(object):
self.actionMatch.setObjectName("actionMatch")
self.actionQuit = QtWidgets.QAction(OpticsGUI)
self.actionQuit.setEnabled(True)
self.actionQuit.setShortcut("")
self.actionQuit.setObjectName("actionQuit")
self.actionExport_Lattice = QtWidgets.QAction(OpticsGUI)
self.actionExport_Lattice.setEnabled(True)
@@ -591,17 +596,37 @@ class Ui_OpticsGUI(object):
self.actionNew_Reference.setObjectName("actionNew_Reference")
self.actionSave = QtWidgets.QAction(OpticsGUI)
self.actionSave.setObjectName("actionSave")
self.actionExport_Elegant_Lattice = QtWidgets.QAction(OpticsGUI)
self.actionExport_Elegant_Lattice.setObjectName("actionExport_Elegant_Lattice")
self.actionOpen_Matching_Script = QtWidgets.QAction(OpticsGUI)
self.actionOpen_Matching_Script.setObjectName("actionOpen_Matching_Script")
self.actionReloadMatch = QtWidgets.QAction(OpticsGUI)
self.actionReloadMatch.setObjectName("actionReloadMatch")
self.actionOpenMatch = QtWidgets.QAction(OpticsGUI)
self.actionOpenMatch.setObjectName("actionOpenMatch")
self.actionOpenMatchEditor = QtWidgets.QAction(OpticsGUI)
self.actionOpenMatchEditor.setObjectName("actionOpenMatchEditor")
self.actionOpenScriptEditor = QtWidgets.QAction(OpticsGUI)
self.actionOpenScriptEditor.setObjectName("actionOpenScriptEditor")
self.menuFile.addAction(self.actionOpen_2)
self.menuFile.addAction(self.actionSave)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionExport_Elegant_Lattice)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionQuit)
self.menuFile.addSeparator()
self.menuHelp.addAction(self.actionAbout)
self.menuHelp.addAction(self.actionHelp)
self.menuMatching.addAction(self.actionOpenMatch)
self.menuMatching.addAction(self.actionReloadMatch)
self.menuMatching.addAction(self.actionOpenMatchEditor)
self.menuMatching.addAction(self.actionOpenScriptEditor)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuMatching.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
self.retranslateUi(OpticsGUI)
self.TabMaster.setCurrentIndex(2)
self.TabMaster.setCurrentIndex(0)
self.actionQuit.triggered.connect(OpticsGUI.close) # type: ignore
QtCore.QMetaObject.connectSlotsByName(OpticsGUI)
@@ -651,7 +676,7 @@ class Ui_OpticsGUI(object):
self.TabMaster.setTabText(self.TabMaster.indexOf(self.tab_8), _translate("OpticsGUI", "Sandbox"))
self.UIMatchSelected.setText(_translate("OpticsGUI", "Match Selected"))
self.label_14.setText(_translate("OpticsGUI", "Label"))
self.label_15.setText(_translate("OpticsGUI", "Matching Point Order (Closest Ref. Point)"))
self.label_15.setText(_translate("OpticsGUI", "Matching Order (Closest Reference Point)"))
self.UIMatchRandom.setText(_translate("OpticsGUI", "Random Initialization"))
self.label_21.setText(_translate("OpticsGUI", "Matching Point"))
self.label_17.setText(_translate("OpticsGUI", "Start"))
@@ -673,6 +698,7 @@ class Ui_OpticsGUI(object):
self.TabMaster.setTabText(self.TabMaster.indexOf(self.tab_2), _translate("OpticsGUI", "Matching"))
self.menuFile.setTitle(_translate("OpticsGUI", "File"))
self.menuHelp.setTitle(_translate("OpticsGUI", "Help"))
self.menuMatching.setTitle(_translate("OpticsGUI", "Matching"))
self.actionOpen_2.setText(_translate("OpticsGUI", "Open Settings..."))
self.actionOpen_2.setShortcut(_translate("OpticsGUI", "Ctrl+O"))
self.actionOpen.setText(_translate("OpticsGUI", "Open Model..."))
@@ -688,6 +714,7 @@ class Ui_OpticsGUI(object):
self.actionMatch.setText(_translate("OpticsGUI", "Match"))
self.actionMatch.setShortcut(_translate("OpticsGUI", "Ctrl+M"))
self.actionQuit.setText(_translate("OpticsGUI", "Quit"))
self.actionQuit.setShortcut(_translate("OpticsGUI", "Ctrl+Q"))
self.actionExport_Lattice.setText(_translate("OpticsGUI", "Export Lattice..."))
self.actionExport_Magnet_Settings.setText(_translate("OpticsGUI", "Export Magnet Settings..."))
self.actionAbout.setText(_translate("OpticsGUI", "About..."))
@@ -727,3 +754,9 @@ class Ui_OpticsGUI(object):
self.actionSave_Reference.setText(_translate("OpticsGUI", "Save Reference"))
self.actionNew_Reference.setText(_translate("OpticsGUI", "New Reference"))
self.actionSave.setText(_translate("OpticsGUI", "Save Settings..."))
self.actionExport_Elegant_Lattice.setText(_translate("OpticsGUI", "Export Elegant Lattice..."))
self.actionOpen_Matching_Script.setText(_translate("OpticsGUI", "Open Matching Script..."))
self.actionReloadMatch.setText(_translate("OpticsGUI", "Reload Current Matching File"))
self.actionOpenMatch.setText(_translate("OpticsGUI", "Open New Matching File..."))
self.actionOpenMatchEditor.setText(_translate("OpticsGUI", "Open Current Matching File in Editor"))
self.actionOpenScriptEditor.setText(_translate("OpticsGUI", "Open Script in Editor"))

View File

@@ -24,7 +24,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
@@ -636,7 +636,7 @@
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Matching Point Order (Closest Ref. Point)</string>
<string>Matching Order (Closest Reference Point)</string>
</property>
</widget>
</item>
@@ -691,10 +691,18 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="UIMatchSequence"/>
<widget class="QLineEdit" name="UIMatchSequence">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="UIMatchLabel"/>
<widget class="QLineEdit" name="UIMatchLabel">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
@@ -711,7 +719,11 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="UIMatchStart"/>
<widget class="QLineEdit" name="UIMatchStart">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
@@ -721,7 +733,11 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="UIMatchEnd"/>
<widget class="QLineEdit" name="UIMatchEnd">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
@@ -815,7 +831,10 @@
<addaction name="actionOpen_2"/>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionExport_Elegant_Lattice"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
@@ -824,7 +843,17 @@
<addaction name="actionAbout"/>
<addaction name="actionHelp"/>
</widget>
<widget class="QMenu" name="menuMatching">
<property name="title">
<string>Matching</string>
</property>
<addaction name="actionOpenMatch"/>
<addaction name="actionReloadMatch"/>
<addaction name="actionOpenMatchEditor"/>
<addaction name="actionOpenScriptEditor"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuMatching"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
@@ -894,7 +923,7 @@
<string>Quit</string>
</property>
<property name="shortcut">
<string/>
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionExport_Lattice">
@@ -1140,6 +1169,36 @@
<string>Save Settings...</string>
</property>
</action>
<action name="actionExport_Elegant_Lattice">
<property name="text">
<string>Export Elegant Lattice...</string>
</property>
</action>
<action name="actionOpen_Matching_Script">
<property name="text">
<string>Open Matching Script...</string>
</property>
</action>
<action name="actionReloadMatch">
<property name="text">
<string>Reload Current Matching File</string>
</property>
</action>
<action name="actionOpenMatch">
<property name="text">
<string>Open New Matching File...</string>
</property>
</action>
<action name="actionOpenMatchEditor">
<property name="text">
<string>Open Current Matching File in Editor</string>
</property>
</action>
<action name="actionOpenScriptEditor">
<property name="text">
<string>Open Script in Editor</string>
</property>
</action>
</widget>
<resources/>
<connections>