Skip to content

Fix #86: Optional inactive parameters - #112

Merged
MLopez-Ibanez merged 4 commits into
MLopez-Ibanez:masterfrom
mork-optimization:fix_86
Nov 10, 2026
Merged

MLopez-Ibanez merged 4 commits into
MLopez-Ibanez:masterfrom
mork-optimization:fix_86

Conversation

@rmartinsanta

Copy link
Copy Markdown
Contributor

Configuration inputs may omit variable parameters that are inactive in every configuration. I am not sure this patch does not have unintended consequences, any feedback is welcome.

@rmartinsanta

Copy link
Copy Markdown
Contributor Author

Related to issue #86.

@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.49%. Comparing base (2c14265) to head (0994ac2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #112      +/-   ##
==========================================
+ Coverage   75.48%   75.49%   +0.01%     
==========================================
  Files          30       30              
  Lines        5120     5110      -10     
==========================================
- Hits         3865     3858       -7     
+ Misses       1255     1252       -3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MLopez-Ibanez

Copy link
Copy Markdown
Owner

@rmartinsanta Could you see this version of test-readconfs.R:

withr::with_output_sink("test-readconfs.Rout", {

params <- readParameters("parameters.txt")

expect_error_readconfs <- function(params, table, exp)
  expect_error(irace::readConfigurationsFile(text=table, parameters = params), exp)

test_that("no error", {
  x <- irace::readConfigurationsFile(text='
param1 param2 mode   real mutation
5        NA    "x2"   4.0   "low"
1        NA    "x2"   4.0   "low"
NA       NA   "x3"   4.5   "low"', parameters=params)
  expect_equal(nrow(x), 3L)
  expect_equal(ncol(x), 6L) # It adds the fixed column

  expect_identical(
    readConfigurationsFile(text='
param1 mode real mutation
5      x2   4.0  low
1      x2   4.0  low', parameters=params),
readConfigurationsFile(text='
param1 param2 mode real mutation
5      NA     x2   4.0  low
1      NA     x2   4.0  low', parameters=params))
})

test_that("wrong fixed", {
  expect_error_readconfs(params, '
param1 param2 mode   real mutation fixed
5       NA    "x2"   4.0  "low"    fixed
1       NA    "x2"   4.0  "low"    fixed
NA      NA    "x3"   4.5  "low"    wrong', "is not among the valid values")
})

test_that("checkDuplicates", {
  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5        NA    "x2"   4.0   "low"
1        NA    "x2"   4.0   "low"
5        NA    "x2"   4.0   "low"
NA       NA    "x3"   4.5   "low"
', "Duplicated")

  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5        NA    "x2"   4.0   "low"
1        NA    "x2"   4.0   "low"
5        NA    "x2"   4.0   "low"
1        NA    "x2"   4.0   "low"
', "Duplicated")

})

test_that("parameter values", {
  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5       NA    "x2"   4.0   "low"
1       NA    "x2"   4.0   "low"
11      NA    "x2"   4.0   "low"
', "is not within the valid range")
  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5       NA    "x2"   4.0   "low"
1       NA    "x2"   4.5001 "low"
', "is not within the valid range")
  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5       NA    "x2"   4.0   "low"
1.1     NA    "x2"   4.5   "low"
', "is not an integer")
  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5       NA    "x2"   4.0   "low"
1       NA    "x2"   4.5   "lower"
', "is not among the valid values")
  expect_error_readconfs(params, '
param1 param2 mode   real mutation
5       NA    "x3"   4.0   "low"
1       NA    "x2"   4.5   "low"
', "is not enabled")
})

test_that("parameter names", {
  expect_error_readconfs(params, '
param1 param0 mode   real mutation
5        NA    "x2"   4.0   "low"
1        NA    "x2"   4.0   "low"
', "do not match")
  expect_error_readconfs(params, '
param1 mode   real mutation
5       "x1"   3.0   "low"
1       "x2"   4.0   "low"
', 'Configuration number 1.*param2.*is missing')
  expect_error_readconfs(params, '
param1 param2 mode   real mutation param3
5        NA    "x2"   4.0   "low"  NA
1        NA    "x2"   4.0   "low"  NA
', "do not match")
})

test_that("inactive variable parameters may be omitted", {
  for (definition in c('i (1, 10)', 'r (0, 1)', 'c (x, y)', 'o (x, y)')) {
    params <- readParameters(text=paste0('
param1 "" i (1, 2)
param2 "" c (a, b, c)
param3 "" ', definition, ' | !(param2 %in% c("a", "b"))'))
    full <- readConfigurationsFile(text='
param1 param2 param3
1 a NA
2 b NA
1 b NA
2 a NA', parameters=params)
    compact <- 'param1 param2\n1 a\n2 b\n1 b\n2 a'
    expect_identical(readConfigurationsFile(text=compact, parameters=params), full)
    expect_identical(irace:::fix_configurations(full[c("param2", "param1")], params), full)

    path <- withr::local_tempfile()
    writeLines(compact, path)
    expect_identical(readConfigurationsFile(path, parameters=params), full)
    
    confs_txt <- 'param1 param2\n1 a\n2 c'
    expect_error_readconfs(params, confs_txt, 'Configuration number 2.*param3.*is missing')
    writeLines(confs_txt, path)
    expect_error(readConfigurationsFile(path, parameters=params),
                 'Configuration number 2 from file .*param3.*is missing')
    expect_error_readconfs(params, 'param2\na', 'param1.*is missing')
    expect_error_readconfs(params, 'param1 param2\n1 a\n1 a', 'Duplicated')
  }
})

test_that("omitted parameters respect chained conditions and dependent domains", {
  params <- readParameters(text='
dependent "" r (0, parent)
child     "" c (x, y) | parent > 0
parent    "" r (0, 1) | mode == "on"
mode      "" c (on, off)')
  full <- readConfigurationsFile(text='
mode parent child dependent
off  NA     NA    NA', parameters=params)
  expect_identical(readConfigurationsFile(text='mode\noff', parameters=params), full)
  expect_error_readconfs(params, 'mode\non', 'parent.*is missing')
  expect_error_readconfs(params, 'mode parent child\noff NA NA\non 0.5 x',
                         'Configuration number 2.*dependent.*is missing')
})

test_that("omitted fixed parameters are resolved in dependency order", {
  params <- readParameters(text='
child  "" c (yes) | parent == "yes"
parent "" c (yes) | mode == "on"
mode   "" c (on, off)')
  expect_identical(
    readConfigurationsFile(text='mode\noff\non', parameters=params),
    readConfigurationsFile(text='mode parent child\noff NA NA\non yes yes', parameters=params))
})


test_that("conditional fixed", {

  params <- readParameters(text='
param1 "" c ("fixed")
param2 "" c ("cond_fixed") | param3 == "on"
param3 "" c ("on", "off")
')

  x <- irace::readConfigurationsFile(text='
param1 param3
fixed  off
', parameters=params)

  expect_equal(x[["param2"]], NA_character_)

  x <- irace::readConfigurationsFile(text='
param1 param2 param3
fixed  NA     off
', parameters=params)

  x <- irace::readConfigurationsFile(text='
param1 param3
fixed  on
', parameters=params)

  expect_equal(x[["param2"]], "cond_fixed")

  expect_error_readconfs(params, '
param1 param2      param3
fixed  cond_fixed     off
', "is not enabled because of condition")
})

}) # withr::with_output_sink

@MLopez-Ibanez

Copy link
Copy Markdown
Owner

@rmartinsanta Could you fix the pre-commit issues? I cannot edit your fork.

@MLopez-Ibanez
MLopez-Ibanez merged commit ae00f21 into MLopez-Ibanez:master Nov 10, 2026
14 checks passed
@rmartinsanta
rmartinsanta deleted the fix_86 branch November 10, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants