Skip to content

Commit

Permalink
fixed osx issues?
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Anibal committed Nov 3, 2023
1 parent a817e92 commit dbcd6c0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
11 changes: 10 additions & 1 deletion pyavl/MExt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import shutil
import sys

import platform

def _tmp_pkg(tempDir):
"""
Expand Down Expand Up @@ -50,6 +50,15 @@ def __init__(self, libName, packageName, lib_so_file=None, debug=False):
self._pkgname, self._pkgdir = _tmp_pkg(tmpdir)
# copy the original module to the new package
shutil.copy(srcpath, self._pkgdir)
if platform.system() == "Darwin":
# create a sym link to the orginal module .dylibs folder
blas_libs_dir = ".dylib"
source_path = os.path.join(srcpath, blas_libs_dir)
target_path = os.path.join(self._pkgdir, blas_libs_dir)

# Unix-based system (Mac, Linux)
os.symlink(source_path, target_path)

# add the directory containing the new package to the search path
sys.path.append(tmpdir)
# import the module
Expand Down
25 changes: 20 additions & 5 deletions pyavl/pyAVL.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class is to provide an easy to use wrapper for avl for intergration
import warnings
import glob
from typing import Optional
import platform

# =============================================================================
# External Python modules
Expand Down Expand Up @@ -174,14 +175,28 @@ def __init__(self, geo_file=None, mass_file=None, debug=False, timing=False):

if timing:
start_time = time.time()
# create a symbolic link to dependecies in the temp directory
blas_libs_dir = "pyavl_wrapper.libs"
source_path = os.path.join(BASE_DIR, "..", blas_libs_dir)
target_path = os.path.join("/tmp", blas_libs_dir)

# Create a symbolic link based on the platform
if not os.path.exists(target_path) and os.path.exists(source_path):
if os.name == "posix":
# create a symbolic link to dependecies in the temp directory
if platform.system() == "Darwin":
# Mac
pass # needs to be fixed in Mext
# blas_libs_dir = ".dylibs"
# source_path = os.path.join(BASE_DIR, blas_libs_dir)
# target_path = os.path.join("/tmp", blas_libs_dir)

elif platform.system() == "Linux":
blas_libs_dir = "pyavl_wrapper.libs"
source_path = os.path.join(BASE_DIR, "..", blas_libs_dir)
target_path = os.path.join("/tmp", blas_libs_dir)


else:
raise NotImplementedError("operating system not recognized")


# Unix-based system (Mac, Linux)
os.symlink(source_path, target_path)
elif os.name == "nt":
Expand All @@ -195,7 +210,7 @@ def __init__(self, geo_file=None, mass_file=None, debug=False, timing=False):
raise NotImplementedError("operating system not recognized")

# This is important for creating multiple instances of the AVL solver that do not share memory
# It is very gross, but I cannot figure out a better way.
# It is very gross, but I cannot figure out a better way (maybe use install_name_tool to change the dynamic library path to absolute).
# increment this counter for the hours you wasted on trying find a better way
# 7 hours

Expand Down
8 changes: 7 additions & 1 deletion tests/test_total_derivs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def setUp(self):
self.avl_solver.add_constraint("beta", 0.0)
self.avl_solver.execute_run()

def tearDown(self):
# Without the following line a copy of large_list will be kept in
# memory for each test that runs, uncomment the line to allow the
mb_memory = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000
print(f"{self.id()} Memory usage: {mb_memory} MB")

def finite_dif(self, con_list, geom_seeds, step=1e-7):
con_seeds = {}

Expand Down Expand Up @@ -97,7 +103,7 @@ def test_aero_constraint(self):
# print(f"{func_key} wrt {con_key}", "AD", ad_dot, "FD", fd_dot)
rel_err = np.abs((ad_dot - fd_dot) / (fd_dot + 1e-20))

print(f"{func_key:5} wrt {con_key:5} | AD:{ad_dot: 5e} FD:{fd_dot: 5e} rel err:{rel_err:.2e}")
# print(f"{func_key:5} wrt {con_key:5} | AD:{ad_dot: 5e} FD:{fd_dot: 5e} rel err:{rel_err:.2e}")

tol = 1e-13
if np.abs(ad_dot) < tol or np.abs(fd_dot) < tol:
Expand Down
12 changes: 0 additions & 12 deletions tools/wheels/cibw_test_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,20 @@ cd $PROJECT_DIR/tests
#HACK: if the tests are not split up the CI runs out of memory...

# test package built and installed correctly
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_import.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_io.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
# test basic avl functionality
python -m unittest -v test_parameters.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_analysis.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_surf_geom.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_contraints.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'

# tests for adjoint
python -m unittest -v test_new_subroutines.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_partial_derivs.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_consurf_partial_derivs.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
python -m unittest -v test_total_derivs.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'

# test mem ussage of pyavl and test framework
python -m unittest -v test_tear_down.py
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'

0 comments on commit dbcd6c0

Please sign in to comment.