Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pySOT/experimental_design/lhd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import warnings

import numpy as np
import pyDOE2 as pydoe

from .experimental_design import ExperimentalDesign, _expdes_dist

Expand Down Expand Up @@ -52,6 +51,8 @@ def generate_points(self, lb=None, ub=None, int_var=None):
int_var = np.array([])

def wrapper():
import pyDOE2 as pydoe

return pydoe.lhs(self.dim, self.num_pts, iterations=1)

return _expdes_dist(wrapper, self.iterations, lb, ub, int_var)
28 changes: 28 additions & 0 deletions tests/test_experimental_designs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import subprocess
import sys

import numpy as np
import pytest

Expand Down Expand Up @@ -39,6 +42,31 @@ def test_slhd():
assert slhd.dim == 3


def test_slhd_import_does_not_require_pydoe2():
script = """
import importlib.abc
import sys

class BlockPyDOE2(importlib.abc.MetaPathFinder):
def find_spec(self, fullname, path=None, target=None):
if fullname == "pyDOE2":
raise ImportError("blocked pyDOE2 import")
return None

sys.meta_path.insert(0, BlockPyDOE2())
from pySOT.experimental_design import SymmetricLatinHypercube
SymmetricLatinHypercube(dim=2, num_pts=4)
"""
proc = subprocess.Popen(
[sys.executable, "-c", script],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_, stderr = proc.communicate()

assert proc.returncode == 0, stderr.decode("utf-8")


def test_slhd_round():
num_pts = 10
dim = 3
Expand Down