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

Fix error handling in initialize_state #1657

Merged
merged 5 commits into from
Mar 13, 2024

Conversation

fmoletta
Copy link
Member

@fmoletta fmoletta commented Mar 11, 2024

initialize_state now returns the correct errors when either program_base or execution_base are None
Also closes #1638

@fmoletta fmoletta marked this pull request as ready for review March 11, 2024 16:19
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.70%. Comparing base (105ca3a) to head (880ba3c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1657      +/-   ##
==========================================
- Coverage   96.70%   96.70%   -0.01%     
==========================================
  Files          95       95              
  Lines       38154    38151       -3     
==========================================
- Hits        36897    36894       -3     
  Misses       1257     1257              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Mar 11, 2024

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.261 ± 0.024 2.239 2.307 1.00
head big_factorial 2.263 ± 0.022 2.235 2.294 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.266 ± 0.022 2.245 2.313 1.00
head big_fibonacci 2.282 ± 0.050 2.249 2.386 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 8.485 ± 0.124 8.265 8.665 1.01 ± 0.02
head blake2s_integration_benchmark 8.399 ± 0.131 8.248 8.575 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.308 ± 0.010 2.298 2.322 1.00
head compare_arrays_200000 2.310 ± 0.006 2.299 2.320 1.00 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.444 ± 0.010 1.431 1.460 1.01 ± 0.01
head dict_integration_benchmark 1.435 ± 0.013 1.420 1.454 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.294 ± 0.010 1.283 1.311 1.00
head field_arithmetic_get_square_benchmark 1.309 ± 0.023 1.288 1.367 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 8.533 ± 0.326 8.287 9.384 1.02 ± 0.04
head integration_builtins 8.392 ± 0.146 8.257 8.575 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.641 ± 0.140 8.512 8.827 1.00
head keccak_integration_benchmark 8.714 ± 0.148 8.496 8.840 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.311 ± 0.011 2.300 2.336 1.00
head linear_search 2.330 ± 0.019 2.314 2.378 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.552 ± 0.010 1.542 1.570 1.00 ± 0.01
head math_cmp_and_pow_integration_benchmark 1.549 ± 0.010 1.537 1.565 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.431 ± 0.032 1.406 1.500 1.00
head math_integration_benchmark 1.442 ± 0.035 1.413 1.508 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.252 ± 0.012 1.231 1.270 1.00 ± 0.01
head memory_integration_benchmark 1.249 ± 0.012 1.230 1.267 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.600 ± 0.006 1.590 1.609 1.00
head operations_with_data_structures_benchmarks 1.600 ± 0.006 1.592 1.608 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 593.0 ± 3.1 588.2 600.0 1.00
head pedersen 593.2 ± 6.3 589.9 610.9 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 979.3 ± 10.5 960.2 998.8 1.00
head poseidon_integration_benchmark 984.5 ± 7.2 975.4 994.6 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.878 ± 0.013 1.864 1.911 1.01 ± 0.01
head secp_integration_benchmark 1.861 ± 0.008 1.850 1.880 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 724.1 ± 3.0 720.5 729.3 1.00 ± 0.01
head set_integration_benchmark 723.6 ± 3.8 719.0 731.9 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.643 ± 0.054 4.560 4.753 1.00 ± 0.04
head uint256_integration_benchmark 4.637 ± 0.164 4.552 5.098 1.00

}
if let Some(exec_base) = self.execution_base {
vm.segments
.load_data(exec_base, &stack)
.map_err(RunnerError::MemoryInitializationError)?;
} else {
return Err(RunnerError::NoProgBase);
return Err(RunnerError::NoExecBase);
Copy link
Member

Choose a reason for hiding this comment

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

Given both return errors if None, another implementation could be:

let prog_base = self.program_base.ok_or(RunnerError::NoProgBase)?;
let exec_base = self.execution_base.ok_or(RunnerError::NoExecBase)?;
// And then the logic without extra indentation or error handling.

Copy link
Member

Choose a reason for hiding this comment

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

That said, do those always error out? Maybe it could make sense to make them not optional and fail earlier if they're missing?

@fmoletta fmoletta added this pull request to the merge queue Mar 13, 2024
Merged via the queue into main with commit 94a3d3b Mar 13, 2024
52 checks passed
@fmoletta fmoletta deleted the fix-error-handling-initialize-state branch March 13, 2024 15:44
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.

Double unwrap for program_base in Cairo runner initialize_state
3 participants