Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ op.csv
covs.csv
error_theta.csv
lcov.info
Fortran/
Fortran/
result.json
1 change: 1 addition & 0 deletions examples/bimodal_ke/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Ok(())
}
17 changes: 16 additions & 1 deletion src/routines/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,22 @@ impl<E: Equation> NPResult<E> {
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<()> {
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signature uses &mut self, but the method doesn't mutate any fields of the struct - it only serializes the current state. Based on the documentation comment stating this method will not calculate predictions automatically, and the pattern used by other non-mutating write methods like write_theta and write_covs, this should use &self instead of &mut self.

Suggested change
pub fn write_json(&mut self) -> Result<()> {
pub fn write_json(&self) -> Result<()> {

Copilot uses AI. Check for mistakes.
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")?;
Expand Down
Loading