Refactor/extract standalone functions from structure#367
Conversation
…zation, and training modules to `pub(crate)` for better encapsulation.
…'test_' to enhance clarity and maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This is a solid refactoring pull request that significantly improves the modularity and overall quality of the codebase. Extracting current_retrievability into a standalone function is a great move for better API design. The accompanying changes, such as adjusting visibility for better encapsulation, simplifying function signatures, and renaming tests for consistency, are all well-executed and contribute to a cleaner, more maintainable codebase. The major version bump is appropriate for the breaking API changes. I have one minor suggestion to remove a redundant import.
|
Could you wait for me to implement the per-card DR + (maybe) per-card parameters(?) for the simulator before you publish the next major version? I might wait for this to merge first so that there are no potential merge conflicts . |
|
I will merge this PR and wait for your PR. The next release will not come soon. |
There was a problem hiding this comment.
Should evaluate_with_time_series_splits and optimal_retention be made standalone?
also should we remove the Option in
Line 256 in 1e27198
if the intention is that there are no functions that don't require parameters?
…und parameters in multiple files, enhancing code clarity and consistency.
…ult()` instead of `FSRS::new(&[])`, improving code consistency and readability.
…fault()`, ensuring consistency and improving code readability.
…roving consistency and reducing redundancy in multiple test files.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a significant and well-executed refactoring that improves the modularity and API design of the fsrs crate. By extracting standalone functions from the FSRS struct, the API becomes cleaner and more intuitive. The changes are consistently applied across the codebase, including examples, benchmarks, and tests. The renaming of test functions and adjustment of visibility for utility functions are also welcome improvements for code quality. I have one comment regarding device handling which could lead to a runtime panic in some scenarios.
src/model.rs
Outdated
| None => None, | ||
| }; | ||
| let parameters = check_and_fill_parameters(parameters)?; | ||
| let model = parameters_to_model::<B2>(¶meters); |
There was a problem hiding this comment.
The parameters_to_model function creates tensors on the default device, but new_with_backend can be called with a non-default device. This will lead to a panic if the devices don't match when performing operations.
The device should be passed to parameters_to_model and used when creating tensors to ensure they are on the correct device.
You'll need to update parameters_to_model to accept a device parameter. This will likely require a few knock-on changes, for example:
// in src/model.rs
pub(crate) fn parameters_to_model<B: Backend>(parameters: &Parameters, device: &B::Device) -> Model<B> {
let config = ModelConfig::default();
// Model::new also needs to be updated to accept a device
let mut model = Model::new(config.clone(), device);
model.w = Param::from_tensor(Tensor::from_floats(
TensorData::new(
clip_parameters(parameters, config.num_relearning_steps, Default::default()),
Shape { dims: vec![21] },
),
device,
));
model
}| let model = parameters_to_model::<B2>(¶meters); | |
| let model = parameters_to_model::<B2>(¶meters, &device); |
|
|
||
| // evaluate | ||
| let model = FSRS::new(Some(¶meters)).unwrap(); | ||
| let model = FSRS::new(¶meters).unwrap(); |
There was a problem hiding this comment.
Good change here.
…nsor creation, enhancing device management and consistency across the codebase.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and well-executed refactoring of the FSRS codebase. The key changes, such as extracting standalone functions and simplifying the FSRS struct and its API, make the library more ergonomic and improve its overall structure. The move to a non-optional model field in FSRS and the introduction of FSRS::default() are excellent improvements. The code changes are consistent with the goals outlined in the description. My review includes a few minor suggestions to improve code consistency and clean up test code.
| .unwrap(); | ||
| dbg!(optimal_retention); | ||
| let retention_value = optimal_retention(&config, &[], |_| true, None, None).unwrap(); | ||
| dbg!(retention_value); |
| num_relearning_steps: None, | ||
| }) | ||
| .unwrap(); | ||
| dbg!(¶meters); |
| let model = FSRS::new(Some(¶meters)).unwrap(); | ||
| let model = FSRS::new(¶meters).unwrap(); | ||
| let metrics = model.evaluate(items.clone(), |_| true).unwrap(); | ||
| dbg!(&metrics); |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…cing code consistency across multiple files.
…e parameter, improving code consistency and simplifying tensor creation across multiple files.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and well-executed refactoring of the FSRS codebase. The primary changes involve extracting several key functions (compute_parameters, evaluate_with_time_series_splits, optimal_retention, current_retrievability) into standalone functions, which improves modularity and API ergonomics. The introduction of FSRS::default() and the simplification of FSRS::new are welcome improvements. The code organization has also been enhanced by reducing visibility of internal modules and standardizing test function names.
My review has identified one high-severity issue related to device handling. The refactoring removed the device field from the FSRS struct, but the new device() method incorrectly returns the default device, which could lead to panics if a non-default device is used. I have provided a specific suggestion to fix this.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…iple files for improved consistency and clarity.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and well-executed refactoring, extracting standalone functions like compute_parameters, evaluate_with_time_series_splits, and optimal_retention from the FSRS struct. The API is now more ergonomic, with the introduction of FSRS::default() and a simplified FSRS::new(). The internal structure of FSRS is also improved by making the model field non-optional and removing the redundant device field. The code organization is enhanced through consistent test naming and better visibility control for internal modules. Overall, these changes are a great improvement to the codebase, making it cleaner, safer, and easier to use for the common cases, justifying the major version bump.
|
@Luc-Mcgrady, the PR is merged now. |
This PR introduces a significant refactoring of the FSRS codebase, making the API more ergonomic and consistent while extracting standalone functions from the FSRS structure. These changes warrant a major version bump from 5.2.0 to 6.0.0.
Key changes:
API improvements:
FSRS::default()for simpler initializationFSRS::new()to take parameters directly instead ofOption<&Parameters>Extracted standalone functions:
compute_parametersevaluate_with_time_series_splitsoptimal_retentioncurrent_retrievabilityCode organization:
test_prefixMigration guide:
FSRS Instance Creation
Before:
After:
Optimizing Parameters
Before:
After:
Evaluating with Time Series Splits
Before:
After:
Calculating Optimal Retention
Before:
After:
Retrievability Calculation
Before:
After: