Skip to content

Commit 9adc3f5

Browse files
Merge branch 'pr/1.4.4' into mpvanderschelling/issue194
2 parents f47bc0f + 452c53b commit 9adc3f5

File tree

14 files changed

+257
-56
lines changed

14 files changed

+257
-56
lines changed

.github/workflows/pr_to_pr.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
name: Pull request to pr/** branches
1+
name: Pull request and push to pr/** branches
22

33
on:
44
pull_request:
55
branches:
66
- "pr/**"
7+
push:
8+
branches:
9+
- "pr/**"
710

811
jobs:
912
check-coding-style:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.3
1+
1.4.4

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
project = 'f3dasm'
2525
author = 'Martin van der Schelling'
2626
copyright = '2022, Martin van der Schelling'
27-
version = '1.4.3'
28-
release = '1.4.3'
27+
version = '1.4.4'
28+
release = '1.4.4'
2929

3030

3131
# -- General configuration ----------------------------------------------------

docs/source/rst_doc_files/classes/design/experimentsample.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ An KeyError will be raised if the key is not found.
5454
>>> experiment_sample.get('param_1')
5555
0.0249
5656
57+
Manually iterating over ExperimentData
58+
----------------------------------------
59+
60+
The :class:`~f3dasm.design.ExperimentData` object can be manually iterated over to get :class:`~f3dasm.design.ExperimentSample` objects for each experiment:
61+
62+
.. code-block:: python
63+
64+
>>> for experiment_sample in experiment_data:
65+
... print(experiment_sample)
66+
ExperimentSample(0 : {'x0': 0.8184054141827567, 'x1': 0.937852542255321, 'x2': 0.7376563782762678} - {})
67+
ExperimentSample(1 : {'x0': 0.7203461491873061, 'x1': 0.7320604457665572, 'x2': 0.2524387342272223} - {})
68+
ExperimentSample(2 : {'x0': 0.35449352388104904, 'x1': 0.11413412225748525, 'x2': 0.1467895592274866} - {})
69+
5770
Storing output parameters to the experiment sample
5871
--------------------------------------------------
5972

src/f3dasm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# =============================================================================
3838

3939

40-
__version__ = '1.4.3'
40+
__version__ = '1.4.4'
4141

4242

4343
# Log welcome message and the version of f3dasm

src/f3dasm/_src/datageneration/datagenerator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def post_process(self, experiment_sample: ExperimentSample, **kwargs) -> None:
8888
...
8989

9090
@time_and_log
91-
def run(self, experiment_sample: ExperimentSample, **kwargs) -> ExperimentSample:
92-
"""This function chains the following methods together
91+
def _run(self, experiment_sample: ExperimentSample, **kwargs) -> ExperimentSample:
92+
"""
93+
Run the data generator
94+
This function chains the following methods together
9395
9496
* pre_process(); to combine the experiment_sample and the parameters
9597
of the data generator to an input file that can be used to run the data generator

src/f3dasm/_src/datageneration/functions/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def execute(self, experiment_sample: ExperimentSample) -> ExperimentSample:
9999
experiment_sample["y"] = self(x).ravel().astype(np.float32)
100100
return experiment_sample
101101

102-
def run(self, experiment_sample: ExperimentSample, **kwargs) -> ExperimentSample:
102+
def _run(self, experiment_sample: ExperimentSample, **kwargs) -> ExperimentSample:
103103
return self.execute(experiment_sample)
104104

105105
def _retrieve_original_input(self, x: np.ndarray):

src/f3dasm/_src/design/domain.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
from __future__ import annotations
99

1010
# Standard
11+
import math
1112
import pickle
1213
from dataclasses import dataclass, field
1314
from pathlib import Path
14-
from typing import Any, Dict, Iterator, List, Sequence, Type
15+
from typing import Any, Dict, Iterable, Iterator, List, Sequence, Type
1516

1617
# Third-party core
1718
import numpy as np
@@ -252,7 +253,14 @@ def add_int(self, name: str, low: int, high: int, step: int = 1):
252253
>>> domain.add_int('param1', 0, 10, 2)
253254
>>> domain.space
254255
{'param1': DiscreteParameter(lower_bound=0, upper_bound=10, step=2)}
256+
257+
Note
258+
----
259+
If the lower and upper bound are equal, then a constant parameter
260+
will be added to the domain!
255261
"""
262+
if low == high:
263+
self.add_constant(name, low)
256264
self._add(name, DiscreteParameter(low, high, step))
257265

258266
def add_float(self, name: str, low: float, high: float, log: bool = False):
@@ -275,8 +283,16 @@ def add_float(self, name: str, low: float, high: float, log: bool = False):
275283
>>> domain.add_float('param1', 0., 10., log=True)
276284
>>> domain.space
277285
{'param1': ContinuousParameter(lower_bound=0., upper_bound=10., log=True)}
286+
287+
Note
288+
----
289+
If the lower and upper bound are equal, then a constant parameter
290+
will be added to the domain!
278291
"""
279-
self._add(name, ContinuousParameter(low, high, log))
292+
if math.isclose(low, high):
293+
self.add_constant(name, low)
294+
else:
295+
self._add(name, ContinuousParameter(low, high, log))
280296

281297
def add_category(self, name: str, categories: Sequence[CategoricalType]):
282298
"""Add a new categorical input parameter to the domain.
@@ -573,6 +589,38 @@ def _filter(self, type: Type[Parameter]) -> Domain:
573589
if isinstance(parameter, type)}
574590
)
575591

592+
def select(self, names: str | Iterable[str]) -> Domain:
593+
"""Select a subset of parameters from the domain.
594+
595+
Parameters
596+
----------
597+
598+
names : str or Iterable[str]
599+
The names of the parameters to select.
600+
601+
Returns
602+
-------
603+
Domain
604+
A new domain with the selected parameters.
605+
606+
Example
607+
-------
608+
>>> domain = Domain()
609+
>>> domain.space = {
610+
... 'param1': ContinuousParameter(lower_bound=0., upper_bound=1.),
611+
... 'param2': DiscreteParameter(lower_bound=0, upper_bound=8),
612+
... 'param3': CategoricalParameter(categories=['cat1', 'cat2'])
613+
... }
614+
>>> domain.select(['param1', 'param3'])
615+
Domain({'param1': ContinuousParameter(lower_bound=0, upper_bound=1),
616+
'param3': CategoricalParameter(categories=['cat1', 'cat2'])})
617+
"""
618+
619+
if isinstance(names, str):
620+
names = [names]
621+
622+
return Domain(space={key: self.space[key] for key in names})
623+
576624
# Miscellaneous
577625
# =============================================================================
578626

src/f3dasm/_src/experimentdata/_data.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ def n_best_samples(self, nosamples: int, column_name: List[str] | str) -> pd.Dat
291291
"""
292292
return self.data.nsmallest(n=nosamples, columns=column_name)
293293

294+
def select_columns(self, columns: Iterable[str] | str) -> _Data:
295+
"""Filter the data on the selected columns.
296+
297+
Parameters
298+
----------
299+
columns : Iterable[str] | str
300+
The columns to select.
301+
302+
Returns
303+
-------
304+
_Data
305+
The data only with the selected columns
306+
"""
307+
# This is necessary otherwise self.data[columns] will be a Series
308+
if isinstance(columns, str):
309+
columns = [columns]
310+
return _Data(self.data[columns])
294311
# Append and remove data
295312
# =============================================================================
296313

0 commit comments

Comments
 (0)