Skip to content

Commit

Permalink
Merge branch 'master' into 5911-sirepo-resource-render-file
Browse files Browse the repository at this point in the history
  • Loading branch information
git-user committed Jul 13, 2023
2 parents 7eb1b49 + 51e4418 commit a4d2a35
Show file tree
Hide file tree
Showing 31 changed files with 769 additions and 532 deletions.
36 changes: 35 additions & 1 deletion sirepo/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from pykern import pkio
from pykern import pksubprocess
from pykern.pkdebug import pkdc, pkdexc, pkdp, pkdlog
import sirepo.const
import multiprocessing
import re
import sirepo.const
import sys

FIRST_RANK = 0
Expand Down Expand Up @@ -43,6 +44,9 @@ def restrict_op_to_first_rank(op):
Args:
op (function): function to call
Returns:
object: result of `op`
"""
c = None
r = FIRST_RANK
Expand All @@ -69,6 +73,31 @@ def restrict_op_to_first_rank(op):
return res


def restrict_ops_to_first_node(ops):
"""Run `ops` in parallel on available cores on the first node
This functions uses `multiprocessing` to run `ops`. If run under
MPI, will run instantiate the multiprocessing.Pool in the first
rank only, and the other MPI ranks (processes) will remain idle
until all `ops` have been run.
Note that processes originate from the first rank MPI process so
they share the first rank's memory up until multiprocessing spawns
each op.
Args:
ops (iterable): produces callables that will be run in parallel
"""

def _run():
# TODO(robnagler): if run on multiple machines, cores need to be tasks_per_node
with multiprocessing.Pool(_cfg.cores) as p:
p.map(_globalize_op, ops)

restrict_op_to_first_rank(_run)


def run_program(cmd, output=sirepo.const.MPI_LOG, env=None):
"""Execute python script with mpi.
Expand Down Expand Up @@ -99,6 +128,11 @@ def run_script(script):
run_program([sys.executable or "python", fn])


def _globalize_op(op):
"""Runs `op` in global namespace for multiprocessing"""
return op()


def _mpiexec_cmd():
return [
"mpiexec",
Expand Down
19 changes: 9 additions & 10 deletions sirepo/package_data/static/html/vtk-display.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
<div class="sr-plot-legend plot-visibility">
<div class="row">
<div class="col-sm-12">
<div style="padding-top: 5px; padding-bottom: 8px"><span>{{ modeText[vtkScene.interactionMode] }}</span><span data-text-with-math="selection.info || ''" data-is-dynamic="true" data-ng-show="enableSelection" class="pull-right"></span></div>
<div data-ng-show="enableSelection" data-toggle="tooltip" title="Select" class="btn btn-default" data-ng-class="{'btn-primary': vtkScene.interactionMode == VTKUtils.interactionMode().INTERACTION_MODE_SELECT}" style="margin: 2px;" data-ng-click="setInteractionMode(VTKUtils.interactionMode().INTERACTION_MODE_SELECT)">&#x2B09;</div>
<div data-ng-show="enableSelection" data-toggle="tooltip" title="Manipulate" class="btn btn-default" data-ng-class="{'btn-primary': vtkScene.interactionMode == VTKUtils.interactionMode().INTERACTION_MODE_MOVE}" style="margin: 2px;" data-ng-click="setInteractionMode(VTKUtils.interactionMode().INTERACTION_MODE_MOVE)"><span class="glyphicon glyphicon-hand-up"></span></div>
<div data-ng-repeat="dim in GeometryUtils.BASIS()" data-toggle="tooltip" title="View along {{ dim }} axis" class="btn btn-default" data-ng-class="{'btn-primary': vtkScene.viewSide == '{{dim}}'}" style="margin: 2px;" data-ng-click="showSide(dim)">{{ dim }}{{ vtkScene.directionIcon() }}</div>
<div data-ng-repeat="r in [-90, -45]" data-toggle="tooltip" title="Rotate {{ r }}º" class="btn btn-default" data-ng-click="rotate(r)" ><span>{{ r }}º</span></div>
<div data-toggle="tooltip" title="Reset" class="btn btn-default" data-ng-click="showSide(vtkScene.viewSide)">Reset</div>
<div data-ng-repeat="r in [45, 90]" data-toggle="tooltip" title="Rotate {{ r }}º" class="btn btn-default" data-ng-click="rotate(r)" ><span>{{ r }}º</span></div>
<div class="checkbox checkbox-inline"><label data-ng-if="vtkScene.hasMarker()"><input type="checkbox" id="sr-toggle-marker" data-ng-model="vtkScene.isMarkerEnabled" data-ng-change="vtkScene.refreshMarker()"> Toggle Marker</label></div>
<div data-toggle="tooltip" title="Toggle between perspective and orthographic view" class="btn btn-default pull-right" style="margin: 2px;" data-ng-click="toggleOrtho()"><span data-ng-show="! isOrtho"><ng-include src="'/static/svg/perspective.svg'"></ng-include></span><span data-ng-show="isOrtho"><ng-include src="'/static/svg/ortho.svg'"></span></div>
<div data-ng-if="enableSelection && selection.model" data-advanced-editor-pane="" data-view-name="selection.model.modelKey" data-model-data="selection.model" data-want-buttons="true"></div>
<div style="padding-top: 5px; padding-bottom: 8px"><span>Click and drag to rotate. Control-click an object to select. Double-click to reset camera</span><span data-text-with-math="selection.info || ''" data-is-dynamic="true" data-ng-show="enableSelection" class="pull-right"></span></div>
<div data-ng-repeat="dim in GeometryUtils.BASIS()" data-toggle="tooltip" title="View along {{ dim }} axis" class="btn btn-default" data-ng-class="{'btn-primary': vtkScene.viewSide == '{{ dim }}'}" style="margin: 2px; width: 3em;" data-ng-click="showSide(dim)">{{ dim }}{{ vtkScene.directionIcon() }}</div>
<div style="display: inline-block; margin-left: 4px; margin-right: 4px;">
<div data-toggle="tooltip" title="Rotate 45º clockwise" class="btn btn-default" data-ng-click="rotate(-45)"><span class="glyphicon glyphicon-repeat"></span></div>
<div data-toggle="tooltip" title="Reset camera" class="btn btn-default" data-ng-click="showSide(vtkScene.viewSide)"><span class="glyphicon glyphicon-record"></span></div>
<div data-toggle="tooltip" title="Rotate 45º counter clockwise" class="btn btn-default" data-ng-click="rotate(45)"><span class="glyphicon glyphicon-repeat" style="margin: 2px; transform: scaleX(-1);"></span></div>
</div>
<div data-toggle="tooltip" title="Change to {{ isOrtho ? 'perspective' : 'orthographic' }} view" class="btn btn-default" style="margin: 2px;" data-ng-click="toggleOrtho()"><span data-ng-show="! isOrtho"><img alt="perspective" src="/static/svg/perspective.svg"></span><span data-ng-show="isOrtho"><img alt="orthogonal" src="/static/svg/ortho.svg"></span></div>
<div data-ng-if="selection.model" data-advanced-editor-pane="" data-view-name="selection.model.modelKey" data-model-data="selection.model" data-want-buttons="true"></div>
</div>
</div>
</div>
Expand Down
17 changes: 13 additions & 4 deletions sirepo/package_data/static/js/cloudmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, frameCache
new SIREPO.GEOMETRY.SquareMatrix([[scale, 0, 0], [0, scale, 0], [0, 0, scale]])
)
);
const watchFields = [`${$scope.modelName}.bgColor`, `${$scope.modelName}.showEdges`];
const watchFields = [
`${$scope.modelName}.bgColor`,
`${$scope.modelName}.showEdges`,
`${$scope.modelName}.showMarker`
];
const clientOnlyFields = ['voxels.colorMap'].concat(watchFields);
const voxelPoly = [
[0, 1, 2, 3],
Expand Down Expand Up @@ -653,9 +657,7 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, frameCache
}

// regular clicks are generated when spinning the scene - we'll select/deselect with ctrl-click
if (vtkScene.interactionMode === SIREPO.VTK.VTKUtils.interactionMode().INTERACTION_MODE_MOVE ||
(vtkScene.interactionMode === SIREPO.VTK.VTKUtils.interactionMode().INTERACTION_MODE_SELECT && ! callData.controlKey)
) {
if (! callData.controlKey) {
return;
}

Expand Down Expand Up @@ -768,6 +770,7 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, frameCache
return;
}
vtkScene.setBgColor(model().bgColor);
updateMarker();
for (const volId in bundleByVolume) {
const b = bundleByVolume[volId];
const v = getVolumeById(volId);
Expand Down Expand Up @@ -880,6 +883,11 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, frameCache
}
}

function updateMarker() {
vtkScene.isMarkerEnabled = model().showMarker === '1';
vtkScene.refreshMarker();
}

function updateSlice() {
buildTallyReport();
appState.saveQuietly('tallyReport');
Expand Down Expand Up @@ -1008,6 +1016,7 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, frameCache
vtk.Interaction.Widgets.vtkOrientationMarkerWidget.Corners.TOP_RIGHT
)
);
updateMarker();

picker = vtk.Rendering.Core.vtkCellPicker.newInstance();
picker.setPickFromList(true);
Expand Down
2 changes: 1 addition & 1 deletion sirepo/package_data/static/js/omega.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ SIREPO.app.controller('SourceController', function (appState, frameCache, persis
self.simHandleStatus = data => {
errorMessage = data.error;
frameCache.setFrameCount(data.frameCount || 0);
self.reports = data.reports;
if (data.reports) {
self.reports = data.reports;
for (const r of data.reports) {
frameCache.setFrameCount(r.modelName, r.frameCount);
}
Expand Down
39 changes: 20 additions & 19 deletions sirepo/package_data/static/js/radia.js
Original file line number Diff line number Diff line change
Expand Up @@ -2142,8 +2142,14 @@ SIREPO.app.directive('radiaViewer', function(appState, errorService, frameCache,
continue;
}
const isPoly = t === SIREPO.APP_SCHEMA.constants.geomTypePolys;
const isLine = t === SIREPO.APP_SCHEMA.constants.geomTypeLines;
let gObj = radiaService.getObject(objId) || {};
let gColor = gObj.color ? vtk.Common.Core.vtkMath.hex2float(gObj.color) : null;
// use black for edges
//TODO(mvk): possibly use high contrast so dark objects have white edges
if (gColor && isLine) {
gColor = [0, 0, 0];
}
// use colors from Radia for groups
if (gObj.members) {
gColor = null;
Expand Down Expand Up @@ -2383,10 +2389,7 @@ SIREPO.app.directive('radiaViewer', function(appState, errorService, frameCache,
}

// regular clicks are generated when spinning the scene - we'll select/deselect with ctrl-click
const iMode = $scope.vtkScene.interactionMode;
if (iMode === vtkUtils.INTERACTION_MODE_MOVE ||
(iMode === vtkUtils.INTERACTION_MODE_SELECT && ! callData.controlKey)
) {
if (! callData.controlKey) {
return;
}

Expand Down Expand Up @@ -2714,6 +2717,11 @@ SIREPO.app.directive('radiaViewer', function(appState, errorService, frameCache,
});
}

function updateMarker() {
$scope.vtkScene.isMarkerEnabled = appState.models.magnetDisplay.showMarker === '1';
$scope.vtkScene.refreshMarker();
}

function updateViewer(doShowLoader=false) {
const c = didDisplayValsChange();
sceneData = {};
Expand All @@ -2736,6 +2744,7 @@ SIREPO.app.directive('radiaViewer', function(appState, errorService, frameCache,
$scope.model = appState.models[$scope.modelName];
appState.watchModelFields($scope, watchFields, updateLayout);
appState.watchModelFields($scope, ['magnetDisplay.bgColor'], setBgColor);
appState.watchModelFields($scope, ['magnetDisplay.showMarker'], updateMarker);
panelState.enableField('geometryReport', 'name', ! appState.models.simulation.isExample);
});

Expand All @@ -2752,20 +2761,6 @@ SIREPO.app.directive('radiaViewer', function(appState, errorService, frameCache,
plotToPNG.initVTK($element, $scope.vtkScene.renderer);
});

$scope.$on('vtkScene.interactionMode', (e, d) => {
if (d === SIREPO.VTK.VTKUtils.interactionMode().INTERACTION_MODE_MOVE) {
if (selectedObj) {
$scope.$broadcast('vtk.selected', null);
setEdgeColor(
getActorInfo(selectedObj.id),
[0, 0, 0]
);
selectedObj = null;
savedObj = null;
}
}
});

$scope.$on('radiaObject.changed', function(e) {
radiaService.saveGeometry(true, false);
});
Expand Down Expand Up @@ -3180,7 +3175,7 @@ SIREPO.viewLogic('geomObjectView', function(appState, panelState, radiaService,

$scope.watchFields = [
[
'geomObject.type', 'geomObject.segmentation', 'geomObject.segmentationCylUseObjectCenter',
'geomObject.type', 'geomObject.segmentation', 'geomObject.segmentationCylUseObjectCenter', 'geomObject.segmentationCylAxis',
'cylinder.radius',
'extrudedPoly.extrusionAxisSegments', 'extrudedPoly.triangulationLevel',
'extrudedObject.extrusionAxis',
Expand Down Expand Up @@ -3321,12 +3316,18 @@ SIREPO.viewLogic('geomObjectView', function(appState, panelState, radiaService,
'segmentationCylAxis',
'segmentationCylPoint',
'segmentationCylRadius',
'segmentationCylRatio',
'segmentationCylUseObjectCenter',
];
segCylFields.forEach(f => {
panelState.showField('geomObject', f, isSegCyl);
});
panelState.showArrayField('geomObject', 'segments', 0, ! isSegCyl);
[
appState.models.geomObject.segmentationCylAxisMinor,
appState.models.geomObject.segmentationCylAxisMajor,
] = SIREPO.GEOMETRY.GeometryUtils.nextAxes(appState.models.geomObject.segmentationCylAxis);


if (o.segmentationCylUseObjectCenter === '1') {
o.segmentationCylPoint = o.center.slice();
Expand Down
23 changes: 22 additions & 1 deletion sirepo/package_data/static/js/raydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ SIREPO.app.directive('dateTimePicker', function() {
$scope.model[$scope.field] = timeService.unixTime(newTime);
}
});

$scope.$watch('model.' + $scope.field, function(newTime, oldTime) {
if (newTime !== oldTime) {
$scope.dateTime = timeService.unixTimeToDate(newTime);
}
});
}
};
});
Expand Down Expand Up @@ -402,7 +408,7 @@ SIREPO.app.directive('scansTable', function() {
</div>
<div data-view-log-iframe-wrapper data-scan-id="runLogScanId" data-modal-id="runLogModalId" data-show-log="showLog"></div>
`,
controller: function(appState, errorService, panelState, raydataService, requestSender, $scope, $interval) {
controller: function(appState, errorService, panelState, raydataService, requestSender, timeService, $scope, $interval) {
$scope.analysisModalId = 'sr-analysis-output-' + $scope.analysisStatus;
$scope.availableColumns = [];
$scope.awaitingScans = false;
Expand Down Expand Up @@ -624,6 +630,20 @@ SIREPO.app.directive('scansTable', function() {
];
};

$scope.setDefaultStartStopTime = () => {
const m = appState.models[$scope.modelName];
if (!m.searchStartTime && !m.searchStopTime) {
$scope.setSearchTimeLastHour();
appState.saveChanges($scope.modelName);
}
};

$scope.setSearchTimeLastHour = () => {
const m = appState.models[$scope.modelName];
m.searchStartTime = timeService.roundUnixTimeToMinutes(timeService.unixTimeOneHourAgo());
m.searchStopTime = timeService.roundUnixTimeToMinutes(timeService.unixTimeNow());
};

$scope.setSelectedScan = (scan) => {
$scope.selectedScan = scan;
if ($scope.selectedScan !== null && ! [raydataService.ANALYSIS_STATUS_NONE, raydataService.ANALYSIS_STATUS_PENDING].includes($scope.selectedScan.status)) {
Expand Down Expand Up @@ -682,6 +702,7 @@ SIREPO.app.directive('scansTable', function() {
}
};

$scope.setDefaultStartStopTime();
$scope.$on(`${$scope.modelName}.changed`, sendScanRequest);
$scope.$on('catalog.changed', sendScanRequest);
$scope.$watchCollection('appState.models.metadataColumns.selected', (newValue, previousValue) => {
Expand Down
Loading

0 comments on commit a4d2a35

Please sign in to comment.