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

Improve MATLAB integration #5

Open
MLopez-Ibanez opened this issue Feb 16, 2021 · 0 comments
Open

Improve MATLAB integration #5

MLopez-Ibanez opened this issue Feb 16, 2021 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@MLopez-Ibanez
Copy link
Owner

Currently, communication with MATLAB is slow, requires editing R files and quite cumbersome and fragile. How to fix this?

  1. Figure out what is the best way to communicate to MATLAB the information that irace generates. Currently, we use:
  matlab_function_call <- "Main(INSTANCE,SEED,A,B)"
  args <- paste0(names(configuration), "=", configuration, collapse=";")
  exitcode <- matlabr::run_matlab_code(
                         # This is the instance and seed
                         c(paste0("INSTANCE='", instance, "';SEED=", seed),
                           # The configuration parameters,
                           args, matlab_function_call),
                         paths_to_add=matlab_script_path,
                         verbose= (debugLevel >= 2))

which uses the matlabr package to run the code:

INSTANCE='instance'
SEED=seed
A=value_of_A
B=value_of_B
Main(INSTANCE,SEED,A,B)

The above assumes that there are 2 parameters A and B. If the parameters are different, then the above code must be edited.

This is not very flexible, because the user has to create such a function Main() with the precise parameters, but I don't know what would be a better way. Is there a way to call a MATLAB function with a variable number of parameters?

There is another package: https://cran.r-project.org/web/packages/R.matlab/index.html

I think using R.matlab package to send/receive data from/to MATLAB would be much better than using matlabr.

  1. Figure out what is the best way to collect the output given by MATLAB. Currently, we read the output like:
  ## Parse the output (just a single number!)
  # FIXME: Create a uniquely named temporary file instead of Result.txt to
  # allow parallel execution
  output <- scan(file="Result.txt", quiet=TRUE)
  cost <- as.numeric(output)

That is the function Main() in MATLAB must save the output to a file Result.txt, which irace reads. The above is slow and very unflexible. Ideally we would be able to call MATLAB and get the output directly without any extra files, but I don't know how to do that. Maybe possible with the R.matlab package mentioned above.

  1. Once the above is figured out, create an R package tunematlab that contains a function: irace_matlab_runner(). And in scenario.txt you would just specify "targetRunner="matlab" and irace will load the tunematlab package and use the irace_matlab_runner() function to call matlab in the right way. This is the easy part.
@MLopez-Ibanez MLopez-Ibanez added enhancement New feature or request help wanted Extra attention is needed labels Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant