/usr/lib/python2.7/dist-packages/code_saturne/Pages/BatchRunningView.py is in code-saturne-data 4.2.0+repack-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 | # -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2015 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
#-------------------------------------------------------------------------------
"""
This module contains the following classes and function:
- BatchRunningAdvancedOptionsDialogView
- BatchRunningStopByIterationDialogView
- BatchRunningListingLinesDisplayedDialogView
- ListingDialogView
- BatchRunningView
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import os, sys
import string, types
import re
import logging
import subprocess
try:
import ConfigParser # Python2
configparser = ConfigParser
except Exception:
import configparser # Python3
#-------------------------------------------------------------------------------
# Third-party modules
#-------------------------------------------------------------------------------
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import cs_case
import cs_exec_environment
import cs_runcase
import cs_submit
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from code_saturne.Pages.BatchRunningForm import Ui_BatchRunningForm
from code_saturne.Pages.BatchRunningAdvancedOptionsDialogForm import Ui_BatchRunningAdvancedOptionsDialogForm
from code_saturne.Pages.BatchRunningDebugOptionsHelpDialogForm import Ui_BatchRunningDebugOptionsHelpDialogForm
from code_saturne.Pages.BatchRunningStopByIterationDialogForm import Ui_BatchRunningStopByIterationDialogForm
from code_saturne.Base.Toolbox import GuiParam
from code_saturne.Base.QtPage import ComboModel, IntValidator, RegExpValidator, setGreenColor
from code_saturne.Base.QtPage import to_qvariant, from_qvariant
from code_saturne.Base.CommandMgrDialogView import CommandMgrDialogView
from code_saturne.Pages.BatchRunningModel import BatchRunningModel
from code_saturne.Pages.ScriptRunningModel import ScriptRunningModel
from code_saturne.Pages.LocalizationModel import LocalizationModel, Zone
#-------------------------------------------------------------------------------
# log config
#-------------------------------------------------------------------------------
logging.basicConfig()
log = logging.getLogger("BatchRunningView")
log.setLevel(GuiParam.DEBUG)
#-------------------------------------------------------------------------------
# Popup advanced options
#-------------------------------------------------------------------------------
class BatchRunningDebugOptionsHelpDialogView(QDialog, Ui_BatchRunningDebugOptionsHelpDialogForm):
"""
Help dialog
"""
def __init__(self, parent):
"""
Constructor
"""
QDialog.__init__(self, parent)
Ui_BatchRunningAdvancedOptionsDialogForm.__init__(self)
self.setupUi(self)
self.retranslateUi(self)
self.setWindowTitle(self.tr("Debugger syntax help"))
self.parent = parent
# Connections
self.connect(self.pushButtonClose, SIGNAL("clicked()"), self.slotDebugclose)
@pyqtSignature("")
def slotDebugclose(self):
"""
Close debugging page
"""
QDialog.accept(self)
return
#-------------------------------------------------------------------------------
# Popup advanced options
#-------------------------------------------------------------------------------
class BatchRunningAdvancedOptionsDialogView(QDialog, Ui_BatchRunningAdvancedOptionsDialogForm):
"""
Advanced dialog
"""
def __init__(self, parent):
"""
Constructor
"""
QDialog.__init__(self, parent)
Ui_BatchRunningAdvancedOptionsDialogForm.__init__(self)
self.setupUi(self)
self.setWindowTitle(self.tr("Advanced options"))
self.parent = parent
# Combo models
self.modelCSOUT1 = ComboModel(self.comboBox_6, 2, 1)
self.modelCSOUT2 = ComboModel(self.comboBox_7, 3, 1)
# Combo items
self.modelCSOUT1.addItem(self.tr("to standard output"), 'stdout')
self.modelCSOUT1.addItem(self.tr("to listing"), 'listing')
self.modelCSOUT2.addItem(self.tr("no output"), 'null')
self.modelCSOUT2.addItem(self.tr("to standard output"), 'stdout')
self.modelCSOUT2.addItem(self.tr("to listing_r<r>"), 'listing')
# Connections
self.connect(self.toolButton_2, SIGNAL("clicked()"), self.slotDebugHelp)
self.connect(self.lineEdit_3, SIGNAL("textChanged(const QString &)"), self.slotDebug)
self.connect(self.comboBox_6, SIGNAL("activated(const QString&)"), self.slotLogType)
self.connect(self.comboBox_7, SIGNAL("activated(const QString&)"), self.slotLogType)
# Previous values
self.debug = self.parent.mdl.getString('debug')
if self.debug is not None:
self.lineEdit_3.setText(str(self.debug))
self.setLogType()
@pyqtSignature("const QString &")
def slotDebug(self, text):
"""
Input for Debug.
"""
self.debug = str(text)
def setLogType(self):
"""
Set logging arguments.
"""
self.log_type = self.parent.mdl.getLogType()
self.modelCSOUT1.setItem(str_model=self.log_type[0])
self.modelCSOUT2.setItem(str_model=self.log_type[1])
@pyqtSignature("const QString &")
def slotLogType(self, text):
"""
Input logging options.
"""
self.log_type = [self.modelCSOUT1.dicoV2M[str(self.comboBox_6.currentText())],
self.modelCSOUT2.dicoV2M[str(self.comboBox_7.currentText())]]
@pyqtSignature("")
def slotDebugHelp(self):
"""
Show help page for debugging
"""
dialog = BatchRunningDebugOptionsHelpDialogView(self)
dialog.show()
return
def get_result(self):
"""
Method to get the result
"""
return self.result
def accept(self):
"""
Method called when user clicks 'OK'
"""
self.parent.mdl.setString('debug', self.debug.strip())
self.parent.mdl.setLogType(self.log_type)
QDialog.accept(self)
def reject(self):
"""
Method called when user clicks 'Cancel'
"""
QDialog.reject(self)
def tr(self, text):
"""
Translation
"""
return text
#-------------------------------------------------------------------------------
# Popup window class: stop the computation at a iteration
#-------------------------------------------------------------------------------
class BatchRunningStopByIterationDialogView(QDialog, Ui_BatchRunningStopByIterationDialogForm):
"""
Advanced dialog to stop the computation at a given iteration
"""
def __init__(self, parent, default):
"""
Constructor
"""
QDialog.__init__(self, parent)
Ui_BatchRunningStopByIterationDialogForm.__init__(self)
self.setupUi(self)
self.setWindowTitle(self.tr("Stop"))
self.default = default
self.result = self.default.copy()
v = IntValidator(self.lineEditStopIter, min=1)
v.setExclusiveMin(True)
self.lineEditStopIter.setValidator(v)
# Previous values
self.iter = self.default['iter']
self.lineEditStopIter.setText(str(self.iter))
self.connect(self.lineEditStopIter,
SIGNAL("textChanged(const QString &)"),
self.__slotStopIter)
@pyqtSignature("const QString &")
def __slotStopIter(self, text):
"""
Private slot to set an iteration number to stop the code.
"""
if self.sender().validator().state == QValidator.Acceptable:
iter = from_qvariant(text, int)
self.iter = iter
def get_result(self):
"""
Method to get the result
"""
return self.result
def accept(self):
"""
Method called when user clicks 'OK'
"""
self.result['iter'] = self.iter
QDialog.accept(self)
def reject(self):
"""
Method called when user clicks 'Cancel'
"""
QDialog.reject(self)
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
class ListingDialogView(CommandMgrDialogView):
def __init__(self, parent, case, title, cmd):
self.case = case
CommandMgrDialogView.__init__(self, parent, title, cmd, self.case['scripts_path'], self.case['salome'])
self.connect(self.pushButtonStop, SIGNAL('clicked()'), self.__slotStop)
self.connect(self.pushButtonStopAt, SIGNAL('clicked()'), self.__slotStopAt)
self.scratch_dir = ""
self.result_dir = ""
self.suffix = ""
self.listing = "listing"
self.n_lines = 0
self.proc.start(self.cmd)
def slotReadFromStdout(self):
"""
Public slot to handle the readyReadStandardOutput signal of the process.
"""
if self.proc is None:
return
self.proc.setReadChannel(QProcess.StandardOutput)
while self.proc and self.proc.canReadLine():
ba = self.proc.readLine()
if ba.isNull(): return
s = (ba.data()).decode("utf-8")[:-1]
self.logText.append(s)
self.n_lines += 1
# Work and result directories printed in first lines of log.
if self.n_lines < 16:
self.__execDir(s)
def __execDir(self, s):
"""
Private method. Find the directory of the code execution.
"""
# Read directly the run directory from the sdtout of the code.
if "Working directory" in s:
self.scratch_dir = "Working directory"
return
elif self.scratch_dir == "Working directory":
self.scratch_dir = " ".join(str(s).split())
title = os.path.basename(self.scratch_dir)
self.setWindowTitle(title)
self.suffix = title
return
if not self.result_dir:
if "Result directory" in s:
self.result_dir = "Result directory"
elif self.result_dir == "Result directory":
self.result_dir = " ".join(str(s).split())
title = os.path.basename(self.result_dir)
self.setWindowTitle(title)
self.suffix = title
def __stopExec(self, iter, msg):
"""
Private method. Stops the code.
"""
line = "\n" + str(iter) + "\n\n"
if self.scratch_dir:
exec_dir = self.scratch_dir
elif self.result_dir:
exec_dir = self.result_dir
else:
return
fstp = os.path.join(exec_dir, "control_file")
f = open(fstp, 'w')
f.write(line)
f.close()
QMessageBox.warning(self, self.tr("Warning"), msg)
@pyqtSignature("")
def __slotStop(self):
"""
Private slot. Stops the code at the end of the current iteration.
"""
iter = 1
msg = self.tr("Stop at the end of the current iteration.")
self.__stopExec(iter, msg)
@pyqtSignature("")
def __slotStopAt(self):
"""
Private slot. Stops the code at the end of the given iteration.
"""
default = {}
default['iter'] = 100
dlg = BatchRunningStopByIterationDialogView(self, default)
if dlg.exec_():
result = dlg.get_result()
msg = self.tr("Stop at iteration number: %i" % result['iter'])
self.__stopExec(result['iter'], msg)
@pyqtSignature("QProcess::ProcessState")
def slotStateChanged(self, state):
"""
Public slot. Handle the current status of the process.
"""
bool = not(state == QProcess.NotRunning)
self.pushButtonKill.setEnabled(bool)
self.pushButtonStop.setEnabled(bool)
self.pushButtonStopAt.setEnabled(bool)
#-------------------------------------------------------------------------------
# Main class
#-------------------------------------------------------------------------------
class BatchRunningView(QWidget, Ui_BatchRunningForm):
"""
This class is devoted to the Computer selection.
When a new computer is selected, The old data frame is deleted and
a new apropriate frame is open.
If the batch script file name is known, informations are display
in the apropiate widget.
"""
def __init__(self, parent, case):
"""
Constructor
"""
QWidget.__init__(self, parent)
Ui_BatchRunningForm.__init__(self)
self.setupUi(self)
self.case = case
self.parent = parent
self.case.undoStopGlobal()
self.mdl = ScriptRunningModel(self.case)
# Check if the script file name is already defined
if self.case['scripts_path']:
if not self.case['runcase']:
if self.case['package'].runcase in os.listdir(self.case['scripts_path']):
runcase_path = os.path.join(self.case['scripts_path'],
self.case['package'].runcase)
self.case['runcase'] = cs_runcase.runcase(runcase_path,
package=self.case['package'])
# Get MPI and OpenMP features
self.have_mpi = False
self.have_openmp = False
config_features = self.case['package'].config.features
config = configparser.ConfigParser()
config.read(self.case['package'].get_configfiles())
if config.has_option('install', 'compute_versions'):
compute_versions = config.get('install', 'compute_versions').split(':')
if compute_versions[0]:
pkg_compute = self.case['package'].get_alternate_version(compute_versions[0])
config_features = pkg_compute.config.features
if config_features['mpi'] == 'yes':
self.have_mpi = True
if config_features['openmp'] == 'yes':
self.have_openmp = True
self.jmdl = BatchRunningModel(parent, self.case)
# Batch info
self.hideBatchInfo()
self.labelNProcs.hide()
self.spinBoxNProcs.hide()
self.labelNThreads.hide()
self.spinBoxNThreads.hide()
self.class_list = None
if self.jmdl.batch.rm_type != None:
self.groupBoxArchi.setTitle("Job and script files")
self.labelBatch.show()
self.toolButtonSearchBatch.show()
validatorSimpleName = RegExpValidator(self.lineEditJobName,
QRegExp("[_A-Za-z0-9]*"))
validatorAccountName = RegExpValidator(self.lineEditJobAccount,
QRegExp("\\S+"))
self.lineEditJobName.setValidator(validatorSimpleName)
self.lineEditJobAccount.setValidator(validatorAccountName)
self.lineEditJobWCKey.setValidator(validatorAccountName)
self.pushButtonRunSubmit.setText("Submit job")
else:
if self.jmdl.dictValues['run_nprocs'] == None:
try:
# For backwards compatibility
# (this is a specific case, as we move information from
# the XML model to the batch script)
self.jmdl.dictValues['run_nprocs'] = self.mdl.getString('n_procs')
self.mdl.setString('n_procs', None)
except Exception:
pass
# Connections
if self.jmdl.batch.rm_type != None:
self.connect(self.lineEditJobName, SIGNAL("textChanged(const QString &)"),
self.slotJobName)
self.connect(self.spinBoxNodes, SIGNAL("valueChanged(int)"),
self.slotJobNodes)
self.connect(self.spinBoxPpn, SIGNAL("valueChanged(int)"),
self.slotJobPpn)
self.connect(self.spinBoxProcs, SIGNAL("valueChanged(int)"),
self.slotJobProcs)
self.connect(self.spinBoxThreads, SIGNAL("valueChanged(int)"),
self.slotJobThreads)
self.connect(self.spinBoxDays, SIGNAL("valueChanged(int)"),
self.slotJobWallTime)
self.connect(self.spinBoxHours, SIGNAL("valueChanged(int)"),
self.slotJobWallTime)
self.connect(self.spinBoxMinutes, SIGNAL("valueChanged(int)"),
self.slotJobWallTime)
self.connect(self.spinBoxSeconds, SIGNAL("valueChanged(int)"),
self.slotJobWallTime)
self.connect(self.comboBoxClass, SIGNAL("activated(const QString&)"),
self.slotClass)
self.connect(self.lineEditJobAccount, SIGNAL("textChanged(const QString &)"),
self.slotJobAccount)
self.connect(self.lineEditJobWCKey, SIGNAL("textChanged(const QString &)"),
self.slotJobWCKey)
else:
self.connect(self.spinBoxNProcs, SIGNAL("valueChanged(int)"), self.slotNProcs)
self.connect(self.spinBoxNThreads, SIGNAL("valueChanged(int)"), self.slotNThreads)
self.connect(self.toolButtonSearchBatch, SIGNAL("clicked()"), self.slotSearchBatchFile)
self.connect(self.comboBoxRunType, SIGNAL("activated(const QString&)"), self.slotArgRunType)
self.connect(self.toolButtonAdvanced, SIGNAL("clicked()"), self.slotAdvancedOptions)
self.connect(self.pushButtonRunSubmit, SIGNAL("clicked()"), self.slotBatchRunning)
# Combomodels
self.modelArg_cs_verif = ComboModel(self.comboBoxRunType, 2, 1)
self.modelArg_cs_verif.addItem(self.tr("Import mesh only"), 'none')
self.modelArg_cs_verif.addItem(self.tr("Mesh preprocessing"), 'mesh preprocess')
self.modelArg_cs_verif.addItem(self.tr("Mesh quality criteria"), 'mesh quality')
self.modelArg_cs_verif.addItem(self.tr("Standard"), 'standard')
if self.case['prepro'] == False:
self.modelArg_cs_verif.enableItem(3)
else:
self.modelArg_cs_verif.disableItem(3)
self.modelArg_cs_verif.setItem(str_model=self.mdl.getRunType(self.case['prepro']))
# initialize Widgets
# Check if the script file name is already defined
if self.case['runcase']:
name = os.path.basename(self.case['runcase'].path)
self.labelBatchName.setText(str(name))
setGreenColor(self.toolButtonSearchBatch, False)
else:
setGreenColor(self.toolButtonSearchBatch, True)
if self.jmdl.batch.rm_type != None and self.case['runcase']:
self.displayBatchInfo()
# Script info is based on the XML model
self.displayScriptInfo()
self.case.undoStartGlobal()
@pyqtSignature("const QString &")
def slotJobName(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
if self.lineEditJobName.validator().state == QValidator.Acceptable:
self.jmdl.batch.params['job_name'] = str(v)
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_name')
@pyqtSignature("int")
def slotJobNodes(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
self.jmdl.batch.params['job_nodes'] = str(self.spinBoxNodes.text())
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_nodes')
@pyqtSignature("int")
def slotJobPpn(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
self.jmdl.batch.params['job_ppn'] = str(self.spinBoxPpn.text())
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_ppn')
@pyqtSignature("int")
def slotJobProcs(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
self.jmdl.batch.params['job_procs'] = str(self.spinBoxProcs.text())
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_procs')
@pyqtSignature("int")
def slotJobThreads(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
self.jmdl.batch.params['job_threads'] = str(self.spinBoxThreads.text())
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_threads')
@pyqtSignature("")
def slotJobWallTime(self):
h_cput = self.spinBoxDays.value()*24 + self.spinBoxHours.value()
m_cput = self.spinBoxMinutes.value()
s_cput = self.spinBoxSeconds.value()
self.jmdl.batch.params['job_walltime'] = h_cput*3600 + m_cput*60 + s_cput
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_walltime')
@pyqtSignature("")
def slotClass(self):
self.jmdl.batch.params['job_class'] = str(self.comboBoxClass.currentText())
if len(self.jmdl.batch.params['job_class']) > 0:
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_class')
@pyqtSignature("const QString &")
def slotJobAccount(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
if self.lineEditJobAccount.validator().state == QValidator.Acceptable:
self.jmdl.batch.params['job_account'] = str(v)
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_account')
@pyqtSignature("const QString &")
def slotJobWCKey(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
if self.lineEditJobWCKey.validator().state == QValidator.Acceptable:
self.jmdl.batch.params['job_wckey'] = str(v)
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_wckey')
@pyqtSignature("const QString &")
def slotArgRunType(self, text):
"""
Input run type option.
"""
run_type = self.modelArg_cs_verif.dicoV2M[str(text)]
self.mdl.setRunType(run_type)
@pyqtSignature("int")
def slotNProcs(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
if v > 1:
self.jmdl.dictValues['run_nprocs'] = str(v)
else:
self.jmdl.dictValues['run_nprocs'] = None
self.jmdl.updateBatchFile('run_nprocs')
@pyqtSignature("int")
def slotNThreads(self, v):
"""
Increment, decrement and colorize the input argument entry
"""
if v > 1:
self.jmdl.dictValues['run_nthreads'] = str(v)
else:
self.jmdl.dictValues['run_nthreads'] = None
self.jmdl.updateBatchFile('run_nthreads')
@pyqtSignature("")
def slotAdvancedOptions(self):
"""
Ask one popup for advanced specifications
"""
log.debug("slotAdvancedOptions")
dialog = BatchRunningAdvancedOptionsDialogView(self)
if dialog.exec_():
log.debug("slotAdvancedOptions validated")
@pyqtSignature("")
def slotBatchRunning(self):
"""
Launch Code_Saturne batch running.
"""
# Is the file saved?
if self.case['new'] == "yes" or len(self.case['undo']) > 0 or len(self.case['redo']) > 0:
title = self.tr("Warning")
msg = self.tr("The current case must be saved before "\
"running the ") + self.tr(self.case['package']).code_name + self.tr(" script.")
QMessageBox.information(self, title, msg)
return
# Ensure code is run from a case subdirectory
prv_dir = os.getcwd()
os.chdir(self.case['scripts_path'])
# Do we have a mesh ?
have_mesh = False
node_ecs = self.case.xmlGetNode('solution_domain')
if node_ecs.xmlGetNode('meshes_list'):
if node_ecs.xmlGetNode('meshes_list').xmlGetNodeList('mesh'):
have_mesh = True
if node_ecs.xmlGetNode('mesh_input', 'path'):
have_mesh = True
if not have_mesh:
title = self.tr("Warning")
msg = self.tr("You have to select a mesh.\n\n")
QMessageBox.information(self, title, msg)
return
# Verify if boundary condition definitions exist
if self.case['prepro'] == False:
bd = LocalizationModel('BoundaryZone', self.case)
if not bd.getZones():
if self.case['no_boundary_conditions'] == False:
title = self.tr("Warning")
msg = self.tr("No boundary definition declared.\n\n")
QMessageBox.warning(self, title, msg)
self.case['no_boundary_conditions'] = True
# Build command line
rm_type = self.jmdl.batch.rm_type
batch = self.case['runcase'].path
cmd = None
run_title = None
if rm_type == None:
run_id, run_title = self.__suggest_run_id()
self.__updateRuncase(run_id)
cmd = batch
else:
run_title = self.case['package'].code_name + ' - Job Submission'
cmd = cs_exec_environment.enquote_arg(sys.argv[0]) \
+ ' submit ' + cs_exec_environment.enquote_arg(batch)
dlg = ListingDialogView(self.parent, self.case, run_title, cmd)
dlg.show()
if rm_type == None:
self.__updateRuncase('') # remove --id <id> from runcase
os.chdir(prv_dir)
def __suggest_run_id(self):
"""
Return an id.
"""
cmd = os.path.join(self.case['package'].get_dir('bindir'),
self.case['package'].name)
cmd = cs_exec_environment.enquote_arg(cmd) + " run --suggest-id"
if self.mdl.getRunType() != "standard":
cmd += " --id-prefix=preprocess"
r_title = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True).stdout.read()[:-1]
r_id = os.path.join(self.case['resu_path'], r_title)
run_id = r_id
run_title = r_title
return os.path.basename(run_id), run_title
def __updateRuncase(self, run_id):
"""
Update the command line in the launcher C{runcase}.
"""
runcase = self.case['runcase']
runcase.set_run_id(run_id=run_id)
runcase.save()
def hideBatchInfo(self):
"""
hide all batch info before displaying a selected subset
"""
self.groupBoxJob.hide()
self.labelJobName.hide()
self.lineEditJobName.hide()
self.labelNodes.hide()
self.spinBoxNodes.hide()
self.labelPpn.hide()
self.spinBoxPpn.hide()
self.labelProcs.hide()
self.spinBoxProcs.hide()
self.labelThreads.hide()
self.spinBoxThreads.hide()
self.labelClass.hide()
self.labelWTime.hide()
self.spinBoxDays.hide()
self.labelDays.hide()
self.spinBoxHours.hide()
self.labelHours.hide()
self.spinBoxMinutes.hide()
self.labelMinutes.hide()
self.spinBoxSeconds.hide()
self.labelSeconds.hide()
self.comboBoxClass.hide()
self.labelJobAccount.hide()
self.lineEditJobAccount.hide()
self.labelJobWCKey.hide()
self.lineEditJobWCKey.hide()
def displayBatchInfo(self):
"""
Layout of the second part of this page.
"""
self.job_name = self.jmdl.batch.params['job_name']
self.job_nodes = self.jmdl.batch.params['job_nodes']
self.job_ppn = self.jmdl.batch.params['job_ppn']
self.job_procs = self.jmdl.batch.params['job_procs']
self.job_threads = self.jmdl.batch.params['job_threads']
self.job_walltime = self.jmdl.batch.params['job_walltime']
self.job_class = self.jmdl.batch.params['job_class']
self.job_account = self.jmdl.batch.params['job_account']
self.job_wckey = self.jmdl.batch.params['job_wckey']
if self.job_name != None:
self.labelJobName.show()
self.lineEditJobName.setText(str(self.job_name))
self.lineEditJobName.show()
if self.job_nodes != None:
self.labelNodes.show()
self.spinBoxNodes.setValue(int(self.job_nodes))
self.spinBoxNodes.show()
if self.job_ppn != None:
self.labelPpn.show()
self.spinBoxPpn.setValue(int(self.job_ppn))
self.spinBoxPpn.show()
if self.job_procs != None:
self.labelProcs.show()
self.spinBoxProcs.setValue(int(self.job_procs))
self.spinBoxProcs.show()
if self.job_threads != None:
self.labelThreads.show()
self.spinBoxThreads.setValue(int(self.job_threads))
self.spinBoxThreads.show()
if self.job_walltime != None:
seconds = self.job_walltime
minutes = seconds / 60
hours = minutes / 60
days = hours / 24
seconds = seconds % 60
minutes = minutes % 60
hours = hours % 24
self.spinBoxDays.setValue(days)
self.spinBoxHours.setValue(hours)
self.spinBoxMinutes.setValue(minutes)
self.spinBoxSeconds.setValue(seconds)
self.labelWTime.show()
self.spinBoxDays.show()
self.labelDays.show()
self.spinBoxHours.show()
self.labelHours.show()
self.spinBoxMinutes.show()
self.labelMinutes.show()
self.spinBoxSeconds.show()
self.labelSeconds.show()
if self.job_class != None:
# Only one pass here
if self.class_list == None:
self.class_list = self.jmdl.batch.get_class_list()
if len(self.class_list) > 0:
for c in self.class_list:
self.comboBoxClass.addItem(self.tr(c), to_qvariant(c))
else:
c = self.job_class
self.comboBoxClass.addItem(self.tr(c), to_qvariant(c))
# All passes
try:
index = self.class_list.index(self.job_class)
self.comboBoxClass.setCurrentIndex(index)
except Exception:
if len(self.class_list) > 0:
self.job_class = self.class_list[0]
self.labelClass.show()
self.comboBoxClass.show()
# update runcase (compute class specific to ivanoe)
self.jmdl.batch.params['job_class'] = str(self.comboBoxClass.currentText())
if len(self.jmdl.batch.params['job_class']) > 0:
self.jmdl.batch.update_lines(self.case['runcase'].lines, 'job_class')
if self.job_account != None:
self.labelJobAccount.show()
self.lineEditJobAccount.setText(str(self.job_account))
self.lineEditJobAccount.show()
if self.job_wckey != None:
self.labelJobWCKey.show()
self.lineEditJobWCKey.setText(str(self.job_wckey))
self.lineEditJobWCKey.show()
# Show Job management box
if self.jmdl.batch.rm_type == 'LOADL':
self.groupBoxJob.setTitle("Load Leveler job parameters")
self.labelJobAccount.setText(str("Group"))
self.lineEditJobAccount.setToolTip("To obtain a list of defined groups, run <b><tt>xloadl</tt></b>, then select <i>File -> Build a Job</i>, and check the group names in the <i>Group</i> field")
elif self.jmdl.batch.rm_type == 'LSF':
self.groupBoxJob.setTitle("LSF job parameters")
elif self.jmdl.batch.rm_type == 'PBS':
self.groupBoxJob.setTitle("PBS job parameters")
elif self.jmdl.batch.rm_type == 'SGE':
self.groupBoxJob.setTitle("Sun Grid Engine job parameters")
if self.jmdl.batch.rm_type == 'SLURM':
self.groupBoxJob.setTitle("SLURM job parameters")
else:
self.groupBoxJob.setTitle("Batch job parameters")
self.groupBoxJob.show()
# Update file
self.jmdl.batch.update_lines(self.case['runcase'].lines)
def displayScriptInfo(self):
"""
Layout of the second part of this page.
"""
if self.case['batch_type'] == None:
if self.have_mpi:
self.labelNProcs.show()
self.spinBoxNProcs.show()
if self.have_openmp:
self.labelNThreads.show()
self.spinBoxNThreads.show()
else:
self.labelNProcs.hide()
self.spinBoxNProcs.hide()
self.labelNThreads.hide()
self.spinBoxNThreads.hide()
if self.case['batch_type'] == None:
if self.have_mpi:
n_procs_s = self.jmdl.dictValues['run_nprocs']
if n_procs_s:
n_procs = int(n_procs_s)
else:
n_procs = 1
self.spinBoxNProcs.setValue(n_procs)
if self.have_openmp == 'yes':
n_threads_s = self.jmdl.dictValues['run_nthreads']
if n_threads_s:
n_threads = int(n_threads_s)
else:
n_threads = 1
self.spinBoxNThreads.setValue(n_threads)
else:
pass
@pyqtSignature("")
def slotSearchBatchFile(self):
"""
Open a FileDialog in order to search the batch command file
in the system file.
"""
file_name = ""
if self.case['scripts_path'] and os.path.isdir(self.case['scripts_path']):
path = self.case['scripts_path']
else:
path = os.getcwd()
title = self.tr("Select the batch script")
filetypes = self.tr("All Files (*)")
file_name = QFileDialog.getOpenFileName(self, title, path, filetypes)
file_name = str(file_name)
if file_name:
launcher = os.path.basename(file_name)
setGreenColor(self.toolButtonSearchBatch, False)
if self.case['scripts_path'] == os.path.dirname(file_name):
self.case['runcase'] = cs_runcase.runcase(os.path.join(self.case['scripts_path'],
launcher),
package=self.case['package'])
self.labelBatchName.setText(str(launcher))
self.hideBatchInfo()
if self.jmdl.batch.rm_type != None:
self.displayBatchInfo()
else:
title = self.tr("Warning")
msg = self.tr("The new batch file is not in scripts "\
"directory given in the 'Identity and paths' "\
"section.\n\n" + \
"Verify the existence and location of these files, "\
"and the 'Identity and Pathes' section")
QMessageBox.warning(self, title, msg)
def tr(self, text):
"""
Translation
"""
return text
#-------------------------------------------------------------------------------
# Testing part
#-------------------------------------------------------------------------------
if __name__ == "__main__":
pass
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|