From 64e02a02e88ea0ca82d5ca5d4be6a0c3296bbaec Mon Sep 17 00:00:00 2001 From: Markus Date: Wed, 28 Jan 2026 18:32:30 +0100 Subject: [PATCH 1/3] feat: Add method to write NPresult to JSON --- examples/bimodal_ke/main.rs | 1 + src/routines/output/mod.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/bimodal_ke/main.rs b/examples/bimodal_ke/main.rs index bbd92febe..580b96a11 100644 --- a/examples/bimodal_ke/main.rs +++ b/examples/bimodal_ke/main.rs @@ -50,6 +50,7 @@ fn main() -> Result<()> { let mut algorithm = dispatch_algorithm(settings, eq, data)?; let mut result = algorithm.fit()?; result.write_outputs()?; + result.write_json(true)?; Ok(()) } diff --git a/src/routines/output/mod.rs b/src/routines/output/mod.rs index 2a9e43d69..5eb5b9f90 100644 --- a/src/routines/output/mod.rs +++ b/src/routines/output/mod.rs @@ -436,7 +436,22 @@ impl NPResult { Ok(()) } - /// Writes the covariates + /// Writes the entire NPResult to a JSON file + /// + /// This will not calculate predictions automatically, to do so, call [NPResult::calculate_predictions] first + pub fn write_json(&mut self) -> Result<()> { + tracing::debug!("Writing NPResult to JSON..."); + + let outputfile = OutputFile::new(&self.settings.output().path, "result.json") + .context("Failed to create output file for JSON")?; + + serde_json::to_writer_pretty(&outputfile.file, self) + .context("Failed to serialize NPResult to JSON")?; + + tracing::debug!("NPResult written to {:?}", &outputfile.relative_path()); + Ok(()) + } + pub fn write_covs(&self) -> Result<()> { tracing::debug!("Writing covariates..."); let outputfile = OutputFile::new(&self.settings.output().path, "covs.csv")?; From b343900f57e04d6fb5dfbe6af3b155a3256ac318 Mon Sep 17 00:00:00 2001 From: Markus Date: Wed, 28 Jan 2026 18:32:52 +0100 Subject: [PATCH 2/3] fix: Remove unused argument --- examples/bimodal_ke/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bimodal_ke/main.rs b/examples/bimodal_ke/main.rs index 580b96a11..939add61b 100644 --- a/examples/bimodal_ke/main.rs +++ b/examples/bimodal_ke/main.rs @@ -50,7 +50,7 @@ fn main() -> Result<()> { let mut algorithm = dispatch_algorithm(settings, eq, data)?; let mut result = algorithm.fit()?; result.write_outputs()?; - result.write_json(true)?; + result.write_json()?; Ok(()) } From dd10a6e5fdc45b46eda9af61f4c6fa0e25b5ae55 Mon Sep 17 00:00:00 2001 From: Markus Date: Sun, 1 Feb 2026 10:09:05 +0100 Subject: [PATCH 3/3] Ignore result.json --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 802b1ab3c..9cc7438bc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ op.csv covs.csv error_theta.csv lcov.info -Fortran/ \ No newline at end of file +Fortran/ +result.json