Skip to content

Commit

Permalink
Merge pull request #4 from leanprover/ConcentratedBound
Browse files Browse the repository at this point in the history
workflow update for testing extraction
  • Loading branch information
jtristan authored Apr 18, 2024
2 parents 4bfdd8c + 04fe0a7 commit ccd7ae2
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lean_build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
on:
push:
branches:
- 'main'
pull_request:

name: ci
name: Verify

jobs:
build:
Expand All @@ -21,3 +23,4 @@ jobs:
- name: build std
id: build
run: lake build -Kwerror

34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- 'main'
pull_request:

name: Extract, build, run

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: install elan
run: |
set -o pipefail
curl -sSfL https://github.com/leanprover/elan/releases/download/v1.4.2/elan-x86_64-unknown-linux-gnu.tar.gz | tar xz
./elan-init -y --default-toolchain none
echo "$HOME/.elan/bin" >> $GITHUB_PATH
- uses: actions/checkout@v4

- name: build std
id: build
run: lake build -Kwerror FastExtract

- name: install Dafny
run: wget https://github.com/dafny-lang/dafny/releases/download/v4.4.0/dafny-4.4.0-x64-ubuntu-20.04.zip ; unzip dafny-4.4.0-x64-ubuntu-20.04.zip

- name: build Python version of SampCert
run: dafny/dafny build --target:py Tests/SampCert.dfy Tests/Random.py Tests/Test.py -o Tests/SampCert.dfy

- name: run Test
run: python3 Tests/SampCert-py/Test.py
7 changes: 7 additions & 0 deletions FastExtract.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/-
Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean-Baptiste Tristan
-/

import SampCert.Extraction
2 changes: 1 addition & 1 deletion SampCert.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean-Baptiste Tristan
-/

import SampCert.Extraction
import SampCert.Samplers.Gaussian.Basic
import SampCert.DiffPrivacy.ConcentratedBound
2 changes: 1 addition & 1 deletion SampCert/Extractor/Extension.lean
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inductive Entry where
def addEntry (s : State) (e : Entry) : State :=
match e with
| .addDecl key val => { s with map := s.map.insert key val }
| .toExport decl => { s with decls := decl :: s.decls }
| .toExport decl => { s with decls := decl.replace "SLang." "" :: s.decls }
| .addInline name => { s with inlines := name.toString :: s.inlines }
| .addFunc key val => { s with glob := s.glob.insert key val}

Expand Down
26 changes: 18 additions & 8 deletions SampCert/Extractor/Print.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open System IO.FS

namespace Lean.ToDafny

def destination : String := "/tmp/DafnyVMCTrait.dfy"
def destination : String := "Tests/SampCert.dfy"

def writeLn (ln : String) : IO Unit := do
let h ← Handle.mk destination Mode.append
Expand All @@ -21,17 +21,27 @@ def writeLn (ln : String) : IO Unit := do

elab "#print_dafny_exports" : command => do
writeFile destination ""
writeLn "module DafnyVMCTrait {"
writeLn " import UniformPowerOfTwo"
writeLn " import FisherYates"
writeLn " import opened Pos"
writeLn " import Uniform"

writeLn " trait {:termination false} RandomTrait extends UniformPowerOfTwo.Interface.Trait, FisherYates.Implementation.Trait, Uniform.Interface.Trait {\n"
writeLn "module {:extern} Random {"
writeLn " class {:extern} Random {"
writeLn " static method {:extern \"UniformPowerOfTwoSample\"} ExternUniformPowerOfTwoSample(n: nat) returns (u: nat)"
writeLn " }"
writeLn "}"

writeLn "module {:extern} SampCert {"
writeLn " import Random"
writeLn " type pos = x: nat | x > 0 witness 1"

writeLn " class SLang {\n"

writeLn " method UniformPowerOfTwoSample(n: nat) returns (u: nat)"
writeLn " requires n >= 1"
writeLn " {"
writeLn " u := Random.Random.ExternUniformPowerOfTwoSample(n);"
writeLn " }"

let { decls, .. } := extension.getState (← getEnv)
for decl in decls.reverse do
--IO.println decl
let h ← Handle.mk destination Mode.append
h.putStr decl
writeLn "}"
Expand Down
3 changes: 3 additions & 0 deletions SampCert/Samplers/Gaussian/Properties.lean
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ theorem summable_gauss_core (num : PNat) (den : PNat) :
intro Y
apply (RCLike.summable_ofReal ℂ).mp Y

theorem Add1 (n : Nat) : 0 < n + 1 := by
simp only [add_pos_iff, zero_lt_one, or_true]

@[simp]
theorem DiscreteGaussianSample_apply (num : PNat) (den : PNat) (x : ℤ) :
(DiscreteGaussianSample num den) x =
Expand Down
5 changes: 5 additions & 0 deletions Tests/Random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import secrets

class Random:
def UniformPowerOfTwoSample(n):
return secrets.randbits(n.bit_length()-1)
8 changes: 8 additions & 0 deletions Tests/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import SampCert

def main():
r = SampCert.SLang()
x = r.UniformSample(10)
print(x)

main()
3 changes: 2 additions & 1 deletion lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ require mathlib from git

@[default_target]
lean_lib «SampCert» where
-- add any library configuration options here

lean_lib «FastExtract» where

0 comments on commit ccd7ae2

Please sign in to comment.