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

Sync with main #1829

Merged
merged 12 commits into from
Jan 30, 2025
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
5 changes: 3 additions & 2 deletions cmake/support/run-scripts/labenv.bat.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ SET EXT=%%~xi

@IF "%EXT%"==".instr" (
@FLAVOR@-pygen %INSTRUMENT%
SET INSTRUMENT="%BASE%_generated.py"
goto :JupyText
sed s/INSTRUMENT/%BASE%/g %BINDIR%\@MCCODE_RELPATH_BINDIR2TOOLDIR@\Python\@MCCODE_PREFIX@run\template.ipynb.in > %BASE%_generated.ipynb
SET INSTRUMENT="%BASE%_generated.ipynb"
goto :JupyLaunch
) ELSE IF "%EXT%"==".py" (
goto :JupyLaunch
) ELSE IF "%EXT%"==".ipynb" (
Expand Down
2 changes: 1 addition & 1 deletion mcstas-comps/optics/Elliptic_guide_gravity.comp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ SETTING PARAMETERS (xwidth = 0,yheight = 0,l,
string verbose = "on",
enableGravity = 1.0,
curvature=0,
nSegments=-1,
int nSegments=-1,
vector mvaluesright=NULL, vector mvaluesleft=NULL, vector mvaluestop=NULL, vector mvaluesbottom=NULL,
vector seglength=NULL)

Expand Down
4 changes: 2 additions & 2 deletions mcstas-comps/optics/Pol_mirror.comp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ INITIALIZE
if (strlen(rUpData) && strcmp(rUpData,"NULL")){
if (Table_Read(&rUpTable, rUpData, 1) <= 0) {
fprintf(stderr,"Pol_mirror: %s: can not read file %s\n",
NAME_CURRENT_COMP, rUpPar);
NAME_CURRENT_COMP, rUpData);
exit(1);
}
rUpTableFlag=1;
Expand All @@ -121,7 +121,7 @@ INITIALIZE
if (strlen(rUpData) && strcmp(rUpData,"NULL")){
if (Table_Read(&rDownTable, rDownData, 1) <= 0) {
fprintf(stderr,"Pol_mirror: %s: can not read file %s\n",
NAME_CURRENT_COMP, rDownPar);
NAME_CURRENT_COMP, rDownData);
exit(1);
}
rDownTableFlag=1;
Expand Down
189 changes: 98 additions & 91 deletions mcstas/src/pygen.c.in

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions meta-pkgs/windows/McStas-metapackage64.iss
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Source: "dist\mcstas-tools-python-mcdisplay-pyqtgraph-NSIS64-@[email protected]
Source: "dist\mcstas-tools-python-mcdisplay-matplotlib-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "dist\mcstas-tools-python-mcdisplay-mantid-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "dist\mcstas-tools-python-mcdoc-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "dist\mcstas-mcpl-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "Support\Miniforge3-Windows-x86_64.exe"; DestDir: "{tmp}"

[Run]
Expand All @@ -76,7 +75,6 @@ Filename: "{tmp}\mcstas-tools-python-mcdisplay-pyqtgraph-NSIS64-@VERSION@-mingw6
Filename: "{tmp}\mcstas-tools-python-mcdisplay-matplotlib-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\mcstas-tools-python-mcdisplay-mantid-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\mcstas-tools-python-mcdoc-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\mcstas-mcpl-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\docupdate.bat";

; NOTE: Don't use "Flags: ignoreversion" on any shared system files
2 changes: 0 additions & 2 deletions meta-pkgs/windows/McXtrace-metapackage64.iss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Source: "dist\mcxtrace-tools-python-mxdisplay-webgl-NSIS64-@[email protected]
Source: "dist\mcxtrace-tools-python-mxdisplay-pyqtgraph-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "dist\mcxtrace-tools-python-mxdisplay-matplotlib-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "dist\mcxtrace-tools-python-mxdoc-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "dist\mcxtrace-mcpl-NSIS64-@[email protected]"; DestDir: "{tmp}"
Source: "Support\Miniforge3-Windows-x86_64.exe"; DestDir: "{tmp}"

[Run]
Expand All @@ -66,7 +65,6 @@ Filename: "{tmp}\mcxtrace-tools-python-mxdisplay-webgl-NSIS64-@VERSION@-mingw64.
Filename: "{tmp}\mcxtrace-tools-python-mxdisplay-pyqtgraph-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\mcxtrace-tools-python-mxdisplay-matplotlib-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\mcxtrace-tools-python-mxdoc-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\mcxtrace-mcpl-NSIS64-@[email protected]"; Parameters: "/S"
Filename: "{tmp}\docupdate.bat";

; NOTE: Don't use "Flags: ignoreversion" on any shared system files
2 changes: 2 additions & 0 deletions meta-pkgs/windows/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ channels:

dependencies:
- m2-msys2-runtime
- m2-which
- m2-sed
- m2w64-gcc
- m2w64-gsl
- msmpi
Expand Down
6 changes: 3 additions & 3 deletions tools/Python/mcrun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ set(CPACK_NSIS_DISPLAY_NAME "${NSIS_NAME}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${NSIS_NAME}")

# Debian
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${FLAVOR}, python3-yaml")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${FLAVOR}, python3-yaml, python3-numpy")
set(CPACK_DEBIAN_PACKAGE_REPLACES "${FLAVOR}-tools-python-${P}run-3.5.1")

# RPM
Expand Down Expand Up @@ -90,8 +90,8 @@ install(
RENAME "${P}run.py"
)

# Other .py infrastructure
foreach(NAME "__init__.py" "log.py" "mccode.py" "optimisation.py" "mcsplit.py")
# Copy in place .py and other infrastructure
foreach(NAME "__init__.py" "log.py" "mccode.py" "optimisation.py" "mcsplit.py" "template.ipynb.in")
install(
FILES "${PROJECT_SOURCE_DIR}/${NAME}"
DESTINATION "${DEST_TOOLDIR}/${TOOLS_NAME}"
Expand Down
3 changes: 1 addition & 2 deletions tools/Python/mcrun/jupylab.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ canrun() {
if ( canrun ); then
INSTR=$1 # We can actually assume a single input here
BASE=`basename ${INSTR} .instr`
PYINSTR="${BASE}_generated.py"
JUPYBK="${BASE}_generated.ipynb"
@FLAVOR@-pygen ${INSTR}
jupytext --to ipynb ${PYINSTR}
sed s/INSTRUMENT/${BASE}/g ${UTILDIR}/template.ipynb.in > ${JUPYBK}
jupyter lab ${JUPYBK}
else
@FLAVOR@_errmsg Failed to run Python ${TOOL} - permissions or missing dependencies\?
Expand Down
159 changes: 159 additions & 0 deletions tools/Python/mcrun/template.ipynb.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import mcstasscript as ms\n",
"from INSTRUMENT_generated import make"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"instr=make()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Use instr.settings() to add e.g. seed=1000, ncount=1e7, mpi=8, openacc=True, force_compile=False etc.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Show diagram\n",
"instr.show_diagram()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Visualise with default parameters (defaults to 'window'/pyqtgraph visualisation)\n",
"instr.show_instrument(format='window')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Generate a dataset with default parameters.\n",
"data = instr.backengine()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Overview plot:\n",
"ms.make_sub_plot(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Other useful commands follow...\n",
"# One plot pr. window\n",
"#ms.make_plot(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load another dataset\n",
"#data2 = ms.load_data('some_other_folder')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Adjusting a specific plot\n",
"#ms.name_plot_options(\\\"PSD_4PI\\\", data, log=1, colormap=\\\"hot\\\", orders_of_mag=5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Bring up the 'interface' - only relevant in Jupyter\n",
"#%matplotlib widget\n",
"#import mcstasscript.jb_interface as ms_widget\n",
"#ms_widget.show(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Bring up the simulation 'interface' - only relevant in Jupyter\n",
"#%matplotlib widget\n",
"#import mcstasscript.jb_interface as ms_widget\n",
"#sim_widget = ms_widget.SimInterface(instr)\n",
"#sim_widget.show_interface()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Acessing data from the interface\n",
"#data = sim_widget.get_data()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}