async def _prog(context): context.preproc = FakePreProcessedElements() for i in range(0, iters): a = FixedPoint(context, aval[i]) b = FixedPoint(context, bval[i]) assert await (await a.ltz()).open() == 0 assert await (await b.ltz()).open() == 1
async def _prog(context): context.preproc = FakePreProcessedElements() for i in range(0, iters): a = FixedPoint(context, aval[i]) b = FixedPoint(context, bval[i]) c = await a.__mul__(b) assert approx_equal(await c.open(), aval[i] * bval[i])
async def tutorial_fixedpoint(): n, t = 4, 1 pp = FakePreProcessedElements() pp.generate_zeros(100, n, t) pp.generate_triples(1000, n, t) pp.generate_bits(1000, n, t) program_runner = TaskProgramRunner(n, t, config) program_runner.add(_prog) results = await program_runner.join() return results
async def _prog(context): context.preproc = FakePreProcessedElements() a = FixedPoint(context, aval) b = FixedPoint(context, bval) assert approx_equal(await a.open(), aval) assert approx_equal(await b.open(), bval) assert approx_equal(await (a - b).open(), aval - bval) assert approx_equal(await (a + b).open(), aval + bval)
async def tutorial_1(): # Create a test network of 4 nodes (no sockets, just asyncio tasks) n, t = 4, 1 pp = FakePreProcessedElements() pp.generate_zeros(100, n, t) pp.generate_triples(100, n, t) pp.generate_bits(100, n, t) program_runner = TaskProgramRunner(n, t, config) program_runner.add(prog) results = await program_runner.join() return results
async def prog(): n, t = 4, 1 pp = FakePreProcessedElements() pp.generate_zeros(1000, n, t) pp.generate_triples(120000, n, t) pp.generate_share_bits(1000, n, t) pp.generate_bits(3000, n, t) pp.generate_rands(10000, n, t) program_runner = TaskProgramRunner(n, t, config) program_runner.add(laesa_test_1) results = await program_runner.join() return results
async def _prog(ctx): ctx.preproc = FakePreProcessedElements() logging.info("Starting _prog") a = FixedPoint(ctx, 2.5) b = FixedPoint(ctx, -3.8) A = await a.open() # noqa: F841, N806 B = await b.open() # noqa: F841, N806 AplusB = await (a + b).open() # noqa: N806 AminusB = await (a - b).open() # noqa: N806 AtimesB = await (await a.__mul__(b)).open() # noqa: N806 AltB = await (await a.lt(b)).open() # noqa: N806 BltA = await (await b.lt(a)).open() # noqa: N806 logging.info("done") logging.info(f"A:{A} B:{B} A-B:{AminusB} A+B:{AplusB}") logging.info(f"A*B:{AtimesB} A<B:{AltB} B<A:{BltA}") logging.info("Finished _prog")
if __name__ == "__main__": from honeybadgermpc.config import HbmpcConfig import sys if not HbmpcConfig.peers: print(f"WARNING: the $CONFIG_PATH environment variable wasn't set. " f"Please run this file with `scripts/launch-tmuxlocal.sh " f"apps/tutorial/hbmpc-tutorial-2.py conf/mpc/local`") sys.exit(1) asyncio.set_event_loop(asyncio.new_event_loop()) loop = asyncio.get_event_loop() loop.set_debug(True) try: if HbmpcConfig.my_id == 0: k = 100 # How many of each kind of preproc pp_elements = FakePreProcessedElements() pp_elements.generate_bits(k, HbmpcConfig.N, HbmpcConfig.t) pp_elements.generate_triples(k, HbmpcConfig.N, HbmpcConfig.t) pp_elements.preprocessing_done() else: loop.run_until_complete(pp_elements.wait_for_preprocessing()) loop.run_until_complete( _run(HbmpcConfig.peers, HbmpcConfig.N, HbmpcConfig.t, HbmpcConfig.my_id)) finally: loop.close()