Skip to content

Commit

Permalink
refactor methods to be more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Aug 31, 2023
1 parent dd88615 commit 43a2d80
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ private Map<String, String> addCpuOrGpu(Map<String, String> suffixes){
List<DeepLearningVersion> copiesOfVersion = new ArrayList<DeepLearningVersion>();
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder();
List<String> downloadedVersions = installed.getDownloadedPythonVersionsForEngine(engine);
List<String> downloadedVersions = installed.getDownloadedPythonVersionsForFramework(engine);
String executionVersion = VersionStringUtils.getMostCompatibleEngineVersion(trainingVersion, downloadedVersions, engine);
copiesOfVersion = installed.getDownloadedForEngine(engine)
copiesOfVersion = installed.getDownloadedForFramework(engine)
.stream().filter(v -> v.getPythonVersion().equals(executionVersion)).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -247,7 +247,7 @@ private String findLocalEngine(String version, String trainingVersion) {
List<String> downloadedVersions = new ArrayList<String>();
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder();
downloadedVersions = installed.getDownloadedPythonVersionsForEngine(engine);
downloadedVersions = installed.getDownloadedPythonVersionsForFramework(engine);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/bioimage/modelrunner/engine/EngineInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,10 @@ public static EngineInfo defineCompatibleDLEngineCPU( String framework, String v
String jarsDirectory ) throws IOException, IllegalArgumentException
{
InstalledEngines manager = InstalledEngines.buildEnginesFinder(jarsDirectory);
String compatibleVersion = manager.getMostCompatibleVersionForEngine(framework, version);
String compatibleVersion = manager.getMostCompatibleVersionForFramework(framework, version);
if (compatibleVersion == null)
return null;
List<DeepLearningVersion> vv = manager.getDownloadedForVersionedEngine(framework, compatibleVersion);
List<DeepLearningVersion> vv = manager.getDownloadedForVersionedFramework(framework, compatibleVersion);
boolean gpu = vv.stream().filter(v -> v.getGPU()).findFirst().orElse(null) != null;
return EngineInfo.defineDLEngine(framework, compatibleVersion, true, gpu, jarsDirectory);
}
Expand Down Expand Up @@ -791,10 +791,10 @@ public static EngineInfo defineCompatibleDLEngineWithRdfYamlWeights(WeightFormat
String engine = weight.getWeightsFormat();
String version = weight.getTrainingVersion();
InstalledEngines manager = InstalledEngines.buildEnginesFinder(enginesDir);
compatibleVersion = manager.getMostCompatibleVersionForEngine(engine, version);
compatibleVersion = manager.getMostCompatibleVersionForFramework(engine, version);
if (compatibleVersion == null)
return null;
List<DeepLearningVersion> vv = manager.getDownloadedForVersionedEngine(engine, compatibleVersion);
List<DeepLearningVersion> vv = manager.getDownloadedForVersionedFramework(engine, compatibleVersion);
boolean gpu = vv.stream().filter(v -> v.getGPU()).findFirst().orElse(null) != null;
return EngineInfo.defineDLEngine(engine, compatibleVersion, true, gpu, enginesDir);
}
Expand Down Expand Up @@ -845,7 +845,7 @@ public static EngineInfo defineExactDLEngineWithRdfYamlWeights(WeightFormat weig
InstalledEngines manager = InstalledEngines.buildEnginesFinder(enginesDir);
if (version == null)
return null;
List<DeepLearningVersion> vv = manager.getDownloadedForVersionedEngine(engine, version);
List<DeepLearningVersion> vv = manager.getDownloadedForVersionedFramework(engine, version);
if (vv.size() == 0)
return null;
boolean gpu = vv.stream().filter(v -> v.getGPU()).findFirst().orElse(null) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public static boolean installEngineForWeightsInDir(WeightFormat ww, String engin
InstalledEngines manager = InstalledEngines.buildEnginesFinder(enginesDir);
String engine = ww.getWeightsFormat();
String version = ww.getTrainingVersion();
List<DeepLearningVersion> vs = manager.getDownloadedForVersionedEngine(engine, version);
List<DeepLearningVersion> vs = manager.getDownloadedForVersionedFramework(engine, version);
if (vs.size() != 0)
return true;
if (AvailableEngines.isEngineSupportedInOS(engine, version, true, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ public static List<DeepLearningVersion> getAll(String enginesPath)
* Creates a list containing only downloaded Deep Learning versions compatible with
* the current system and corresponding to the engine of interest
*
* @param engine
* @param framework
* name of the engine as defined with the engine tag at:
* https://raw.githubusercontent.com/bioimage-io/model-runner-java/main/src/main/resources/availableDLVersions.json
* for example tensorflow, pytorch, onnx
* @return The available versions instance.
*/
public List<DeepLearningVersion> getDownloadedForEngine(String engine) {
String searchEngine = AvailableEngines.getSupportedVersionsEngineTag(engine);
public List<DeepLearningVersion> getDownloadedForFramework(String framework) {
String searchEngine = AvailableEngines.getSupportedVersionsEngineTag(framework);
if (searchEngine == null)
return new ArrayList<DeepLearningVersion>();
return getDownloadedForOS().stream()
Expand All @@ -163,16 +163,16 @@ public List<DeepLearningVersion> getDownloadedForEngine(String engine) {
* Creates a list containing only downloaded Deep Learning versions compatible with
* the current system, corresponding to the engine of interest and corresponding version
*
* @param engine
* @param framework
* name of the engine as defined with the engine tag at:
* https://raw.githubusercontent.com/bioimage-io/model-runner-java/main/src/main/resources/availableDLVersions.json
* for example tensorflow, pytorch, onnx
* @param version
* version of interest of the engine
* @return The available versions instance.
*/
public List<DeepLearningVersion> getDownloadedForVersionedEngine(String engine, String version) {
String searchEngine = AvailableEngines.getSupportedVersionsEngineTag(engine);
public List<DeepLearningVersion> getDownloadedForVersionedFramework(String framework, String version) {
String searchEngine = AvailableEngines.getSupportedVersionsEngineTag(framework);
if (searchEngine == null)
return new ArrayList<DeepLearningVersion>();
return getDownloadedForOS().stream()
Expand All @@ -187,15 +187,15 @@ public List<DeepLearningVersion> getDownloadedForVersionedEngine(String engine,
*
* @param enginesPath
* path to where the engines are stored
* @param engine
* @param framework
* name of the engine as defined with the engine tag at:
* https://raw.githubusercontent.com/bioimage-io/model-runner-java/main/src/main/resources/availableDLVersions.json
* for example tensorflow, pytorch, onnx
* @return The available versions instance.
*/
public static List<DeepLearningVersion> getDownloadedForEngine(String enginesPath, String engine) {
public static List<DeepLearningVersion> getDownloadedForFramework(String enginesPath, String framework) {
try{
return buildEnginesFinder(enginesPath).getDownloadedForEngine(engine);
return buildEnginesFinder(enginesPath).getDownloadedForFramework(framework);
} catch (IOException ex) {
return new ArrayList<DeepLearningVersion>();
}
Expand Down Expand Up @@ -238,12 +238,12 @@ public static List<DeepLearningVersion> getDownloadedForOS(String enginesPath) {
* Return a list of all the downloaded Python versions of the corresponding engine
* are installed in the local machine
*
* @param engine
* @param framework
* the engine of interest
* @return the list of deep learning versions for the given engine
*/
public List<String> getDownloadedPythonVersionsForEngine(String engine) {
return getDownloadedForEngine(engine).stream()
public List<String> getDownloadedPythonVersionsForFramework(String framework) {
return getDownloadedForFramework(framework).stream()
.map(DeepLearningVersion::getPythonVersion).collect(Collectors.toList());
}

Expand All @@ -253,13 +253,13 @@ public List<String> getDownloadedPythonVersionsForEngine(String engine) {
*
* @param enginesPath
* path to where the engines are stored
* @param engine
* @param framework
* the engine of interest
* @return the list of deep learning versions for the given engine
*/
public static List<String> getDownloadedPythonVersionsForEngine(String enginesPath, String engine) {
public static List<String> getDownloadedPythonVersionsForFramework(String enginesPath, String framework) {
try{
return buildEnginesFinder(enginesPath).getDownloadedPythonVersionsForEngine(engine);
return buildEnginesFinder(enginesPath).getDownloadedPythonVersionsForFramework(framework);
} catch (IOException ex) {
return new ArrayList<String>();
}
Expand Down Expand Up @@ -290,24 +290,24 @@ public static void setEnginesDirectory(String dir) throws IOException {
* For a specific Deep Learning framework, specified by the parameter
* engine, and a specific version of interest, return the closest existing
* version among the installed ones for the DL framework
* @param engine
* @param framework
* the engine of interest
* Deep Learning framework (tensorflow, pytorch, onnx...) as defined with the engine tag
* at https://raw.githubusercontent.com/bioimage-io/model-runner-java/main/src/main/resources/availableDLVersions.json
* @param version
* the version of interest
* @return the closest version to the version provided for the engine provided
*/
public String getMostCompatibleVersionForEngine(String engine, String version) {
List<String> downloadedVersions = getDownloadedPythonVersionsForEngine(engine);
return VersionStringUtils.getMostCompatibleEngineVersion(version, downloadedVersions, engine);
public String getMostCompatibleVersionForFramework(String framework, String version) {
List<String> downloadedVersions = getDownloadedPythonVersionsForFramework(framework);
return VersionStringUtils.getMostCompatibleEngineVersion(version, downloadedVersions, framework);
}

/**
* For a specific Deep Learning framework, specified by the parameter
* engine, and a specific version of interest, return the closest existing
* version among the installed ones for the DL framework
* @param engine
* @param framework
* the engine of interest
* Deep Learning framework (tensorflow, pytorch, onnx...) as defined with the engine tag
* at https://raw.githubusercontent.com/bioimage-io/model-runner-java/main/src/main/resources/availableDLVersions.json
Expand All @@ -317,11 +317,11 @@ public String getMostCompatibleVersionForEngine(String engine, String version) {
* path to where the engines are stored
* @return the closest version to the version provided for the engine provided
*/
public static String getMostCompatibleVersionForEngine(String engine, String version, String enginesDir) {
public static String getMostCompatibleVersionForFramework(String framework, String version, String enginesDir) {
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder(enginesDir);
List<String> downloadedVersions = installed.getDownloadedPythonVersionsForEngine(engine);
return VersionStringUtils.getMostCompatibleEngineVersion(version, downloadedVersions, engine);
List<String> downloadedVersions = installed.getDownloadedPythonVersionsForFramework(framework);
return VersionStringUtils.getMostCompatibleEngineVersion(version, downloadedVersions, framework);
} catch (IOException e) {
return null;
}
Expand All @@ -331,7 +331,7 @@ public static String getMostCompatibleVersionForEngine(String engine, String ver
* Returns a list of all the installed engine versions that are compatible
* with the versioned engine provided in the input parameters.
*
* @param engine
* @param framework
* name of the DL framework of interest
* @param version
* original version we are looking for compatibles
Expand All @@ -340,46 +340,46 @@ public static String getMostCompatibleVersionForEngine(String engine, String ver
* @return a list of all the string versions compatible
* with the provided versioned engine
*/
public static List<String> getOrderedListOfCompatibleVesionsForEngine(String engine,
public static List<String> getOrderedListOfCompatibleVesionsForFramework(String framework,
String version, String enginesDir) {
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder(enginesDir);
List<String> downloadedVersions = installed.getDownloadedPythonVersionsForEngine(engine);
return VersionStringUtils.getCompatibleEngineVersionsInOrder(version, downloadedVersions, engine);
List<String> downloadedVersions = installed.getDownloadedPythonVersionsForFramework(framework);
return VersionStringUtils.getCompatibleEngineVersionsInOrder(version, downloadedVersions, framework);
} catch (IOException e) {
return null;
}
}

/**
* Check whether the engine version of interest is installed or not
* @param engine
* @param framework
* DL framework of interest
* @param version
* version of the DL framework
* @return true if it is installed and false otherwise
*/
public boolean checkEngineVersionInstalled(String engine, String version) {
List<String> downloadedVersions = getDownloadedPythonVersionsForEngine(engine);
public boolean checkFrameworkVersionInstalled(String framework, String version) {
List<String> downloadedVersions = getDownloadedPythonVersionsForFramework(framework);
String v = downloadedVersions.stream()
.filter(vv -> vv.equals(version)).findFirst().orElse(null);
return v != null;
}

/**
* Check whether the engine version of interest is installed or not
* @param engine
* @param framework
* DL framework of interest
* @param version
* version of the DL framework
* @param enginesDir
* directory where all the engines are located
* @return true if it is installed and false otherwise
*/
public static boolean checkEngineVersionInstalled(String engine, String version, String enginesDir) {
public static boolean checkFrameworkVersionInstalled(String framework, String version, String enginesDir) {
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder(enginesDir);
return installed.checkEngineVersionInstalled(engine, version);
return installed.checkFrameworkVersionInstalled(framework, version);
} catch (IOException e) {
return false;
}
Expand All @@ -395,7 +395,7 @@ public static boolean checkEngineVersionInstalled(String engine, String version,
* the resulting list of engines will contain both engines that support and do not support GPU.
*
*
* @param engine
* @param framework
* the name of the DL framework. Can be null.
* @param version
* the version of the DL framework in Python. Can be null.
Expand All @@ -410,14 +410,14 @@ public static boolean checkEngineVersionInstalled(String engine, String version,
* minimum Java version that the engine needs to work. Can be null.
* @return a list containing a list of installed engiens satisfying the constraints
*/
public List<DeepLearningVersion> checkEngineWithArgsInstalled(String engine,
public List<DeepLearningVersion> checkEngineWithArgsInstalled(String framework,
String version, Boolean cpu, Boolean gpu, Boolean rosetta, Integer minJavaVersion) {
String searchEngine;
if (engine != null)
searchEngine = AvailableEngines.getSupportedVersionsEngineTag(engine);
if (framework != null)
searchEngine = AvailableEngines.getSupportedVersionsEngineTag(framework);
else
searchEngine = null;
if (searchEngine == null && engine != null)
if (searchEngine == null && framework != null)
return new ArrayList<DeepLearningVersion>();
List<DeepLearningVersion> filtered = getDownloadedForOS().stream().filter(vv ->{
if (searchEngine != null && !vv.getFramework().toLowerCase().equals(searchEngine))
Expand Down Expand Up @@ -448,7 +448,7 @@ else if (rosetta != null && rosetta == true && vv.getRosetta() != rosetta)
*
* The ONLY PARAMETER THAT CANNOT BE NULL IS: enginesDir
*
* @param engine
* @param framework
* the name of the DL framework. Can be null.
* @param version
* the version of the DL framework in Python. Can be null.
Expand All @@ -465,13 +465,13 @@ else if (rosetta != null && rosetta == true && vv.getRosetta() != rosetta)
* the directory where all the engines are stored. CANNOT BE NULL.
* @return a list containing a list of installed engiens satisfying the constraints
*/
public static List<DeepLearningVersion> checkEngineWithArgsInstalled(String engine,
public static List<DeepLearningVersion> checkEngineWithArgsInstalled(String framework,
String version, Boolean cpu, Boolean gpu, Boolean rosetta,
Integer minJavaVersion, String enginesDir) {
Objects.requireNonNull(enginesDir);
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder(enginesDir);
return installed.checkEngineWithArgsInstalled(engine, version,
return installed.checkEngineWithArgsInstalled(framework, version,
cpu, gpu, rosetta, minJavaVersion);
} catch (IOException e) {
return new ArrayList<DeepLearningVersion>();
Expand All @@ -490,7 +490,7 @@ public static List<DeepLearningVersion> checkEngineWithArgsInstalled(String engi
* the resulting list of engines will contain both engines that support and do not support GPU.
*
*
* @param engine
* @param framework
* the name of the DL framework. Can be null.
* @param version
* the version of the DL framework in Python. Can be null.
Expand All @@ -500,11 +500,11 @@ public static List<DeepLearningVersion> checkEngineWithArgsInstalled(String engi
* whether it supports running on GPU or not. Can be null.
* @return a list containing a list of installed engiens satisfying the constraints
*/
public List<DeepLearningVersion> checkEngineWithArgsInstalledForOS(String engine,
public List<DeepLearningVersion> checkEngineWithArgsInstalledForOS(String framework,
String version, Boolean cpu, Boolean gpu) {
int javaVersion = PlatformDetection.getJavaVersion();
boolean rosetta = new PlatformDetection().isUsingRosseta();
return checkEngineWithArgsInstalled(engine, version, cpu, gpu,
return checkEngineWithArgsInstalled(framework, version, cpu, gpu,
rosetta, javaVersion);
}

Expand All @@ -521,7 +521,7 @@ public List<DeepLearningVersion> checkEngineWithArgsInstalledForOS(String engine
*
* The ONLY PARAMETER THAT CANNOT BE NULL IS: enginesDir
*
* @param engine
* @param framework
* the name of the DL framework. Can be null.
* @param version
* the version of the DL framework in Python. Can be null.
Expand All @@ -533,12 +533,12 @@ public List<DeepLearningVersion> checkEngineWithArgsInstalledForOS(String engine
* the directory where all the engines are stored. CANNOT BE NULL.
* @return a list containing a list of installed engiens satisfying the constraints
*/
public static List<DeepLearningVersion> checkEngineWithArgsInstalledForOS(String engine,
public static List<DeepLearningVersion> checkEngineWithArgsInstalledForOS(String framework,
String version, Boolean cpu, Boolean gpu, String enginesDir) {
Objects.requireNonNull(enginesDir);
try {
InstalledEngines installed = InstalledEngines.buildEnginesFinder(enginesDir);
return installed.checkEngineWithArgsInstalledForOS(engine, version,
return installed.checkEngineWithArgsInstalledForOS(framework, version,
cpu, gpu);
} catch (IOException e) {
return new ArrayList<DeepLearningVersion>();
Expand Down

0 comments on commit 43a2d80

Please sign in to comment.