mde-optimiser / mde_optimiser

Multi-objective optimisation of domain-specific models
https://mde-optimiser.github.io/
2 stars 7 forks source link

Path problems when writing experiment results to disk (under Windows) #112

Open dstrueber opened 2 years ago

dstrueber commented 2 years ago

I ran an .mpot file (CRA case) via context menu. The search seems to have behaved as expected, but during the serialization, the following exception was thrown. Possibly there is a simple fix, in the way that MDEOResultsOutput.saveOutcome() puts together the output path.

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 52: C:\Users\danie\Desktop\cra\mdeo-results/experiment-C:\Users\danie\Desktop\cra\src\main\java\cra_manual_rules.mopt/ at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229) at java.base/java.nio.file.Path.of(Path.java:147) at java.base/java.nio.file.Paths.get(Paths.java:69) at uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.output.MDEOResultsOutput.saveOutcome(MDEOResultsOutput.java:67) at uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.output.MDEOResultsOutput.saveOutcome(MDEOResultsOutput.java:60) at uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run.runSearch(Run.java:209) at uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run.run(Run.java:121) at uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run.run(Run.java:103) at uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run.main(Run.java:61)

Leative commented 2 years ago

Did you specify an absolute path as the basepath in the mopt configuration? Working with relative paths I never encountered such an issue. Maybe you can attach the mopt code?

dstrueber commented 2 years ago

It's the "cra_manual_rules.mopt" file from the CRA example, I didn't change it. It contains a relative basepath:

basepath <src/main/resources/models/cra/>

alxbrd commented 2 years ago

This is because the paths are concatenated it would seem. No issue on linux, but windows complains. There is an additional step required to filter invalid characters from the path.

dstrueber commented 2 years ago

Possibly it would even be preferable to have a non-OS-specific solution that avoids this problem: By concatenating the paths, one gets a somewhat excessively nested directory hierarchy. Instead, one could just add a new directory (e.g., with a timestamp in the name) to the base path.

Leative commented 2 years ago

Strangely, I never encountered this problem on my windows machines. Did you start MDEO from within Eclipse or via command line? In the latter case, did you specify the path to your project as an absolute path in your call to MDEO? I am always working with relative paths there.

dstrueber commented 1 year ago

Via context menu (= from Eclipse) and using the unchanged "cra_manual_rules.mopt" example file (= including relative path).

I haven't encountered this problem in the past either, under Windows - it could potentially even come from a different Java or Eclipse version (12 and 2021-09 in my case).

alxbrd commented 1 year ago

This might be caused by something that changed in the version of Eclipse you are using. I only tested up to Eclipse 2019-03 and Java 11 running on Linux.

When running experiments on cloud, these paths are parametrised, to more easily identify which configuration generated which experiment results. Just having the timestamp can also work, but it's harder to tell what results you look at. This is what the tool did initially.

I will push a fix.

Leative commented 3 months ago

A student is trying to use MDEO in Eclipse on Windows. Seems like this bug still exists. Did you manage to find the cause of it?

szschaler commented 3 months ago

It looks like @alxbrd never got round to pushing the proposed fix. I expect this should't be too difficult to fix. I think all it would take is to change https://github.com/mde-optimiser/mde_optimiser/blob/201a7e5633277993933182cb31af8c83ba7a8247/libraries/core/src/main/java/uk/ac/kcl/inf/mdeoptimiser/libraries/core/optimisation/output/MDEOResultsOutput.java#L67 to

Paths.get(projectRoot.toString(), String.format("mdeo-results/experiment-%s/", moptFile.getFileName())); 

the same way as https://github.com/mde-optimiser/mde_optimiser/blob/201a7e5633277993933182cb31af8c83ba7a8247/libraries/core/src/main/java/uk/ac/kcl/inf/mdeoptimiser/libraries/core/optimisation/output/MDEOResultsOutput.java#L75

If either of you, @Leative / @alxbrd, can try this out locally on your machine, I would be happy to review and merge a PR for this.

Leative commented 3 months ago

Nicely spotted, that's definitely the problem. Unfortunately, neither Maven, Java, nor Eclipse is installed on my machine at the moment so testing this comes with some overhead. Nonetheless, I'll try to find time for it next week.

Leative commented 2 months ago

Who would have thought that fixing something in MDEO might not be as easy as just fixing a line. :)

Fixed two other issues on the way. Maybe have a short review on these as well.