From b733c442da0cf095956d7cd210b9cc7a1445e181 Mon Sep 17 00:00:00 2001 From: lucaparisi91 Date: Thu, 19 Jun 2025 18:38:48 +0100 Subject: [PATCH 1/6] Added basic R test --- tests/utils/R/R.py | 28 ++++++++++++++++++++++++++++ tests/utils/R/src/basic_benchmark.R | 25 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/utils/R/R.py create mode 100644 tests/utils/R/src/basic_benchmark.R diff --git a/tests/utils/R/R.py b/tests/utils/R/R.py new file mode 100644 index 0000000..42b26c2 --- /dev/null +++ b/tests/utils/R/R.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +""" +R benchmarks + +These tests checks that the R programming language is functional. + +""" + +import reframe as rfm +import reframe.utility.sanity as sn + +@rfm.simple_test +class RscriptBasic(rfm.RunOnlyRegressionTest): + """ A functional test of the R programming language""" + + descr = "Run a basic R script. Checks packages can be locally installed and basic functionality is present " + valid_systems = ["archer2:login"] + valid_prog_environs = ["PrgEnv-gnu"] + modules = ["cray-R"] + executable_opts = ["basic_benchmark.R"] + executable = "Rscript" + local = True + prerun_cmds = ["mkdir -p packages"] + + @sanity_function + def validate_job_run(self): + """Basic check that any output was produced and the job run until completion""" + return sn.assert_found("Success", self.stdout) diff --git a/tests/utils/R/src/basic_benchmark.R b/tests/utils/R/src/basic_benchmark.R new file mode 100644 index 0000000..bd4860f --- /dev/null +++ b/tests/utils/R/src/basic_benchmark.R @@ -0,0 +1,25 @@ +.libPaths("packages") + +install.packages("plyr",NCores=8,repos="https://www.stats.bris.ac.uk/R") +library("plyr") + +# declaring first data frame +data_frame1 <- data.frame(col1 = c(2,4,6), + col2 = c(4,6,8), + col3 = c(8,10,12), + col4 = LETTERS[1:3]) +print ("First Dataframe") +print (data_frame1) + +# declaring second data frame +data_frame2 <- data.frame(col4 = letters[1:4], + col5 = TRUE) +print ("Second Dataframe") +print (data_frame2) + +print ("Combining Dataframe") + +# binding data frames +rbind.fill(data_frame1,data_frame2) + +print("Success") \ No newline at end of file From 6fc189dc5f9f70f40ed5fc2887a921d22c879ee6 Mon Sep 17 00:00:00 2001 From: lucaparisi91 Date: Fri, 20 Jun 2025 11:59:00 +0100 Subject: [PATCH 2/6] Separated installing packages test and running a simple script test --- tests/utils/R/R.py | 57 ++++++++++++++++--- .../utils/R/src/install_benchmark_packages.R | 5 ++ .../{basic_benchmark.R => run_benchmark.R} | 2 - 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 tests/utils/R/src/install_benchmark_packages.R rename tests/utils/R/src/{basic_benchmark.R => run_benchmark.R} (85%) diff --git a/tests/utils/R/R.py b/tests/utils/R/R.py index 42b26c2..78affa0 100644 --- a/tests/utils/R/R.py +++ b/tests/utils/R/R.py @@ -8,21 +8,64 @@ import reframe as rfm import reframe.utility.sanity as sn +import os -@rfm.simple_test -class RscriptBasic(rfm.RunOnlyRegressionTest): +class RscriptBase(rfm.RunOnlyRegressionTest): """ A functional test of the R programming language""" descr = "Run a basic R script. Checks packages can be locally installed and basic functionality is present " - valid_systems = ["archer2:login"] valid_prog_environs = ["PrgEnv-gnu"] modules = ["cray-R"] - executable_opts = ["basic_benchmark.R"] - executable = "Rscript" - local = True - prerun_cmds = ["mkdir -p packages"] + executable = "Rscript" @sanity_function def validate_job_run(self): """Basic check that any output was produced and the job run until completion""" return sn.assert_found("Success", self.stdout) + + +class RscriptInstall( RscriptBase ): + """ Tests installing packages with R on the login nodes """ + + valid_systems = ["archer2:login"] + local = True + executable_opts = ["install_benchmark_packages.R"] + + @run_before("run") + def setup_R_library(self): + """ Setup R library path + + The default R library directory is on the home folder, which is not writable on the compute nodes and pollute user's environment. This sets environment variables so that packages are written/read in a local directory. + """ + + self.libs_path = os.path.join(self.stagedir, ".libs") + + self.env_vars = { + "R_LIBS_USER" : self.libs_path + } + + self.prerun_cmds = [f"mkdir -p {self.libs_path}" ] + + +@rfm.simple_test +class RscriptRun( RscriptBase ): + + """ Runs a basic R functionality test. Uses packages installed locally in a previous test.""" + + + valid_systems = ["archer2:login","archer2:compute"] + executable_opts = ["run_benchmark.R"] + library = fixture(RscriptInstall, scope="session") + + @run_before("run") + def setup_R_library(self): + """ Setup R library path + + Set the library path to where packages were installed in the R package install test. + """ + + self.libs_path = self.library.libs_path + + self.env_vars = { + "R_LIBS_USER" : self.libs_path + } \ No newline at end of file diff --git a/tests/utils/R/src/install_benchmark_packages.R b/tests/utils/R/src/install_benchmark_packages.R new file mode 100644 index 0000000..9a359c4 --- /dev/null +++ b/tests/utils/R/src/install_benchmark_packages.R @@ -0,0 +1,5 @@ + +install.packages("plyr",NCores=8,repos="https://www.stats.bris.ac.uk/R") +library(plyr) + +print("Success") \ No newline at end of file diff --git a/tests/utils/R/src/basic_benchmark.R b/tests/utils/R/src/run_benchmark.R similarity index 85% rename from tests/utils/R/src/basic_benchmark.R rename to tests/utils/R/src/run_benchmark.R index bd4860f..571c70e 100644 --- a/tests/utils/R/src/basic_benchmark.R +++ b/tests/utils/R/src/run_benchmark.R @@ -1,6 +1,4 @@ -.libPaths("packages") -install.packages("plyr",NCores=8,repos="https://www.stats.bris.ac.uk/R") library("plyr") # declaring first data frame From dc79fa288a067896dc16270225716c15892a87d5 Mon Sep 17 00:00:00 2001 From: lucaparisi91 Date: Fri, 20 Jun 2025 12:17:35 +0100 Subject: [PATCH 3/6] Formatting --- tests/utils/R/R.py | 47 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/tests/utils/R/R.py b/tests/utils/R/R.py index 78affa0..d12a5f4 100644 --- a/tests/utils/R/R.py +++ b/tests/utils/R/R.py @@ -10,13 +10,14 @@ import reframe.utility.sanity as sn import os + class RscriptBase(rfm.RunOnlyRegressionTest): - """ A functional test of the R programming language""" + """A base class for R functionality tests.""" - descr = "Run a basic R script. Checks packages can be locally installed and basic functionality is present " + descr = "A base class for R functionality tests. " valid_prog_environs = ["PrgEnv-gnu"] modules = ["cray-R"] - executable = "Rscript" + executable = "Rscript" @sanity_function def validate_job_run(self): @@ -24,48 +25,46 @@ def validate_job_run(self): return sn.assert_found("Success", self.stdout) -class RscriptInstall( RscriptBase ): - """ Tests installing packages with R on the login nodes """ +class RscriptInstall(RscriptBase): + """Tests installing packages with R on the login nodes""" + descr = "Tests that R packages can be installed locally. Requires internet access." valid_systems = ["archer2:login"] local = True executable_opts = ["install_benchmark_packages.R"] @run_before("run") def setup_R_library(self): - """ Setup R library path - - The default R library directory is on the home folder, which is not writable on the compute nodes and pollute user's environment. This sets environment variables so that packages are written/read in a local directory. + """Setup R library path + + The default R library directory is on the home folder, + which is not writable on the compute nodes and pollute user's environment. + This sets environment variables so that packages are written/read in a local directory. """ - + self.libs_path = os.path.join(self.stagedir, ".libs") - self.env_vars = { - "R_LIBS_USER" : self.libs_path - } + self.env_vars = {"R_LIBS_USER": self.libs_path} - self.prerun_cmds = [f"mkdir -p {self.libs_path}" ] + self.prerun_cmds = [f"mkdir -p {self.libs_path}"] @rfm.simple_test -class RscriptRun( RscriptBase ): +class RscriptRun(RscriptBase): + """Runs a basic R functionality test.""" - """ Runs a basic R functionality test. Uses packages installed locally in a previous test.""" - - - valid_systems = ["archer2:login","archer2:compute"] + descr = "Runs a basic R functionality test. " "Uses packages installed locally in a previous test." + valid_systems = ["archer2:login", "archer2:compute"] executable_opts = ["run_benchmark.R"] - library = fixture(RscriptInstall, scope="session") + library = fixture(RscriptInstall, scope="session") @run_before("run") def setup_R_library(self): - """ Setup R library path - + """Setup R library path + Set the library path to where packages were installed in the R package install test. """ self.libs_path = self.library.libs_path - self.env_vars = { - "R_LIBS_USER" : self.libs_path - } \ No newline at end of file + self.env_vars = {"R_LIBS_USER": self.libs_path} From 320b50bc49bf81578effb45ad65fb2d749bfe2fb Mon Sep 17 00:00:00 2001 From: lucaparisi91 Date: Fri, 20 Jun 2025 14:08:02 +0100 Subject: [PATCH 4/6] Fixed pylint complaints --- tests/utils/R/rscript.py | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/utils/R/rscript.py diff --git a/tests/utils/R/rscript.py b/tests/utils/R/rscript.py new file mode 100644 index 0000000..29fb6f7 --- /dev/null +++ b/tests/utils/R/rscript.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +""" +R benchmarks + +These tests checks that the R programming language is functional. + +""" + +import os +import reframe as rfm +import reframe.utility.sanity as sn + + +class RscriptBase(rfm.RunOnlyRegressionTest): + """A base class for R functionality tests.""" + + descr = "A base class for R functionality tests. " + valid_prog_environs = ["PrgEnv-gnu"] + modules = ["cray-R"] + executable = "Rscript" + + @sanity_function + def validate_job_run(self): + """Basic check that any output was produced and the job run until completion""" + return sn.assert_found("Success", self.stdout) + + +class RscriptInstall(RscriptBase): + """Tests installing packages with R on the login nodes""" + + descr = "Tests that R packages can be installed locally. Requires internet access." + valid_systems = ["archer2:login"] + local = True + executable_opts = ["install_benchmark_packages.R"] + libs_path = None + env_vars = {} + prerun_cmds = [] + + @run_before("run") + def setup_r_library(self): + """Setup R library path + + The default R library directory is on the home folder, + which is not writable on the compute nodes and pollute user's environment. + This sets environment variables so that packages are written/read in a local directory. + """ + + self.libs_path = os.path.join(self.stagedir, ".libs") + + self.env_vars = {"R_LIBS_USER": self.libs_path} + + self.prerun_cmds = [f"mkdir -p {self.libs_path}"] + + +@rfm.simple_test +class RscriptRun(RscriptBase): + """Runs a basic R functionality test.""" + + descr = "Runs a basic R functionality test. " \ + "Uses packages installed locally in a previous test." + valid_systems = ["archer2:login", "archer2:compute"] + executable_opts = ["run_benchmark.R"] + library = fixture(RscriptInstall, scope="session") + libs_path = None + env_vars = {} + + @run_before("run") + def setup_r_library(self): + """Setup R library path + + Set the library path to where packages were installed in the R package install test. + """ + + self.libs_path = self.library.libs_path + + self.env_vars = {"R_LIBS_USER": self.libs_path} From b7d6b1d0b37f69812645e1093e96c3dbb2ffa23f Mon Sep 17 00:00:00 2001 From: lucaparisi91 Date: Fri, 20 Jun 2025 14:19:35 +0100 Subject: [PATCH 5/6] Removed obsolete R.py --- tests/utils/R/R.py | 70 ---------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 tests/utils/R/R.py diff --git a/tests/utils/R/R.py b/tests/utils/R/R.py deleted file mode 100644 index d12a5f4..0000000 --- a/tests/utils/R/R.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python3 -""" -R benchmarks - -These tests checks that the R programming language is functional. - -""" - -import reframe as rfm -import reframe.utility.sanity as sn -import os - - -class RscriptBase(rfm.RunOnlyRegressionTest): - """A base class for R functionality tests.""" - - descr = "A base class for R functionality tests. " - valid_prog_environs = ["PrgEnv-gnu"] - modules = ["cray-R"] - executable = "Rscript" - - @sanity_function - def validate_job_run(self): - """Basic check that any output was produced and the job run until completion""" - return sn.assert_found("Success", self.stdout) - - -class RscriptInstall(RscriptBase): - """Tests installing packages with R on the login nodes""" - - descr = "Tests that R packages can be installed locally. Requires internet access." - valid_systems = ["archer2:login"] - local = True - executable_opts = ["install_benchmark_packages.R"] - - @run_before("run") - def setup_R_library(self): - """Setup R library path - - The default R library directory is on the home folder, - which is not writable on the compute nodes and pollute user's environment. - This sets environment variables so that packages are written/read in a local directory. - """ - - self.libs_path = os.path.join(self.stagedir, ".libs") - - self.env_vars = {"R_LIBS_USER": self.libs_path} - - self.prerun_cmds = [f"mkdir -p {self.libs_path}"] - - -@rfm.simple_test -class RscriptRun(RscriptBase): - """Runs a basic R functionality test.""" - - descr = "Runs a basic R functionality test. " "Uses packages installed locally in a previous test." - valid_systems = ["archer2:login", "archer2:compute"] - executable_opts = ["run_benchmark.R"] - library = fixture(RscriptInstall, scope="session") - - @run_before("run") - def setup_R_library(self): - """Setup R library path - - Set the library path to where packages were installed in the R package install test. - """ - - self.libs_path = self.library.libs_path - - self.env_vars = {"R_LIBS_USER": self.libs_path} From 5b2bd38fc6dcbf2a10b6286425680af6163f05f7 Mon Sep 17 00:00:00 2001 From: lucaparisi91 Date: Fri, 20 Jun 2025 14:24:11 +0100 Subject: [PATCH 6/6] Reformatting --- tests/utils/R/rscript.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/utils/R/rscript.py b/tests/utils/R/rscript.py index 29fb6f7..18b829d 100644 --- a/tests/utils/R/rscript.py +++ b/tests/utils/R/rscript.py @@ -56,8 +56,11 @@ def setup_r_library(self): class RscriptRun(RscriptBase): """Runs a basic R functionality test.""" - descr = "Runs a basic R functionality test. " \ - "Uses packages installed locally in a previous test." + descr = """ + Runs a basic R functionality test. + Uses packages installed locally + in a previous test. + """ valid_systems = ["archer2:login", "archer2:compute"] executable_opts = ["run_benchmark.R"] library = fixture(RscriptInstall, scope="session")