Skip to content

Commit 016ef79

Browse files
GitHub release v2.0.0
1 parent f289396 commit 016ef79

16 files changed

Lines changed: 543 additions & 216 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ipython_config.py
102102
# This is especially recommended for binary packages to ensure reproducibility, and is more
103103
# commonly ignored for libraries.
104104
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105-
# poetry.lock
105+
poetry.lock
106106

107107
# pdm
108108
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
# MUPOL MPC Solution for the Collaborative Freighter Delivery Problem :articulated_lorry: :closed_lock_with_key:
22

3+
## Overview :telescope:
4+
5+
This library forms the second component of the MUPOL MPC demonstrator, namely, the MPC solver itself.
6+
In a nutshell, given a problem instance generated with the MUPOL plaintext library (hence a map with orders and trucks at given locations, where orders need to be brought to other locations with a given priority), the MPC solver will find a solution by making use of MPC, and hence by preserving the confidentiality of the trucks and orders information.
7+
38
## Installation :wrench:
49

510
### Dependency management
611

712
Installation and dependencies are managed by [Poetry](https://python-poetry.org/), which can be installed with `pipx install poetry`.
813

14+
Once you've cloned the project, just run `poetry install` and you should be good to go.
15+
916
### Internal dependencies
1017

11-
Furthermore, this project uses [MUPOL plaintext](https://github.com/ait-crypto/MUPOL-Plaintext).
12-
The project code is currently not provided in a Python package, hence it is up to the user to create such a package and add it to the Python virtual environment.
18+
This project uses a non-PyPI repository, [MUPOL plaintext](https://github.com/ait-crypto/MUPOL-Plaintext), as a dependency.
19+
It will be installed from source by Poetry when you run `poetry install`, so this should not affect the user.
20+
21+
## Content :clipboard:
22+
23+
The library files are contained in the `mupol/mpc` folder;
24+
they primarily consists of the `solver.py` file (containing the main class to solve a MUPOL problem instance with MPC) and of the `input_uploader.py` file (that "uploads" MUPOL objects to the MPyC framework).
25+
The `utils` folder contains files for arguments handling and logging, and some MPyC utility functions.
26+
27+
The necessary configuration files can be found in the `config` folder.
28+
29+
Finally, the root folder contain an example wrapper `example.py`, that will generatae a MUPOL problem instance and solve it, and a `profiler.py` for benchmarking.
1330

1431

1532
## Example usage :checkered_flag:
@@ -20,6 +37,6 @@ If you want to fully simulate several parties (e.g., 3) with separate processes,
2037

2138
## Credits
2239

23-
This project was partially funded by the Austrian Research Promotiion Agency (FFG) with the "Digitale Technolgien" funding frame under grant agreement no. 902669 (MUPOL).
40+
This project was partially funded by the Austrian Research Promotiion Agency (FFG) with the "Digitale Technologien" funding frame under grant agreement no. 902669 (MUPOL).
2441

2542
Authors: Gabriele Spini and Stephan Krenn, AIT.

config/config.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ num_iters: 1000
1414
[MPC solver parameters]
1515
dummy_node: -1
1616
dummy_freighter_id: -1
17+
use_priorities: 1
18+
test_mode: 1
19+
norm_weight: 0.5
1720

1821
[MPC parameters]
1922
bit_length_sectypes: 10

config/config_scalability.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[Problem parameters]
2-
num_freighters: 3
2+
num_freighters: 1
33
min_num_trucks: 1
44
max_num_trucks: 4
55
truck_capacity: 32
@@ -14,6 +14,9 @@ num_iters: 1000
1414
[MPC solver parameters]
1515
dummy_node: -1
1616
dummy_freighter_id: -1
17+
use_priorities: 0
18+
test_mode: 1
19+
norm_weight: 1
1720

1821
[MPC parameters]
1922
bit_length_sectypes: 10

config/logger_config_scalability.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ propagate=0
2121
class=FileHandler
2222
level=DEBUG
2323
formatter=mupolMPCFormatter
24-
args=(__import__("datetime").datetime.now().strftime('logs/mupol_mpc_log_%%Y-%%m-%%d_%%H-%%M-%%S.log'), 'a')
24+
args=(__import__("datetime").datetime.now().strftime('logs/mupol_mpc_log_%%Y-%%m-%%d_%%H-%%M.log'), 'a')
2525

2626
[formatter_mupolMPCFormatter]
2727
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s

example.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from mupol.plaintext.freighters_day_planning.random_problem_generator import (
66
RandomProblemGenerator,
77
)
8+
from mupol.plaintext.freighters_day_planning.simple_solver import SimpleSolver
89

910
from mupol.mpc.input_uploader import prepare_mpc_data
1011
from mupol.mpc.solver import MPCSolver
@@ -27,15 +28,37 @@ async def main() -> None:
2728
args.random_seed,
2829
)
2930
problem: Problem = generator.get_problem()
31+
logger.debug("Problem instance: %s", str(problem))
32+
33+
plain_solver = SimpleSolver()
34+
logger.info(
35+
"Plain solver result with hardcoded weight: %s", plain_solver.solve(problem)
36+
)
3037

3138
logger.debug("Uploading data in MPC")
3239
await prepare_mpc_data(
3340
problem, args.dummy_freighter_id, args.dummy_node, args.bit_length_sectypes
3441
)
3542

43+
if args.test_mode == 1:
44+
for order in problem.orders:
45+
logger.debug(
46+
"Order: volume %s origin %s destination %s",
47+
await mpc.output(order.volume),
48+
await mpc.output(order.origin),
49+
await mpc.output(order.destination),
50+
)
51+
3652
logger.debug("Running solver")
3753
solver = MPCSolver(
38-
problem, args.dummy_freighter_id, args.dummy_node, args.truck_capacity, logger
54+
problem,
55+
args.dummy_freighter_id,
56+
args.dummy_node,
57+
args.truck_capacity,
58+
args.use_priorities,
59+
args.test_mode,
60+
logger,
61+
args.norm_weight,
3962
)
4063
await solver.solve_problem()
4164

mupol/mpc/input_uploader.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
This module contains the functions to upload the input data to the MPyC framework.
2+
This module contains the functions to 'upload' the input data to the MPyC framework
3+
(i.e. secret-share it).
34
"""
45

56
from mpyc.runtime import mpc
@@ -10,17 +11,25 @@
1011

1112
async def upload_order(order: Order, secint: type) -> None:
1213
"""Function to secret-share a single order object.
14+
Notice that we assume that the order object always comes from the first MPC player:
15+
this is enough for the current MUPOL demonstrator but will need to be made more
16+
flexible when moving to highter TRL or more realistic experiments.
1317
1418
:param order: the order to be secret-shared
1519
:param secint: the desired type of MPyC secret sharing
1620
"""
21+
order.id = mpc.input(secint(order.id), senders=0)
1722
order.origin = mpc.input(secint(order.origin), senders=0)
1823
order.destination = mpc.input(secint(order.destination), senders=0)
1924
order.volume = mpc.input(secint(order.volume), senders=0)
25+
order.priority = mpc.input(secint(order.priority), senders=0)
2026

2127

2228
async def initialize_order(order: Order, secint: type, dummy_freighter_id: int) -> None:
2329
"""Set initial order variables.
30+
Notice that we assume that the order object always comes from the first MPC player:
31+
this is enough for the current MUPOL demonstrator but will need to be made more
32+
flexible when moving to highter TRL or more realistic experiments.
2433
2534
:param order: the relevant order object
2635
:param secint: the desired type of the MPyC secret-shared values
@@ -33,6 +42,9 @@ async def initialize_order(order: Order, secint: type, dummy_freighter_id: int)
3342

3443
async def upload_truck(truck: Truck, secint: type) -> None:
3544
"""Function to secret-share a single truck object.
45+
Notice that we assume that the truck object always comes from the first MPC player:
46+
this is enough for the current MUPOL demonstrator but will need to be made more
47+
flexible when moving to highter TRL or more realistic experiments.
3648
3749
:param truck: the truck to be secret-shared
3850
:param secint: the desired type of MPyC secret sharing
@@ -44,6 +56,9 @@ async def upload_truck(truck: Truck, secint: type) -> None:
4456

4557
async def initialize_truck(truck: Truck, dummy_node: int, secint: type) -> None:
4658
"""Set initial truck variables.
59+
Notice that we assume that the truck object always comes from the first MPC player:
60+
this is enough for the current MUPOL demonstrator but will need to be made more
61+
flexible when moving to highter TRL or more realistic experiments.
4762
4863
:param truck: the relevant truck object
4964
:param dummy_node: which value to use for truck with no destination assigned

0 commit comments

Comments
 (0)