Skip to content

Commit

Permalink
Seq dependency removed
Browse files Browse the repository at this point in the history
  • Loading branch information
hsmajlovic committed Jan 23, 2025
1 parent edd4aad commit 51d280f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 185 deletions.
35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ mkdir $HOME/.codon && curl -L https://github.com/exaloop/codon/releases/download

Then install Sequre:
```bash
curl -L https://github.com/0xTCG/sequre/releases/download/v0.0.16-alpha/sequre-$(uname -s | awk '{print tolower($0)}')-$(uname -m).tar.gz | tar zxvf - -C $HOME/.codon/lib/codon/plugins
curl -L https://github.com/0xTCG/sequre/releases/download/v0.0.20-alpha/sequre-$(uname -s | awk '{print tolower($0)}')-$(uname -m).tar.gz | tar zxvf - -C $HOME/.codon/lib/codon/plugins
```

Afterwards, add alias for sequre command:
```bash
alias sequre="find . -name 'sock.*' -exec rm {} \; && $HOME/.codon/bin/codon run --disable-opt="core-pythonic-list-addition-opt" -plugin sequre -plugin seq"
alias sequre="find . -name 'sock.*' -exec rm {} \; && CODON_DEBUG=lt $HOME/.codon/bin/codon run --disable-opt="core-pythonic-list-addition-opt" -plugin sequre"
```

Finally, you can run Sequre as:
Finally, clone the repository:
```bash
git clone https://github.com/0xTCG/sequre.git && cd sequre
```
and run Sequre examples:
```bash
sequre examples/local_run.codon
```
Expand All @@ -38,7 +42,7 @@ SEQURE_CP_IPS=<ip1>,<ip2>,...,<ipN> sequre examples/online_run.codon <pid>
```
where `<ipN>` denotes the IP address of each party and `<pid>` denotes the ID of the party.

For example, in a two-party setup with a trusted dealer, run:
For example, in a two-party setup with a trusted dealer, run (IP addresses are random):
```bash
SEQURE_CP_IPS=192.168.0.1,192.168.0.2,192.168.0.3 sequre examples/online_run.codon 0
```
Expand All @@ -54,8 +58,6 @@ SEQURE_CP_IPS=192.168.0.1,192.168.0.2,192.168.0.3 sequre examples/online_run.cod
```
at the second party (CP2).

(IP addresses are fictional)

### Local run

To simulate the run on a single machine over multiple processes run:
Expand All @@ -78,31 +80,20 @@ sequre -release examples/local_run.codon --skip-mhe-setup

## Benchmarks (USENIX Security 2025)

Run all USENIX Security 2025 benchmarks.
**Note:** We generate all data at random for easier reproducibility. For the original data (from dbGaP under accession phs000716.v1.p1), please consult the authors.
**Note:** We generate all data at random for easier testing. For the original data (from dbGaP under accession phs000716.v1.p1), please consult the authors.

Run all USENIX Security 2025 benchmarks within the cloned Sequre repository.

### Local run (single machine)
```bash
CODON_DEBUG=lt scripts/run.sh -release benchmarks --local --jit --stdlib-builtin --king --pca --gwas-without-norm
sequre -release scripts/invoke.codon run-benchmarks --local --jit --stdlib-builtin --king --pca --gwas-without-norm
```

### Online run
Set each `<ipN>` to the respective IP address and `<pid>` to the respective ID. Please see the [online run example above](online_run).

```bash
CODON_DEBUG=lt SEQURE_CP_IPS=<ip1>,<ip2>,...,<ipN> scripts/run.sh -release benchmarks --local --jit --stdlib-builtin --king --pca --gwas-without-norm <pid>
```

### Via docker (local run)
```bash
mkdir -p results && sudo podman run --mount type=bind,source=$(pwd)/results,destination=/sequre/results --security-opt label=disable -e "CODON_DEBUG=lt" --privileged --rm -t hsmile/shechi:usenix scripts/run.sh -release benchmarks --local --jit --stdlib-builtin --king --pca --gwas-without-norm
```

### Via docker (online run)
Set each `<ipN>` to the respective IP address and `<pid>` to the respective ID. Please see the [online run example above](online_run). Also, map as many ports as the number of connections in the network (i.e. (N * (N - 1)) / 2) where N is the number of parties (including trusted dealer) starting from port 9001.

```bash
mkdir -p results && sudo podman run --mount type=bind,source=$(pwd)/results,destination=/sequre/results --security-opt label=disable -e "CODON_DEBUG=lt" -e "SEQURE_CP_IPS=<ip1>,<ip2>,...,<ipN>" --privileged --rm -p 9001:9001 -p 9002:9002 -p 9003:9003 -t hsmile/shechi:usenix scripts/run.sh -release benchmarks --jit --stdlib-builtin --king --pca --gwas-without-norm <pid>
SEQURE_CP_IPS=<ip1>,<ip2>,...,<ipN> sequre -release scripts/invoke.codon run-benchmarks --jit --stdlib-builtin --king --pca --gwas-without-norm <pid>
```

### Check accuracy
Expand Down
4 changes: 2 additions & 2 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ echo "Sequre plugin path: $SEQURE_PATH"
if [[ $* == *--jit* ]]
then
echo "Running $2 in $1 mode ..."
/usr/bin/time -v $SEQURE_CODON_PATH/build/codon run --disable-opt="core-pythonic-list-addition-opt" -plugin $SEQURE_PATH -plugin $SEQURE_SEQ_PATH $1 scripts/invoke.codon run-$2 ${*:3}
/usr/bin/time -v $SEQURE_CODON_PATH/build/codon run --disable-opt="core-pythonic-list-addition-opt" -plugin $SEQURE_PATH $1 scripts/invoke.codon run-$2 ${*:3}
echo "Cleaning up sockets ..."
find . -name 'sock.*' -exec rm {} \;
else
if [[ $* == *--build* ]]
then
rm -f ./sequrex
echo "Compiling $2 in $1 mode ..."
CC=clang CXX=clang++ $SEQURE_CODON_PATH/build/codon build --disable-opt="core-pythonic-list-addition-opt" -plugin $SEQURE_PATH -plugin $SEQURE_SEQ_PATH $1 -o sequrex scripts/invoke.codon
CC=clang CXX=clang++ $SEQURE_CODON_PATH/build/codon build --disable-opt="core-pythonic-list-addition-opt" -plugin $SEQURE_PATH $1 -o sequrex scripts/invoke.codon
fi

if [ ! -f "./sequrex" ]
Expand Down
16 changes: 0 additions & 16 deletions stdlib/pickler.codon
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from internal.file import _gz_errcheck
from internal.gc import sizeof, atomic
from bio.seq import seq

from C import memcpy(Jar, cobj, int)
from C import perror(cobj)
Expand Down Expand Up @@ -124,21 +123,6 @@ class str:
_read_raw(jar, p, n, pasteurized)
return str(p, n)

@extend
class seq:
def __pickle__(self, jar: Jar, pasteurized: bool = True):
_write(jar, self.len, pasteurized)
if not pasteurized: jar += sizeof(int)
_write_raw(jar, self.ptr, abs(self.len), pasteurized)

def __unpickle__(jar: Jar, pasteurized: bool = True):
n = _read(jar, pasteurized, int)
if not pasteurized: jar += sizeof(int)
m = abs(n)
p = Ptr[byte](m)
_read_raw(jar, p, m, pasteurized)
return seq(p, n)

@extend
class List:
def __pickle__(self, jar: Jar, pasteurized: bool = True):
Expand Down
3 changes: 0 additions & 3 deletions tests/__init__.codon
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ from ..applications.gwas import \
gwas_protocol, \
gwas_without_norm
from ..applications.dti import dti_mpc_protocol
from ..applications.opal import sequre_opal, offline_opal, load_dico, OPAL_TARGET_DICO_LABEL
from ..applications.ganon import sequre_ganon, offline_ganon, FilterConfig

from ..applications.utils.data_sharing import share_data
from ..applications.offline.seqan import seqan_ungapped_kmer_encode, load_ibf, bulk_count, \
_trailing_zeros, query_ibf, seqan_ibf_hash, SEQAN_HASH_SEEDS
33 changes: 0 additions & 33 deletions tests/benchmark.codon
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ from ..applications.mi import benchmark_mi
from ..applications.king import king
from ..applications.gwas import gwas_protocol, gwas_without_norm
from ..applications.dti import dti_mpc_protocol, dti_mhe_protocol
from ..applications.opal import sequre_opal as opal
from ..applications.ganon import sequre_ganon as ganon, FilterConfig
from ..applications.genotype_imputation import genotype_imputation
from ..applications.utils.data_sharing import share_data

Expand Down Expand Up @@ -474,31 +472,6 @@ def dti_wrapper(mpc, modulus):
return dti_mhe_protocol(mpc)
# return dti_mpc_protocol(mpc, True, modulus, False)

def opal_wrapper(mpc, modulus, coverage):
opal(mpc, modulus, coverage)[0]

def ganon_wrapper(mpc, modulus, read_limit):
parsed_hierarchy = {
"level_1": {
"window_size": 0,
"kmer_size": 19,
"offset": 1,
"rel_filter": 1,
"abs_filter": 0,
"alphabet_size": 5 # the size of the nucleotide alphabeth -- 5 in case of SeqAn's IBF (A,C,G,N,T)
}
}

filter_config = FilterConfig(
ibf_path="data/ganon/opal_dataset_ibf.bin",
map_path="data/ganon/opal_dataset_map.txt",
rel_cutoff=0.25,
abs_cutoff=0.0,
bin_count=63,
hash_count=4)

ganon(mpc, parsed_hierarchy, [filter_config], 'tests/data/opal/test.fragments.fasta', modulus, read_limit)

def ablations_wrapper(mpc, modulus):
rows_per_partition, cols = 16, 8192
rows = rows_per_partition * (mpc.comms.number_of_parties - 1)
Expand Down Expand Up @@ -674,14 +647,8 @@ def benchmark[TP](mpc, benchmark_toggles: dict, modulus: TP):
time_frame(mpc, credit_score_wrapper, 'Credit score inference', modulus)
if benchmark_toggles[RUN_TOGGLES.DTI_FLAG] or run_all:
time_frame(mpc, dti_wrapper, 'Drug target interaction inference', modulus)
if benchmark_toggles[RUN_TOGGLES.OPAL_FLAG] or run_all:
time_frame(mpc, opal_wrapper, 'Opal 0.1x', modulus, 0.1)
time_frame(mpc, opal_wrapper, 'Opal 15x', modulus, 15)
if benchmark_toggles[RUN_TOGGLES.GANON_FLAG] or run_all:
time_frame(mpc, ganon_wrapper, 'Ganon', modulus, 100)
if benchmark_toggles[RUN_TOGGLES.GENOTYPE_IMPUTATION_FLAG] or run_all:
time_frame(mpc, genotype_imputation_wrapper, 'Genotype imputation', modulus)

if benchmark_toggles[RUN_TOGGLES.ABLATIONS_FLAG] or run_all:
time_frame(mpc, ablations_wrapper, 'Ablation study', modulus)

Expand Down
8 changes: 0 additions & 8 deletions tests/e2e_tests/__init__.codon
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,3 @@ def test_e2e(mpc, tests_toggles, modulus):
from test_dti import test_dti
share_data(mpc, "dti", modulus)
test_dti(mpc, modulus)

if tests_toggles[RUN_TOGGLES.OPAL_FLAG] or run_e2e:
from test_opal import test_opal
test_opal(mpc, modulus)

if tests_toggles[RUN_TOGGLES.GANON_FLAG] or run_e2e:
from test_ganon import test_ganon
test_ganon(mpc, modulus)
101 changes: 0 additions & 101 deletions tests/unit_tests/test_helpers.codon
Original file line number Diff line number Diff line change
@@ -1,109 +1,9 @@
from .. import seqan_ungapped_kmer_encode, load_ibf, bulk_count, \
_trailing_zeros, query_ibf, seqan_ibf_hash, SEQAN_HASH_SEEDS

from sequre.utils.testing import assert_eq
from sequre.utils.utils import __rand_mat
from sequre.constants import MPC_FIELD_SIZE
from sequre.utils.io import write_matrix, read_matrix


def test_seqan_kmer_encoding():
expected_encodings = [
1184622173257u,
5923110866288u,
10542068003319u,
14563367360345u,
15596377817352u,
1687943774261u
]

encodings = list(seqan_ungapped_kmer_encode(s'ACGNTAGCACGNTAGCACGNTAGC', 5))
assert_eq('Seqan k-mer encoding', encodings, expected_encodings)


def test_seqan_load_ibf():
expected_value = 1566604024869293150u << 1
ibf, _, __ = load_ibf('tests/data/ganon/sample_bacteria_raw_ibf.bin', 63)

assert_eq('Seqan load ibf', ibf[0], expected_value)


def test_seqan_ibf_hash():
expected_hashes = [
[1911488, 350080, 2274880, 3018048],
[2308352, 2848960, 130496, 1999168],
[167104, 2689728, 381824, 886272],
[1529664, 628672, 2485696, 2773312],
[2531520, 1445504, 603392, 57472],
[2528448, 3995200, 111168, 3011904]
] >> 6

bin_count = 63
ibf, _, __ = load_ibf('tests/data/ganon/sample_bacteria_raw_ibf.bin', bin_count)
ibf_hash_count = 4
sigma = 5
ibf_bin_size = u64(len(ibf))
hash_shift = _trailing_zeros(ibf_bin_size)

encodings = list(seqan_ungapped_kmer_encode(s'ACGNTAGCACGNTAGCACGNTAGC', sigma))
hashes = [[seqan_ibf_hash(kmer_encoding, seed, ibf_bin_size, hash_shift) for seed in SEQAN_HASH_SEEDS[:ibf_hash_count]] for kmer_encoding in encodings]

assert_eq('Seqan IBF hash', hashes, expected_hashes)


def test_seqan_query_ibf():
expected_queries = [
70368752566272u,
0u,
565148976676864u,
33554432u,
0u,
0u
]

bin_count = 63
ibf, _, __ = load_ibf('tests/data/ganon/sample_bacteria_raw_ibf.bin', bin_count)
ibf_hash_count = 4
sigma = 5
ibf_bin_size = u64(len(ibf))
hash_shift = _trailing_zeros(ibf_bin_size)

queries = [
query_ibf(
ibf,
kmer_encoding,
ibf_hash_count,
ibf_bin_size,
bin_count,
hash_shift) for kmer_encoding in seqan_ungapped_kmer_encode(s'ACGNTAGCACGNTAGCACGNTAGC', sigma)]

assert_eq('Seqan query IBF', queries, expected_queries)


def test_seqan_bulk_count():
expected_count = [
0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
]

ibf, _, __ = load_ibf('tests/data/ganon/sample_bacteria_raw_ibf.bin', 63)
count = bulk_count(ibf, list(seqan_ungapped_kmer_encode(s'ACGNTAGCACGNTAGCACGNTAGC', 5)), 63, 4)

assert_eq('Seqan bulk count', count, expected_count)


def test_seqan():
print(f'Testing SeqAn ... \n')

test_seqan_kmer_encoding()
test_seqan_ibf_hash()
test_seqan_load_ibf()
test_seqan_query_ibf()
test_seqan_bulk_count()


def test_io():
print(f'Testing I/O ... \n')

Expand All @@ -121,6 +21,5 @@ def test_helpers():
print(f'Testing helpers ... \n')

test_io()
test_seqan()

print(f'Helpers tests passed.\n')

0 comments on commit 51d280f

Please sign in to comment.