Candidate Generation¶
Candidate-generation helpers build and audit finite materials, chemistry, formulation, or processing-condition pools before Bayesian optimization. Use these functions to create realistic candidate tables, summarize descriptor completeness and duplicate keys, check feature/category coverage against measured data, remove rows that have already been measured, and split candidate metadata from numeric model features.
matgpr.candidate_generation
¶
CandidatePoolDiagnostics
dataclass
¶
Diagnostic tables for a finite candidate pool.
Attributes:
| Name | Type | Description |
|---|---|---|
overview |
DataFrame
|
One-row pool-level summary with candidate counts, missing-feature counts, and duplicate-key counts. |
numeric_features |
DataFrame
|
Per-feature numeric descriptor summary. |
categorical_features |
DataFrame
|
Per-column categorical metadata summary. |
duplicate_keys |
DataFrame
|
Duplicate key groups, empty when no duplicate groups are found or no key columns were supplied. |
Source code in matgpr/candidate_generation.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
overview_frame()
¶
Return a copy of the pool-level overview table.
Source code in matgpr/candidate_generation.py
50 51 52 | |
numeric_feature_frame()
¶
Return a copy of the numeric feature summary table.
Source code in matgpr/candidate_generation.py
54 55 56 | |
categorical_feature_frame()
¶
Return a copy of the categorical metadata summary table.
Source code in matgpr/candidate_generation.py
58 59 60 | |
duplicate_key_frame()
¶
Return a copy of the duplicate-key diagnostics table.
Source code in matgpr/candidate_generation.py
62 63 64 | |
build_cartesian_candidate_grid(parameter_space, *, fixed_values=None, candidate_id_column='candidate_id', candidate_id_prefix='candidate', max_candidates=100000)
¶
Build a finite candidate table from a Cartesian product of choices.
Use this for processing conditions, formulation variables, solvents, categorical choices, or any finite design space that should be ranked by Bayesian optimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter_space
|
Mapping[str, Iterable[Any] | Any]
|
Mapping from output column name to candidate values. Scalars and strings are treated as one-value choices. |
required |
fixed_values
|
Mapping[str, Any] | None
|
Optional columns with constant metadata added to every candidate row. |
None
|
candidate_id_column
|
str | None
|
Optional candidate identifier column. Set to |
'candidate_id'
|
candidate_id_prefix
|
str
|
Prefix used when |
'candidate'
|
max_candidates
|
int | None
|
Optional safety limit. A |
100000
|
Source code in matgpr/candidate_generation.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
build_composition_candidate_grid(elements, *, step=0.25, min_fraction=0.0, max_fraction=1.0, min_components=1, max_components=None, formula_column='formula', fraction_prefix='frac_', candidate_id_column='candidate_id', candidate_id_prefix='composition', max_candidates=100000)
¶
Build inorganic composition candidates on an element-fraction simplex.
The grid uses integer stoichiometric units implied by step. For example,
step=0.25 creates compositions with fractions in increments of one
quarter and formulas such as "Al3Ni" or "AlNi".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
Sequence[str]
|
Element symbols defining the composition space. |
required |
step
|
float
|
Fractional spacing. The value must divide 1.0, such as |
0.25
|
min_fraction
|
float
|
Bounds applied to each nonzero element fraction. |
0.0
|
max_fraction
|
float
|
Bounds applied to each nonzero element fraction. |
0.0
|
min_components
|
int
|
Bounds on the number of elements present in a candidate. |
1
|
max_components
|
int
|
Bounds on the number of elements present in a candidate. |
1
|
formula_column
|
str
|
Name of the generated reduced-formula column. |
'formula'
|
fraction_prefix
|
str
|
Prefix for element-fraction columns. |
'frac_'
|
candidate_id_column
|
str | None
|
Optional candidate identifier column. Set to |
'candidate_id'
|
candidate_id_prefix
|
str
|
Prefix used when |
'composition'
|
max_candidates
|
int | None
|
Optional safety limit for generated rows. |
100000
|
Source code in matgpr/candidate_generation.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
exclude_existing_candidates(candidates, observed, key_columns, *, keep_indicator=False, indicator_column='matgpr_is_observed')
¶
Remove or annotate candidates that already exist in observed data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidates
|
DataFrame
|
Candidate table to filter. |
required |
observed
|
DataFrame
|
Existing measured, simulated, or already-selected rows. |
required |
key_columns
|
Sequence[str]
|
Columns used to identify duplicates, such as |
required |
keep_indicator
|
bool
|
If |
False
|
indicator_column
|
str
|
Name of the boolean indicator column used when |
'matgpr_is_observed'
|
Source code in matgpr/candidate_generation.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
split_candidate_features(candidates, feature_columns, *, metadata_columns=None)
¶
Split a candidate table into numeric features and candidate metadata.
The returned (X_candidates, candidate_data) tuple can be passed directly
to suggest_next_experiments.
Source code in matgpr/candidate_generation.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
summarize_candidate_pool(candidates, *, feature_columns=None, categorical_columns=None, key_columns=None)
¶
Summarize a finite candidate pool before Bayesian optimization.
This helper is intended for search-space audits: descriptor completeness, numeric feature ranges, categorical metadata diversity, and duplicate candidate keys. It does not rank candidates and does not require BoTorch.
Source code in matgpr/candidate_generation.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
summarize_candidate_feature_coverage(candidates, reference_data, feature_columns, *, tolerance=0.0)
¶
Compare numeric candidate-feature ranges with reference/training data.
The returned table reports whether the finite candidate pool covers the reference range for each feature, and how much of the candidate pool lies outside the reference feature range. Use this before BO to identify extrapolative candidate pools or features with poor search-space coverage.
Source code in matgpr/candidate_generation.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
summarize_candidate_category_coverage(candidates, reference_data, categorical_columns, *, max_levels=20)
¶
Compare categorical candidate levels with reference/training data.
This is useful for finite BO pools that include solvents, processing labels, synthesis routes, supplier choices, or discrete formulation classes. The summary highlights candidate-only levels and reference levels that are absent from the candidate pool.
Source code in matgpr/candidate_generation.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
summarize_candidate_duplicates(candidates, key_columns)
¶
Return duplicate candidate-key groups sorted by duplicate count.
Source code in matgpr/candidate_generation.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |