Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fsl_mrs
Commits
d95b93fb
Commit
d95b93fb
authored
Mar 25, 2022
by
William Clarke
Browse files
Add thread control to simulation script.
parent
b291eb0b
Changes
2
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/scripts/fsl_mrs_sim
View file @
d95b93fb
...
...
@@ -74,6 +74,10 @@ def main():
required
=
False
,
metavar
=
'ECHOTIME'
,
help
=
'Echo time value in ms for output files (no effect on simulation).'
)
optional
.
add_argument
(
'--num_processes'
,
type
=
int
,
required
=
False
,
default
=
None
,
help
=
'Number of worker processes to use in simulation, defaults to os.cpu_count().'
)
# optional.add_argument('--verbose',action="store_true",
# help='spit out verbose info')
optional
.
add_argument
(
'--overwrite'
,
action
=
"store_true"
,
...
...
@@ -216,7 +220,8 @@ def main():
# Loop over the spin systems (list) in a parallel way
poolFunc
=
partial
(
runSimForMetab
,
seqParams
=
seqParams
,
args
=
args
)
poolArgs
=
[(
i
,
s
,
n
)
for
i
,
(
s
,
n
)
in
enumerate
(
zip
(
spinsys
,
spinsToSim
))]
pool
=
mp
.
Pool
()
# handle number of processes
pool
=
mp
.
Pool
(
args
.
num_processes
)
pool
.
starmap
(
poolFunc
,
poolArgs
)
# Additional write steps for MM and LCM basis generation
...
...
fsl_mrs/tests/test_scripts_sim.py
View file @
d95b93fb
...
...
@@ -69,3 +69,27 @@ def test_sim(spinsys, seqparams, tmp_path):
assert
np
.
allclose
(
basis_j
[:,
names_j
.
index
(
'sys1'
)],
directSim1
)
assert
np
.
allclose
(
basis_j
[:,
names_j
.
index
(
'sys2'
)],
directSim2
)
def
test_sim_workers
(
spinsys
,
seqparams
,
tmp_path
):
# Test simulation number of workers
# Run the sequence on a couple of metabolites, ask for all types of files, add the reference peak
ssFile
=
op
.
join
(
tmp_path
,
'custom_ss.json'
)
outfile1
=
op
.
join
(
tmp_path
,
'simulated_single'
)
outfile2
=
op
.
join
(
tmp_path
,
'simulated_multi'
)
assert
not
subprocess
.
check_call
(
[
'fsl_mrs_sim'
,
'-s'
,
ssFile
,
'-o'
,
outfile1
,
'-r'
,
'-a'
,
seqfile
,
'--num_processes'
,
'1'
])
assert
not
subprocess
.
check_call
(
[
'fsl_mrs_sim'
,
'-s'
,
ssFile
,
'-o'
,
outfile2
,
'-r'
,
'-a'
,
seqfile
,
'--num_processes'
,
'2'
])
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment