Skip to content

Commit

Permalink
test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinAchondo committed May 31, 2024
1 parent 5bf86d9 commit f2f18bc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
15 changes: 14 additions & 1 deletion tests/test_xppbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import csv
import shutil
from xppbe.Simulation import Simulation
from xppbe import Simulation
from xppbe import Allrun,Allclean

def run_checkers(sim,sim_name,temp_dir):
Expand Down Expand Up @@ -40,6 +40,19 @@ def run_checkers(sim,sim_name,temp_dir):
print('Checkers Passed!')


def test_scripts():
with tempfile.TemporaryDirectory() as temp_dir:
sim_name = f'test_born_ion'
yaml_path = os.path.join(os.path.dirname(__file__),'simulations_yaml',sim_name+'.yaml')
sims_path = os.path.join(temp_dir,'sims')
os.mkdir(sims_path)
shutil.copy(yaml_path,os.path.join(sims_path,sim_name+'.yaml'))
Allrun(sims_path=sims_path, results_path=temp_dir)
sim = Simulation(yaml_path, results_path=temp_dir)
run_checkers(sim,sim_name,temp_dir)
Allclean(results_path=temp_dir)
assert len(os.listdir(os.path.join(temp_dir,'results'))) == 0


@pytest.mark.parametrize(
('molecule'),
Expand Down
22 changes: 20 additions & 2 deletions xppbe/Scripts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ function Allrun() {
exit 1
fi

PYTHON_CODE="
import os
import sys
from xppbe import Simulation
yaml_path = os.path.abspath(sys.argv[1])
results_path = '${results_path%/results}'
plot_pbj = '--pbj' in sys.argv
plot_mesh = '--mesh' in sys.argv
sim = Simulation(yaml_path, results_path=results_path)
sim.create_simulation()
sim.adapt_model()
sim.solve_model()
sim.postprocessing(mesh=plot_mesh, pbj=plot_pbj)
"

sims_count=0
for script_path in "$sims_path"/*.yaml
do
Expand Down Expand Up @@ -51,10 +69,10 @@ function Allrun() {
echo "Running step: $i"
new_iters=$(echo "( $num_iters_per_step*$i)" | bc)
sed -i "s/^N_iters: [0-9]\+/N_iters: $new_iters/" $script_path
python "$main_dir/Simulation.py" "$script_path" "--results-path=${results_path%/results}"
python -c "$PYTHON_CODE" "$script_path"
done
fi
python "$main_dir/Simulation.py" "$script_path" "--results-path=${results_path%/results}" "$pbj_flag" "$mesh_flag"
python -c "$PYTHON_CODE" "$script_path" "$pbj_flag" "$mesh_flag"

echo "Ending Simulation $sims_count : $script_name"
echo ""
Expand Down
1 change: 0 additions & 1 deletion xppbe/Simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ def get_simulation_paths(self,yaml_path, molecule_path=None, results_path=None):

if __name__=='__main__':

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
yaml_path = os.path.abspath(sys.argv[1])

results_path = os.path.dirname(__file__)
Expand Down

0 comments on commit f2f18bc

Please sign in to comment.