Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type checking for frequencies argument of OptimizationProblem constructor #2747

Merged
merged 1 commit into from
Dec 27, 2023
Merged
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
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