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

Deterministic tests #349

Merged
merged 9 commits into from
Jun 25, 2024
Merged

Deterministic tests #349

merged 9 commits into from
Jun 25, 2024

Conversation

adria0
Copy link
Member

@adria0 adria0 commented Jun 6, 2024

  • New crate halo2_debug with some utilities, it can be reused for Adding debugging & testing utils #343
  • Remove integrated dhat profiling, it is activated in cargo test in M3 as also in coverage, creating crashes (since it's already activated). Also remove the associated heap-profiling feature (that is activated with --all-features)
  • Add new feature vector-tests, note that the main idea here is that this feature is activated via --all-features so the vector tests are specific to --all-features

@adria0 adria0 force-pushed the feat/deterministic1 branch 3 times, most recently from 57e333a to 9ea833d Compare June 6, 2024 07:39
@adria0 adria0 force-pushed the feat/deterministic1 branch from 9ea833d to b245fba Compare June 6, 2024 07:52
@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 82.06%. Comparing base (32599e8) to head (3d7cca4).

Files Patch % Lines
halo2_debug/src/lib.rs 53.33% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #349      +/-   ##
==========================================
- Coverage   82.09%   82.06%   -0.03%     
==========================================
  Files          83       84       +1     
  Lines       17228    17243      +15     
==========================================
+ Hits        14143    14151       +8     
- Misses       3085     3092       +7     

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

Copy link

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

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

I am not sure about the change in the PCS. Particularly, the addition of a rng parameter in new.
Seems like IPA doesn't use it and KZG keeps using OsRng.

I wonder if there is a cleaner way to get deterministic params for the tests. What do you think about leaving new as is, and adding a function that generates some fixed kzg parameters for testing?

halo2_backend/src/poly/ipa/commitment.rs Outdated Show resolved Hide resolved
@adria0
Copy link
Member Author

adria0 commented Jun 11, 2024

I am not sure about the change in the PCS. Particularly, the addition of a rng parameter in new. Seems like IPA doesn't use it and KZG keeps using OsRng.

I wonder if there is a cleaner way to get deterministic params for the tests. What do you think about leaving new as is, and adding a function that generates some fixed kzg parameters for testing?

Sure, a good option, there's the ::setup there

Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

Overall looks good to me! Left a few comments to discuss.

halo2_proofs/tests/compress_selectors.rs Outdated Show resolved Hide resolved
cost-estimator = ["halo2_frontend/cost-estimator"]
derive_serde = ["halo2curves/derive_serde", "halo2_frontend/derive_serde", "halo2_backend/derive_serde"]
vector-tests = []
Copy link
Member

Choose a reason for hiding this comment

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

We need to make sure this feature is enabled on test in the CI (this way we can detect the PRs that change the proof output). Is this the case?
If not, maybe we can add vector-tests as a default feature?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that this can be removed at all now, just keeping not(coverage) , let's me check again.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ed255 the main point here is that results can differ when turning some features (like circuit-params), so we want a feature that is only activated when we test it with --all-features. I keep it as is.

Copy link
Member

Choose a reason for hiding this comment

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

I see, but then we're not testing this in the CI. We're only testing these sets of features:

  • batch,dev-graph,gadget-traces
  • batch,dev-graph,gadget-traces,test-dev-graph,thread-safe-region,sanity-checks,circuit-params

I think we should have a job in the CI that runs the tests with vector-tests enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another option is to change the "all features" in CI to --all-features instead "--features batch,dev-graph,gadget-traces,test-dev-graph,thread-safe-region,sanity-checks,circuit-params". Not sure, testing with --all-features is more straighforward that specifying them manually if there's no conflicting options.

halo2_debug/src/lib.rs Show resolved Hide resolved
@adria0 adria0 requested review from davidnevadoc and ed255 June 18, 2024 09:58
Copy link

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

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

Just a small nit. LGTM!

@@ -170,7 +173,7 @@ fn test_serialization() {
&pk,
&[circuit],
instances.as_slice(),
OsRng,
test_rng(),

Choose a reason for hiding this comment

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

should we have &mut rng here instead of re-initializing with test_rng()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just a cosmetic thing, IMO.

Choose a reason for hiding this comment

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

Ah, that's my point! It's not the same thing, the function call resets the rng, not sure if it is important though.

Copy link
Member Author

@adria0 adria0 Jun 18, 2024

Choose a reason for hiding this comment

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

So, you say that if some random in the protocol is the same that tau (SRS's one) could lead to some kind of weakness in tests?

Edit: I would say "cosmetic" in the sense that does adds/removes any property from the test.

Copy link
Member

Choose a reason for hiding this comment

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

I would say that "cosmetically" passing rng (or &mut rng) fits better as it's the same pattern used in the other tests.

@adria0 adria0 force-pushed the feat/deterministic1 branch from c8d0398 to 3c60786 Compare June 19, 2024 14:44
@adria0 adria0 force-pushed the feat/deterministic1 branch 3 times, most recently from b2f305d to 9f1e7d4 Compare June 20, 2024 10:39
@adria0 adria0 force-pushed the feat/deterministic1 branch from 9f1e7d4 to d4cf60b Compare June 20, 2024 10:44
@adria0
Copy link
Member Author

adria0 commented Jun 20, 2024

@ed255 recheck again plz. Happened that with multithreading we get different results with OsX and Linux, so I limited the number of threads and fixed the CI.

Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

Just a small suggestion for the documentation of test_result but otherwise LGTM!

halo2_debug/src/lib.rs Outdated Show resolved Hide resolved
@adria0 adria0 merged commit 445d1da into main Jun 25, 2024
18 checks passed
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.

4 participants