Skip to content

Commit 00b3563

Browse files
authored
Merge pull request #1827 from McStasMcXtrace/willend-pygen-minor-revision
pygen minor revision: Build importable make() function and call from generic notebook
2 parents 7b503d9 + d4b1cae commit 00b3563

File tree

8 files changed

+265
-101
lines changed

8 files changed

+265
-101
lines changed

cmake/support/run-scripts/labenv.bat.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ SET EXT=%%~xi
1313

1414
@IF "%EXT%"==".instr" (
1515
@FLAVOR@-pygen %INSTRUMENT%
16-
SET INSTRUMENT="%BASE%_generated.py"
17-
goto :JupyText
16+
sed s/INSTRUMENT/%BASE%/g %BINDIR%\@MCCODE_RELPATH_BINDIR2TOOLDIR@\Python\@MCCODE_PREFIX@run\template.ipynb.in > %BASE%_generated.ipynb
17+
SET INSTRUMENT="%BASE%_generated.ipynb"
18+
goto :JupyLaunch
1819
) ELSE IF "%EXT%"==".py" (
1920
goto :JupyLaunch
2021
) ELSE IF "%EXT%"==".ipynb" (

mcstas/src/pygen.c.in

Lines changed: 98 additions & 91 deletions
Large diffs are not rendered by default.

meta-pkgs/windows/McStas-metapackage64.iss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Source: "dist\mcstas-tools-python-mcdisplay-pyqtgraph-NSIS64-@[email protected]
5353
Source: "dist\mcstas-tools-python-mcdisplay-matplotlib-NSIS64-@[email protected]"; DestDir: "{tmp}"
5454
Source: "dist\mcstas-tools-python-mcdisplay-mantid-NSIS64-@[email protected]"; DestDir: "{tmp}"
5555
Source: "dist\mcstas-tools-python-mcdoc-NSIS64-@[email protected]"; DestDir: "{tmp}"
56-
Source: "dist\mcstas-mcpl-NSIS64-@[email protected]"; DestDir: "{tmp}"
5756
Source: "Support\Miniforge3-Windows-x86_64.exe"; DestDir: "{tmp}"
5857

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

8280
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

meta-pkgs/windows/McXtrace-metapackage64.iss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Source: "dist\mcxtrace-tools-python-mxdisplay-webgl-NSIS64-@[email protected]
4848
Source: "dist\mcxtrace-tools-python-mxdisplay-pyqtgraph-NSIS64-@[email protected]"; DestDir: "{tmp}"
4949
Source: "dist\mcxtrace-tools-python-mxdisplay-matplotlib-NSIS64-@[email protected]"; DestDir: "{tmp}"
5050
Source: "dist\mcxtrace-tools-python-mxdoc-NSIS64-@[email protected]"; DestDir: "{tmp}"
51-
Source: "dist\mcxtrace-mcpl-NSIS64-@[email protected]"; DestDir: "{tmp}"
5251
Source: "Support\Miniforge3-Windows-x86_64.exe"; DestDir: "{tmp}"
5352

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

7270
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

meta-pkgs/windows/environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ channels:
66

77
dependencies:
88
- m2-msys2-runtime
9+
- m2-which
10+
- m2-sed
911
- m2w64-gcc
1012
- m2w64-gsl
1113
- msmpi

tools/Python/mcrun/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ install(
9090
RENAME "${P}run.py"
9191
)
9292

93-
# Other .py infrastructure
94-
foreach(NAME "__init__.py" "log.py" "mccode.py" "optimisation.py" "mcsplit.py")
93+
# Copy in place .py and other infrastructure
94+
foreach(NAME "__init__.py" "log.py" "mccode.py" "optimisation.py" "mcsplit.py" "template.ipynb.in")
9595
install(
9696
FILES "${PROJECT_SOURCE_DIR}/${NAME}"
9797
DESTINATION "${DEST_TOOLDIR}/${TOOLS_NAME}"

tools/Python/mcrun/jupylab.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ canrun() {
3333
if ( canrun ); then
3434
INSTR=$1 # We can actually assume a single input here
3535
BASE=`basename ${INSTR} .instr`
36-
PYINSTR="${BASE}_generated.py"
3736
JUPYBK="${BASE}_generated.ipynb"
3837
@FLAVOR@-pygen ${INSTR}
39-
jupytext --to ipynb ${PYINSTR}
38+
sed s/INSTRUMENT/${BASE}/g ${UTILDIR}/template.ipynb.in > ${JUPYBK}
4039
jupyter lab ${JUPYBK}
4140
else
4241
@FLAVOR@_errmsg Failed to run Python ${TOOL} - permissions or missing dependencies\?
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import mcstasscript as ms\n",
10+
"from INSTRUMENT_generated import make"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"instr=make()"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"# Use instr.settings() to add e.g. seed=1000, ncount=1e7, mpi=8, openacc=True, force_compile=False etc.)"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"# Show diagram\n",
38+
"instr.show_diagram()"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {},
45+
"outputs": [],
46+
"source": [
47+
"# Visualise with default parameters (defaults to 'window'/pyqtgraph visualisation)\n",
48+
"instr.show_instrument(format='window')"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"# Generate a dataset with default parameters.\n",
58+
"data = instr.backengine()"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"# Overview plot:\n",
68+
"ms.make_sub_plot(data)"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"# Other useful commands follow...\n",
78+
"# One plot pr. window\n",
79+
"#ms.make_plot(data)"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"# Load another dataset\n",
89+
"#data2 = ms.load_data('some_other_folder')"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"# Adjusting a specific plot\n",
99+
"#ms.name_plot_options(\\\"PSD_4PI\\\", data, log=1, colormap=\\\"hot\\\", orders_of_mag=5)"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"# Bring up the 'interface' - only relevant in Jupyter\n",
109+
"#%matplotlib widget\n",
110+
"#import mcstasscript.jb_interface as ms_widget\n",
111+
"#ms_widget.show(data)"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"# Bring up the simulation 'interface' - only relevant in Jupyter\n",
121+
"#%matplotlib widget\n",
122+
"#import mcstasscript.jb_interface as ms_widget\n",
123+
"#sim_widget = ms_widget.SimInterface(instr)\n",
124+
"#sim_widget.show_interface()"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": null,
130+
"metadata": {},
131+
"outputs": [],
132+
"source": [
133+
"# Acessing data from the interface\n",
134+
"#data = sim_widget.get_data()"
135+
]
136+
}
137+
],
138+
"metadata": {
139+
"kernelspec": {
140+
"display_name": "Python 3 (ipykernel)",
141+
"language": "python",
142+
"name": "python3"
143+
},
144+
"language_info": {
145+
"codemirror_mode": {
146+
"name": "ipython",
147+
"version": 3
148+
},
149+
"file_extension": ".py",
150+
"mimetype": "text/x-python",
151+
"name": "python",
152+
"nbconvert_exporter": "python",
153+
"pygments_lexer": "ipython3",
154+
"version": "3.10.14"
155+
}
156+
},
157+
"nbformat": 4,
158+
"nbformat_minor": 5
159+
}

0 commit comments

Comments
 (0)