format on save

This commit is contained in:
Martin Bubel 2023-10-10 18:48:06 +02:00
parent 247b84e90b
commit 1d7504fdfb

View file

@ -9,8 +9,7 @@ try:
from mpi4py import MPI from mpi4py import MPI
import subprocess import subprocess
class MPITests(unittest.TestCase): class MPITests:
def test_BayesianGPLVM_MPI(self): def test_BayesianGPLVM_MPI(self):
code = """ code = """
import numpy as np import numpy as np
@ -33,16 +32,19 @@ if comm.rank==0:
m._trigger_params_changed() m._trigger_params_changed()
print float(m.objective_function()) print float(m.objective_function())
""" """
with open('mpi_test__.py','w') as f: with open("mpi_test__.py", "w") as f:
f.write(code) f.write(code)
f.close() f.close()
p = subprocess.Popen('mpirun -n 4 python mpi_test__.py',stdout=subprocess.PIPE,shell=True) p = subprocess.Popen(
"mpirun -n 4 python mpi_test__.py", stdout=subprocess.PIPE, shell=True
)
(stdout, stderr) = p.communicate() (stdout, stderr) = p.communicate()
L1 = float(stdout.splitlines()[-2]) L1 = float(stdout.splitlines()[-2])
L2 = float(stdout.splitlines()[-1]) L2 = float(stdout.splitlines()[-1])
self.assertTrue(np.allclose(L1,L2)) self.assertTrue(np.allclose(L1, L2))
import os import os
os.remove('mpi_test__.py')
os.remove("mpi_test__.py")
def test_SparseGPRegression_MPI(self): def test_SparseGPRegression_MPI(self):
code = """ code = """
@ -66,27 +68,29 @@ if comm.rank==0:
m._trigger_params_changed() m._trigger_params_changed()
print float(m.objective_function()) print float(m.objective_function())
""" """
with open('mpi_test__.py','w') as f: with open("mpi_test__.py", "w") as f:
f.write(code) f.write(code)
f.close() f.close()
p = subprocess.Popen('mpirun -n 4 python mpi_test__.py',stdout=subprocess.PIPE,shell=True) p = subprocess.Popen(
"mpirun -n 4 python mpi_test__.py", stdout=subprocess.PIPE, shell=True
)
(stdout, stderr) = p.communicate() (stdout, stderr) = p.communicate()
L1 = float(stdout.splitlines()[-2]) L1 = float(stdout.splitlines()[-2])
L2 = float(stdout.splitlines()[-1]) L2 = float(stdout.splitlines()[-1])
self.assertTrue(np.allclose(L1,L2)) self.assertTrue(np.allclose(L1, L2))
import os import os
os.remove('mpi_test__.py')
os.remove("mpi_test__.py")
except: except:
pass pass
if __name__ == "__main__": if __name__ == "__main__":
print("Running unit tests, please be (very) patient...") print("Running unit tests, please be (very) patient...")
try: try:
import mpi4py import mpi4py
unittest.main() unittest.main()
except: except:
pass pass