Skip to content

Commit

Permalink
add a test for NIVC stuttering (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino authored Nov 22, 2023
1 parent 3b9c434 commit e5abcc5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lem/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod eval_tests;
mod misc;
mod nivc_stutter;
83 changes: 83 additions & 0 deletions src/lem/tests/nivc_stutter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use pasta_curves::pallas::Scalar as Fr;

use crate::{
coprocessor::test::DumbCoprocessor,
eval::lang::Lang,
lem::{
eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig},
store::Store,
Tag,
},
state::user_sym,
tag::ExprTag,
};

#[test]
fn test_nivc_stutter() {
let mut lang = Lang::<Fr, DumbCoprocessor<Fr>>::new();
let dumb = DumbCoprocessor::new();
let name = user_sym("cproc-dumb");

let store = Store::<Fr>::default();
lang.add_coprocessor(name, dumb);

let lurk_step = make_eval_step_from_config(&EvalConfig::new_nivc(&lang));
let cprocs = make_cprocs_funcs_from_lang(&lang);

assert_eq!(cprocs.len(), 1);
let cproc = &cprocs[0];

// 9^2 + 8 = 89
let expr = "(cproc-dumb 9 8)";
let expr = store.read_with_default_state(expr).unwrap();

let (frames, _) = evaluate(Some((&lurk_step, &lang)), expr, &store, 10).unwrap();

assert_eq!(frames.len(), 5);

// `cproc` can't reduce the first input
let first_input = &frames[0].input;
let output = &cproc
.call_simple(first_input, &store, &lang, 0)
.unwrap()
.output;
assert_eq!(first_input, output);

// `lurk_step` can't reduce the cproc input
let mut cproc_input = frames[3].input.clone();
assert!(matches!(cproc_input[0].tag(), Tag::Expr(ExprTag::Cproc)));
let output = &lurk_step
.call_simple(&cproc_input, &store, &lang, 0)
.unwrap()
.output;
assert_eq!(&cproc_input, output);

// `cproc` can reduce the cproc input
let output = &cproc
.call_simple(&cproc_input, &store, &lang, 0)
.unwrap()
.output;
assert_ne!(&cproc_input, output);

// swapping the cproc name
let cont = cproc_input.pop().unwrap();
let env = cproc_input.pop().unwrap();
let expr = cproc_input.pop().unwrap();

let idx = expr.get_index2().unwrap();
let (_, args) = store.expect_2_ptrs(idx);
let new_name = user_sym("cproc-dumb-not");
let expr = store.intern_2_ptrs(
Tag::Expr(ExprTag::Cproc),
store.intern_symbol(&new_name),
*args,
);

// `cproc` can't reduce the altered cproc input (with the wrong name)
let cproc_input = vec![expr, env, cont];
let output = &cproc
.call_simple(&cproc_input, &store, &lang, 0)
.unwrap()
.output;
assert_eq!(&cproc_input, output);
}

1 comment on commit e5abcc5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
125.78 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/6963509057

Benchmark Results

LEM Fibonacci Prove - rc = 100

fib-ref=3b9c434a37ed04b4f0fc048af15bde7e6536350a fib-ref=e5abcc5cc1e75688e4f4a4c03e05d345c4e5bb57
num-100 4.77 s (✅ 1.00x) 4.84 s (✅ 1.01x slower)
num-200 9.87 s (✅ 1.00x) 9.90 s (✅ 1.00x slower)

LEM Fibonacci Prove - rc = 600

fib-ref=3b9c434a37ed04b4f0fc048af15bde7e6536350a fib-ref=e5abcc5cc1e75688e4f4a4c03e05d345c4e5bb57
num-100 3.99 s (✅ 1.00x) 4.01 s (✅ 1.00x slower)
num-200 9.05 s (✅ 1.00x) 9.05 s (✅ 1.00x slower)

Made with criterion-table

Please sign in to comment.