Skip to content

Commit

Permalink
add type checking for frequencies argument of OptimizationProblem con…
Browse files Browse the repository at this point in the history
…structor (#2747)
  • Loading branch information
oskooi authored Dec 27, 2023
1 parent 5494b9b commit c92fd9b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions python/adjoint/optimization_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
objective_functions: List[Callable],
objective_arguments: List[ObjectiveQuantity],
design_regions: List[DesignRegion],
frequencies: Optional[Union[float, List[float]]] = None,
frequencies: Optional[Union[np.ndarray, List[float]]] = None,
fcen: Optional[float] = None,
df: Optional[float] = None,
nf: Optional[int] = None,
Expand All @@ -53,7 +53,7 @@ def __init__(
and we have to specify arguments as [A,B,C]
objective_arguments: list of ObjectiveQuantity passed as arguments of objective functions
design_regions: list of DesignRegion to be optimized
frequencies: list of frequencies of interest in the problem. If not specified, then the list of frequencies
frequencies: array/list of frequencies of interest in the problem. If not specified, then the list of frequencies
will be created from fcen, df, and nf: a list of size nf that goes from fcen-df/2 to fcen+df/2
fcen: center frequency
df: range of frequencies, i.e. maximum frequency - minimum frequency
Expand Down Expand Up @@ -88,10 +88,18 @@ def __init__(
self.num_design_params = [ni.num_design_params for ni in self.design_regions]
self.num_design_regions = len(self.design_regions)

# TODO typecheck frequency choices
if frequencies is not None:
self.frequencies = frequencies
self.nf = np.array(frequencies).size
if isinstance(frequencies, (np.ndarray, List)):
self.frequencies = frequencies
if isinstance(frequencies, np.ndarray):
self.nf = frequencies.size
else:
self.nf = len(frequencies)
else:
raise TypeError(
"frequencies argument of OptimizationProblem "
"constructor must be a Numpy array or List."
)
elif nf == 1:
self.nf = nf
self.frequencies = [fcen]
Expand Down

0 comments on commit c92fd9b

Please sign in to comment.