Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Prophet functionality to augurs-js #125

Merged
merged 1 commit into from
Oct 15, 2024
Merged

feat: add Prophet functionality to augurs-js #125

merged 1 commit into from
Oct 15, 2024

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Oct 15, 2024

This adds Javascript bindings for the augurs-prophet crate as part of the augurs Javascript library.

When creating the Prophet object, an optimizer must be provided by the user. This is to avoid having a hard dependency on the Stan WASM module which increases the size of the augurs WASM blob significantly and won't be needed for users not using Prophet.

Summary by CodeRabbit

  • New Features

    • Introduced a new time-series forecasting model, Prophet, enhancing predictive capabilities.
    • Added new dependencies for improved functionality and integration with existing features.
    • Added a new module and structures for optimizing JavaScript integration.
  • Improvements

    • Enhanced optimization process for the Prophet model with additional configuration options.
    • Updated WebAssembly configuration for improved performance.
    • Simplified serialization logic for data structures to streamline functionality.
  • Bug Fixes

    • Improved visibility and access control for certain modules.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes introduce several updates across the augurs-js and augurs-prophet packages. A new dependency, augurs-prophet, is added to Cargo.toml with the serde feature. The wasm-opt configuration is enhanced with additional optimization flags. A new module, prophet, is added to lib.rs, along with a new file prophet.rs that implements the Prophet time-series forecasting model. Modifications in optimizer.rs include changes to module visibility and serialization logic for the OptimizeOpts structure.

Changes

File Path Change Summary
crates/augurs-js/Cargo.toml - Added new dependencies: augurs-prophet = { workspace = true, features = ["serde"] } and tracing.workspace = true.
- Updated wasm-opt configuration: added --enable-bulk-memory, --enable-threads to existing flags.
crates/augurs-js/src/lib.rs - Added new module: mod prophet;
crates/augurs-js/src/prophet.rs - Enhanced Prophet model with new structures and methods including JsOptimizer and various data handling features.
- Added multiple structs, enums, and methods for model functionality.
crates/augurs-prophet/src/optimizer.rs - Changed visibility of mock_optimizer from pub to pub(crate).
- Updated serde::Serialize implementation for XSerializer.
- Added new field refresh to OptimizeOpts.

Possibly related PRs

Poem

In the garden where data grows,
A prophet whispers, and wisdom flows.
With new flags and modules bright,
We forecast futures, taking flight.
Optimization's gentle hand,
Guides our models across the land. 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (2)
crates/augurs-prophet/src/optimizer.rs (1)

Line range hint 139-157: Approved: Simplified lifetime parameter in XSerializer

The change from XSerializer<'a> to XSerializer<'_> simplifies the lifetime management without altering the functionality. This is a good improvement that makes the code more concise.

Consider adding a brief comment explaining the purpose of XSerializer, as it's a crucial part of the serialization process for the Data struct. For example:

/// XSerializer serializes X (a flat slice of f64s) as a sequence of sequences,
/// where each inner sequence has a length equal to K (number of regressors).
impl serde::Serialize for XSerializer<'_> {
    // ... (rest of the implementation)
}
crates/augurs-js/src/prophet.rs (1)

381-396: Validate deserialized OptimizedParams data

When deserializing floating-point values in OptimizedParams, consider validating the data to ensure they are within expected ranges and constraints. This is crucial for maintaining the accuracy and reliability of the model.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2e75057 and 57be5e3.

📒 Files selected for processing (4)
  • crates/augurs-js/Cargo.toml (2 hunks)
  • crates/augurs-js/src/lib.rs (1 hunks)
  • crates/augurs-js/src/prophet.rs (1 hunks)
  • crates/augurs-prophet/src/optimizer.rs (2 hunks)
🧰 Additional context used
🔇 Additional comments (4)
crates/augurs-js/Cargo.toml (2)

33-33: LGTM: New dependency added correctly.

The addition of the augurs-prophet dependency with the serde feature is consistent with the PR objectives and follows the existing pattern for workspace dependencies.


49-51: LGTM: Enhanced WASM optimization, but clarification needed.

The addition of --enable-bulk-memory and --enable-threads flags to the wasm-opt configuration is likely to improve performance and enable necessary features for the new Prophet functionality.

However, given the PR's emphasis on keeping the library lightweight, could you please clarify:

  1. The expected impact of these new flags on the WASM blob size?
  2. Are these flags necessary for all use cases, or only when using the Prophet functionality?

To help assess the impact, let's compare the WASM blob sizes before and after this change:

crates/augurs-prophet/src/optimizer.rs (2)

301-301: Approved: Improved module visibility

The change from pub mod to pub(crate) mod for mock_optimizer is a good practice. It restricts the visibility of test-related code to within the current crate, preventing unintended usage outside the crate.


Line range hint 1-430: Summary: Improvements in code organization and serialization

The changes in this file contribute positively to the integration of Prophet functionality into the augurs JavaScript library. The modifications improve code organization by restricting the visibility of test-related code and simplify the serialization logic. These changes align well with the PR objectives and maintain the flexibility of allowing users to provide their own optimizer, which is crucial for preventing a hard dependency on the Stan WASM module.

crates/augurs-js/src/lib.rs Show resolved Hide resolved
crates/augurs-js/src/prophet.rs Show resolved Hide resolved
crates/augurs-js/src/prophet.rs Show resolved Hide resolved
crates/augurs-js/src/prophet.rs Show resolved Hide resolved
crates/augurs-js/src/prophet.rs Show resolved Hide resolved
@sd2k sd2k force-pushed the prophet-js branch 3 times, most recently from d387c6c to de18a0b Compare October 15, 2024 16:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
crates/augurs-prophet/src/optimizer.rs (1)

229-230: LGTM: Added refresh field to OptimizeOpts

The addition of the refresh field to OptimizeOpts is a valuable enhancement. It provides users with more control over the optimization process by allowing them to specify how frequently convergence statistics should be emitted.

The use of Option<u32> is appropriate, making the field optional. The documentation clearly explains the purpose of the field.

Consider adding a brief example in the documentation to illustrate how this field might be used, e.g., "Setting this to Some(100) would emit statistics every 100 iterations."

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 57be5e3 and d387c6c.

📒 Files selected for processing (4)
  • crates/augurs-js/Cargo.toml (2 hunks)
  • crates/augurs-js/src/lib.rs (1 hunks)
  • crates/augurs-js/src/prophet.rs (1 hunks)
  • crates/augurs-prophet/src/optimizer.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/augurs-js/Cargo.toml
  • crates/augurs-js/src/lib.rs
🧰 Additional context used
🔇 Additional comments (27)
crates/augurs-prophet/src/optimizer.rs (3)

Line range hint 139-159: LGTM: Simplified lifetime parameter in XSerializer

The change from XSerializer<'a> to XSerializer<'_> is a good simplification. It leverages Rust's lifetime elision rules without changing the behavior of the serializer. This change improves code readability while maintaining the correct and efficient serialization logic.


303-303: LGTM: Restricted visibility of mock_optimizer module

The change from pub mod mock_optimizer to pub(crate) mod mock_optimizer is a good improvement. It restricts the visibility of the test-related code to within the crate, which is a best practice for maintaining clear boundaries between production and test code. This change enhances the module's encapsulation without affecting its functionality for testing purposes.


Line range hint 1-458: Overall assessment: Changes align well with PR objectives

The changes in this file successfully contribute to the introduction of Prophet functionality in the augurs-js library. Key improvements include:

  1. Simplified lifetime parameter in XSerializer, enhancing code readability.
  2. Restricted visibility of the mock_optimizer module, improving encapsulation.
  3. Added refresh field to OptimizeOpts, providing more control over the optimization process.

These changes align well with the PR objectives of introducing Prophet functionality and refining the module structure. They enhance the library's capabilities while maintaining good coding practices and encapsulation.

crates/augurs-js/src/prophet.rs (24)

1-2: LGTM!

The imports are relevant and necessary for the functionality in this file.


55-57: Consider making JsOptimizer struct public

The JsOptimizer struct is currently private. If there is a need to access it from other modules or for testing purposes, consider making it public by adding pub before struct.


59-87: LGTM!

The Optimizer trait implementation for JsOptimizer looks good. It correctly converts the input parameters to the expected types, calls the JavaScript optimizer function, and converts the output back to the expected Rust types.


89-116: Excellent documentation and example!

The documentation for the Prophet struct is comprehensive and includes a clear example of how to use it from JavaScript. This will be very helpful for users of the library.


122-152: LGTM!

The Prophet struct implementation looks good:

  • The new method correctly converts the ProphetOptions to the expected types and creates a new Prophet instance.
  • The fit method converts the TrainingData and calls the fit method on the inner Prophet instance.
  • The predict method optionally converts the PredictionData and calls the predict method on the inner Prophet instance, converting the output to the expected type.

157-211: LGTM!

The OptimizeOpts struct and its From implementation for augurs_prophet::optimizer::OptimizeOpts look good. All the fields are correctly converted.


213-250: Review the use of unsafe blocks

These lines use unsafe to create views of slices:

let delta = unsafe { Float64Array::view(&params.delta) };  
let beta = unsafe { Float64Array::view(&params.beta) };

Ensure that the lifetime of the data is correctly managed and that there are no potential memory safety issues. If possible, consider using safe abstractions to avoid unsafe code.


252-273: LGTM!

The Algorithm enum and its From implementation for augurs_prophet::Algorithm look good. The variants are correctly converted.


275-296: LGTM!

The TrendIndicator enum and its From implementation for augurs_prophet::TrendIndicator look good. The variants are correctly converted.


298-391: LGTM!

The Data struct and its From implementation for &augurs_prophet::optimizer::Data look good:

  • The sigmas field is correctly converted from a slice to a Float64Array.
  • The other fields are correctly converted using unsafe to create views of the input slices. The lifetimes are tied to the input Data to ensure memory safety.

393-459: LGTM!

The Logs struct and its emit method look good:

  • The struct fields capture the different log levels.
  • The emit method correctly emits the logs using the tracing macros at the appropriate log levels.
  • The ConvergenceLog parsing logic looks correct and emits structured logs for easier analysis.

461-502: LGTM!

The OptimizeOutput, OptimizedParams structs and the From implementation for augurs_prophet::optimizer::OptimizedParams look good. The fields are correctly converted.


504-546: LGTM!

The TrainingData struct and its TryFrom implementation for augurs_prophet::TrainingData look good:

  • The struct fields capture all the necessary data for training.
  • The TryFrom implementation correctly converts the fields and applies them to a new augurs_prophet::TrainingData instance.

548-591: LGTM!

The PredictionData struct and its TryFrom implementation for augurs_prophet::PredictionData look good:

  • The struct fields capture all the necessary data for prediction, mirroring the structure of TrainingData.
  • The TryFrom implementation correctly converts the fields and applies them to a new augurs_prophet::PredictionData instance.

593-625: LGTM!

The FeaturePrediction struct and its From implementation for augurs_prophet::FeaturePrediction look good. The fields are correctly converted.


627-708: LGTM!

The Predictions struct and its From implementation for augurs_prophet::Predictions look good:

  • The struct fields capture all the different components of the prediction.
  • The From implementation correctly converts all the fields, including the maps of seasonalities, holidays, and regressors.

710-919: Enhance type safety for the optimizer field

In the ProphetOptions struct, the optimizer field is defined as js_sys::Object:

#[tsify(type = "Optimizer")]
pub optimizer: js_sys::Object,

Consider specifying a more precise type or interface to enforce stricter type safety. This will help prevent misuse and improve the developer experience by providing better compile-time checks.


921-943: LGTM!

The GrowthType enum and its From implementation for augurs_prophet::GrowthType look good. The variants are correctly converted.


945-980: LGTM!

The SeasonalityOption enum and its TryFrom implementation for augurs_prophet::SeasonalityOption look good:

  • The enum variants capture the different options for specifying seasonality.
  • The TryFrom implementation correctly converts the variants, using try_into to convert the Fourier variant's argument.

982-1001: LGTM!

The Scaling enum and its From implementation for augurs_prophet::Scaling look good. The variants are correctly converted.


1003-1032: LGTM!

The EstimationMode enum and its From implementation for augurs_prophet::EstimationMode look good:

  • The enum variants capture the different options for parameter estimation.
  • The From implementation correctly converts the variants.
  • The commented out Mcmc variant and the note about it not being implemented yet are clear and helpful.

1034-1053: LGTM!

The FeatureMode enum and its From implementation for augurs_prophet::FeatureMode look good. The variants are correctly converted.


1055-1099: LGTM!

The Holiday struct and its TryFrom implementation for augurs_prophet::Holiday look good:

  • The struct fields capture all the necessary data for defining a holiday.
  • The TryFrom implementation correctly converts the fields and applies them to a new augurs_prophet::Holiday instance using the builder pattern.

1101-1136: LGTM!

The ConvergenceLog struct and its new method look good:

  • The struct fields capture the relevant data for a convergence log line.
  • The new method correctly parses a log line into a ConvergenceLog instance, handling missing fields gracefully.

This adds Javascript bindings for the augurs-prophet crate
as part of the augurs Javascript library.

When creating the Prophet object, an optimizer must be
provided by the user. This is to avoid having a hard dependency
on the Stan WASM module which increases the size of the augurs
WASM blob significantly and won't be needed for users not using
Prophet.
@sd2k sd2k enabled auto-merge (squash) October 15, 2024 16:39
@sd2k sd2k merged commit cc1033b into main Oct 15, 2024
19 checks passed
@sd2k sd2k deleted the prophet-js branch October 15, 2024 16:44
@sd2k sd2k mentioned this pull request Oct 15, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
crates/augurs-prophet/src/optimizer.rs (1)

229-230: LGTM: Added 'refresh' field to OptimizeOpts struct.

The addition of the refresh field to the OptimizeOpts struct is a good enhancement. It allows users to specify how frequently convergence statistics should be emitted during the optimization process. Some observations:

  1. The field is optional (Option<u32>), maintaining backward compatibility.
  2. The comment clearly explains the purpose of the field.

Consider slightly rewording the comment for clarity:

-    /// How frequently to emit convergence statistics, in number of iterations.
+    /// Specifies how frequently (in number of iterations) to emit convergence statistics.

This minor change makes the comment more explicit about the unit of measurement for the refresh value.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d387c6c and 3ea63c4.

📒 Files selected for processing (4)
  • crates/augurs-js/Cargo.toml (1 hunks)
  • crates/augurs-js/src/lib.rs (1 hunks)
  • crates/augurs-js/src/prophet.rs (1 hunks)
  • crates/augurs-prophet/src/optimizer.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/augurs-js/src/lib.rs
🧰 Additional context used
🔇 Additional comments (13)
crates/augurs-js/Cargo.toml (2)

32-32: LGTM: Addition of augurs-prophet dependency

The addition of the augurs-prophet dependency with the serde feature is consistent with the PR objectives. This change enables the integration of the Prophet functionality into the augurs JavaScript library.


44-47: LGTM with a question: Update to wasm-opt configuration

The addition of --enable-bulk-memory and --enable-threads flags to the wasm-opt configuration is a good improvement for performance. However, I have a question about the --enable-threads flag:

  1. How does enabling threads align with the goal of keeping the library lightweight?
  2. Does this have any implications for the library's usage or potential increase in the WASM blob size?

Could you please provide more information on the impact of enabling threads in the context of this library?

#!/bin/bash
# Description: Check for thread-related code in the codebase

# Test: Search for thread-related imports or usage in Rust files
rg --type rust -e 'use std::thread' -e 'spawn\(' -e 'parallel'
crates/augurs-prophet/src/optimizer.rs (3)

Line range hint 139-159: LGTM: Simplified lifetime syntax in XSerializer implementation.

The change from impl serde::Serialize for XSerializer<'a> to impl serde::Serialize for XSerializer<'_> is a good simplification. It uses an elided lifetime ('_) instead of an explicit one ('a). This change:

  1. Improves code readability without altering functionality.
  2. Lets the Rust compiler infer the appropriate lifetime.
  3. Follows modern Rust best practices for lifetime elision.

303-303: LGTM: Restricted visibility of mock_optimizer module.

The change from pub mod mock_optimizer to pub(crate) mod mock_optimizer is a good improvement in module visibility control. This change:

  1. Restricts the visibility of the mock_optimizer module to the current crate only.
  2. Aligns with the principle of least privilege, exposing only what's necessary.
  3. Improves encapsulation of test-related code, preventing unintended use outside the crate.

This modification enhances the overall structure of the codebase by clearly separating test utilities from the public API.


Line range hint 1-458: Overall assessment: Well-implemented changes that improve the codebase.

This review covered three main changes:

  1. Simplified lifetime syntax in XSerializer implementation.
  2. Addition of the 'refresh' field to OptimizeOpts struct.
  3. Restricted visibility of the mock_optimizer module.

All changes have been approved, with minor suggestions for improvement where applicable. These modifications enhance the flexibility, readability, and structure of the codebase without introducing any significant issues or concerns.

crates/augurs-js/src/prophet.rs (8)

117-152: Well-implemented Prophet struct and its methods

The Prophet struct along with its methods new, fit, and predict are correctly defined with appropriate error handling and WASM bindings. The integration facilitates seamless usage from JavaScript, adhering to the intended design.


393-459: Efficient log emission in Logs::emit method

The emit method in the Logs struct effectively processes and categorizes log messages based on severity, ensuring that logs are appropriately routed. This assists in diagnostics and maintains clarity in output.


498-502: Correct conversion in From<OptimizedParams> implementation

The implementation of From<OptimizedParams> correctly maps the fields to augurs_prophet::optimizer::OptimizedParams, ensuring accurate data transfer between structures.


527-546: Robust data conversion in TryFrom<TrainingData> implementation

The TryFrom implementation for TrainingData meticulously handles optional fields and propagates errors appropriately. This ensures that any issues with the input data are caught early, promoting data integrity.


861-918: Thorough configuration parsing in TryFrom<ProphetOptions>

The TryFrom implementation for ProphetOptions efficiently converts user-provided options into internal configuration, including proper error handling for each field. This design enhances the flexibility and usability of the API.


275-296: Clear definition of TrendIndicator enum

The TrendIndicator enum is well-defined, providing clear options for trend types, and the From implementation ensures seamless conversion from internal representations.


981-1000: Consistent usage of Scaling enum

The Scaling enum and its implementation correctly represent the scaling options, following consistent naming conventions and providing straightforward integration with the internal scaling mechanism.


298-391: Safe handling of lifetime in Data struct conversion

The use of unsafe blocks in creating views for the Float64Array and Int32Array is justified with detailed comments explaining the lifetime management, ensuring memory safety.

augurs-seasons = { workspace = true }
console_error_panic_hook = "0.1.7"
getrandom = { version = "0.2.10", features = ["js"] }
js-sys = "0.3.64"
serde.workspace = true
serde-wasm-bindgen = "0.6.0"
tracing.workspace = true
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Clarification Needed: Usage of tracing Dependency

The tracing workspace dependency does not appear to be actively used in the codebase based on the current search results. Could you please confirm its intended purpose or consider removing it if it's not required?

🔗 Analysis chain

LGTM: Addition of tracing as a workspace dependency

The addition of tracing as a workspace dependency is a good practice for maintaining consistent versions across the workspace. However, this change was not mentioned in the PR objectives or summary.

Could you please clarify the purpose of adding the tracing dependency to this package? Is it related to the Prophet functionality, or is it a separate improvement?

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for tracing usage in the codebase

# Test: Search for tracing usage in Rust files
rg --type rust 'use tracing::'

Length of output: 3693

Comment on lines +1100 to +1135
/// Struct representing a convergence log line, such as
/// ` 718 140.457 7.62967e-09 191.549 0.8667 0.8667 809`
struct ConvergenceLog<'a> {
iter: usize,
log_prob: f64,
dx: f64,
grad: f64,
alpha: f64,
alpha0: f64,
evals: usize,
notes: &'a str,
}

impl<'a> ConvergenceLog<'a> {
fn new(s: &'a str) -> Option<Self> {
let mut split = s.split_whitespace();
let iter = split.next()?.parse::<usize>().ok()?;
let log_prob = split.next()?.parse::<f64>().ok()?;
let dx = split.next()?.parse::<f64>().ok()?;
let grad = split.next()?.parse::<f64>().ok()?;
let alpha = split.next()?.parse::<f64>().ok()?;
let alpha0 = split.next()?.parse::<f64>().ok()?;
let evals = split.next()?.parse::<usize>().ok()?;
let notes = split.next().unwrap_or_default();
Some(Self {
iter,
log_prob,
dx,
grad,
alpha,
alpha0,
evals,
notes,
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling in ConvergenceLog::new method

The ConvergenceLog::new function returns None silently if parsing fails due to unexpected input formats. Consider adding detailed error messages or logging to aid in debugging, which will make it easier to trace issues if the optimizer outputs malformed log lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant