mplang-nightly 0.1.dev192__py3-none-any.whl → 0.1.dev268__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mplang/__init__.py +21 -130
- mplang/py.typed +13 -0
- mplang/v1/__init__.py +157 -0
- mplang/v1/_device.py +602 -0
- mplang/{analysis → v1/analysis}/__init__.py +1 -1
- mplang/{analysis → v1/analysis}/diagram.py +4 -4
- mplang/{core → v1/core}/__init__.py +20 -14
- mplang/{core → v1/core}/cluster.py +6 -1
- mplang/{core → v1/core}/comm.py +1 -1
- mplang/{core → v1/core}/context_mgr.py +1 -1
- mplang/{core → v1/core}/dtypes.py +38 -0
- mplang/{core → v1/core}/expr/__init__.py +7 -7
- mplang/{core → v1/core}/expr/ast.py +11 -13
- mplang/{core → v1/core}/expr/evaluator.py +8 -8
- mplang/{core → v1/core}/expr/printer.py +6 -6
- mplang/{core → v1/core}/expr/transformer.py +2 -2
- mplang/{core → v1/core}/expr/utils.py +2 -2
- mplang/{core → v1/core}/expr/visitor.py +1 -1
- mplang/{core → v1/core}/expr/walk.py +1 -1
- mplang/{core → v1/core}/interp.py +6 -6
- mplang/{core → v1/core}/mpir.py +13 -11
- mplang/{core → v1/core}/mpobject.py +6 -6
- mplang/{core → v1/core}/mptype.py +13 -10
- mplang/{core → v1/core}/pfunc.py +2 -2
- mplang/{core → v1/core}/primitive.py +12 -12
- mplang/{core → v1/core}/table.py +36 -8
- mplang/{core → v1/core}/tensor.py +1 -1
- mplang/{core → v1/core}/tracer.py +9 -9
- mplang/{host.py → v1/host.py} +5 -5
- mplang/{kernels → v1/kernels}/__init__.py +1 -1
- mplang/{kernels → v1/kernels}/base.py +1 -1
- mplang/{kernels → v1/kernels}/basic.py +15 -15
- mplang/{kernels → v1/kernels}/context.py +19 -16
- mplang/{kernels → v1/kernels}/crypto.py +8 -10
- mplang/{kernels → v1/kernels}/fhe.py +9 -7
- mplang/{kernels → v1/kernels}/mock_tee.py +3 -3
- mplang/{kernels → v1/kernels}/phe.py +26 -18
- mplang/{kernels → v1/kernels}/spu.py +5 -5
- mplang/{kernels → v1/kernels}/sql_duckdb.py +5 -3
- mplang/{kernels → v1/kernels}/stablehlo.py +18 -17
- mplang/{kernels → v1/kernels}/value.py +2 -2
- mplang/{ops → v1/ops}/__init__.py +3 -3
- mplang/{ops → v1/ops}/base.py +1 -1
- mplang/{ops → v1/ops}/basic.py +6 -5
- mplang/v1/ops/crypto.py +262 -0
- mplang/{ops → v1/ops}/fhe.py +2 -2
- mplang/{ops → v1/ops}/jax_cc.py +26 -59
- mplang/v1/ops/nnx_cc.py +168 -0
- mplang/{ops → v1/ops}/phe.py +16 -3
- mplang/{ops → v1/ops}/spu.py +3 -3
- mplang/v1/ops/sql_cc.py +303 -0
- mplang/{ops → v1/ops}/tee.py +2 -2
- mplang/{runtime → v1/runtime}/__init__.py +2 -2
- mplang/v1/runtime/channel.py +230 -0
- mplang/{runtime → v1/runtime}/cli.py +3 -3
- mplang/{runtime → v1/runtime}/client.py +1 -1
- mplang/{runtime → v1/runtime}/communicator.py +39 -15
- mplang/{runtime → v1/runtime}/data_providers.py +80 -19
- mplang/{runtime → v1/runtime}/driver.py +4 -4
- mplang/v1/runtime/link_comm.py +196 -0
- mplang/{runtime → v1/runtime}/server.py +22 -9
- mplang/{runtime → v1/runtime}/session.py +24 -51
- mplang/{runtime → v1/runtime}/simulation.py +36 -14
- mplang/{simp → v1/simp}/api.py +72 -14
- mplang/{simp → v1/simp}/mpi.py +1 -1
- mplang/{simp → v1/simp}/party.py +5 -5
- mplang/{simp → v1/simp}/random.py +2 -2
- mplang/v1/simp/smpc.py +238 -0
- mplang/v1/utils/table_utils.py +185 -0
- mplang/v2/__init__.py +424 -0
- mplang/v2/backends/__init__.py +57 -0
- mplang/v2/backends/bfv_impl.py +705 -0
- mplang/v2/backends/channel.py +217 -0
- mplang/v2/backends/crypto_impl.py +723 -0
- mplang/v2/backends/field_impl.py +454 -0
- mplang/v2/backends/func_impl.py +107 -0
- mplang/v2/backends/phe_impl.py +148 -0
- mplang/v2/backends/simp_design.md +136 -0
- mplang/v2/backends/simp_driver/__init__.py +41 -0
- mplang/v2/backends/simp_driver/http.py +168 -0
- mplang/v2/backends/simp_driver/mem.py +280 -0
- mplang/v2/backends/simp_driver/ops.py +135 -0
- mplang/v2/backends/simp_driver/state.py +60 -0
- mplang/v2/backends/simp_driver/values.py +52 -0
- mplang/v2/backends/simp_worker/__init__.py +29 -0
- mplang/v2/backends/simp_worker/http.py +354 -0
- mplang/v2/backends/simp_worker/mem.py +102 -0
- mplang/v2/backends/simp_worker/ops.py +167 -0
- mplang/v2/backends/simp_worker/state.py +49 -0
- mplang/v2/backends/spu_impl.py +275 -0
- mplang/v2/backends/spu_state.py +187 -0
- mplang/v2/backends/store_impl.py +62 -0
- mplang/v2/backends/table_impl.py +838 -0
- mplang/v2/backends/tee_impl.py +215 -0
- mplang/v2/backends/tensor_impl.py +519 -0
- mplang/v2/cli.py +603 -0
- mplang/v2/cli_guide.md +122 -0
- mplang/v2/dialects/__init__.py +36 -0
- mplang/v2/dialects/bfv.py +665 -0
- mplang/v2/dialects/crypto.py +689 -0
- mplang/v2/dialects/dtypes.py +378 -0
- mplang/v2/dialects/field.py +210 -0
- mplang/v2/dialects/func.py +135 -0
- mplang/v2/dialects/phe.py +723 -0
- mplang/v2/dialects/simp.py +944 -0
- mplang/v2/dialects/spu.py +349 -0
- mplang/v2/dialects/store.py +63 -0
- mplang/v2/dialects/table.py +407 -0
- mplang/v2/dialects/tee.py +346 -0
- mplang/v2/dialects/tensor.py +1175 -0
- mplang/v2/edsl/README.md +279 -0
- mplang/v2/edsl/__init__.py +99 -0
- mplang/v2/edsl/context.py +311 -0
- mplang/v2/edsl/graph.py +463 -0
- mplang/v2/edsl/jit.py +62 -0
- mplang/v2/edsl/object.py +53 -0
- mplang/v2/edsl/primitive.py +284 -0
- mplang/v2/edsl/printer.py +119 -0
- mplang/v2/edsl/registry.py +207 -0
- mplang/v2/edsl/serde.py +375 -0
- mplang/v2/edsl/tracer.py +614 -0
- mplang/v2/edsl/typing.py +816 -0
- mplang/v2/kernels/Makefile +30 -0
- mplang/v2/kernels/__init__.py +23 -0
- mplang/v2/kernels/gf128.cpp +148 -0
- mplang/v2/kernels/ldpc.cpp +82 -0
- mplang/v2/kernels/okvs.cpp +283 -0
- mplang/v2/kernels/okvs_opt.cpp +291 -0
- mplang/v2/kernels/py_kernels.py +398 -0
- mplang/v2/libs/collective.py +330 -0
- mplang/v2/libs/device/__init__.py +51 -0
- mplang/v2/libs/device/api.py +813 -0
- mplang/v2/libs/device/cluster.py +352 -0
- mplang/v2/libs/ml/__init__.py +23 -0
- mplang/v2/libs/ml/sgb.py +1861 -0
- mplang/v2/libs/mpc/__init__.py +41 -0
- mplang/v2/libs/mpc/_utils.py +99 -0
- mplang/v2/libs/mpc/analytics/__init__.py +35 -0
- mplang/v2/libs/mpc/analytics/aggregation.py +372 -0
- mplang/v2/libs/mpc/analytics/groupby.md +99 -0
- mplang/v2/libs/mpc/analytics/groupby.py +331 -0
- mplang/v2/libs/mpc/analytics/permutation.py +386 -0
- mplang/v2/libs/mpc/common/constants.py +39 -0
- mplang/v2/libs/mpc/ot/__init__.py +32 -0
- mplang/v2/libs/mpc/ot/base.py +222 -0
- mplang/v2/libs/mpc/ot/extension.py +477 -0
- mplang/v2/libs/mpc/ot/silent.py +217 -0
- mplang/v2/libs/mpc/psi/__init__.py +40 -0
- mplang/v2/libs/mpc/psi/cuckoo.py +228 -0
- mplang/v2/libs/mpc/psi/okvs.py +49 -0
- mplang/v2/libs/mpc/psi/okvs_gct.py +79 -0
- mplang/v2/libs/mpc/psi/oprf.py +310 -0
- mplang/v2/libs/mpc/psi/rr22.py +344 -0
- mplang/v2/libs/mpc/psi/unbalanced.py +200 -0
- mplang/v2/libs/mpc/vole/__init__.py +31 -0
- mplang/v2/libs/mpc/vole/gilboa.py +327 -0
- mplang/v2/libs/mpc/vole/ldpc.py +383 -0
- mplang/v2/libs/mpc/vole/silver.py +336 -0
- mplang/v2/runtime/__init__.py +15 -0
- mplang/v2/runtime/dialect_state.py +41 -0
- mplang/v2/runtime/interpreter.py +871 -0
- mplang/v2/runtime/object_store.py +194 -0
- mplang/v2/runtime/value.py +141 -0
- {mplang_nightly-0.1.dev192.dist-info → mplang_nightly-0.1.dev268.dist-info}/METADATA +22 -16
- mplang_nightly-0.1.dev268.dist-info/RECORD +180 -0
- {mplang_nightly-0.1.dev192.dist-info → mplang_nightly-0.1.dev268.dist-info}/WHEEL +1 -1
- mplang/device.py +0 -327
- mplang/ops/crypto.py +0 -108
- mplang/ops/ibis_cc.py +0 -136
- mplang/ops/sql_cc.py +0 -62
- mplang/runtime/link_comm.py +0 -78
- mplang/simp/smpc.py +0 -201
- mplang/utils/table_utils.py +0 -85
- mplang_nightly-0.1.dev192.dist-info/RECORD +0 -83
- /mplang/{core → v1/core}/mask.py +0 -0
- /mplang/{protos → v1/protos}/v1alpha1/mpir_pb2.py +0 -0
- /mplang/{protos → v1/protos}/v1alpha1/mpir_pb2.pyi +0 -0
- /mplang/{protos → v1/protos}/v1alpha1/value_pb2.py +0 -0
- /mplang/{protos → v1/protos}/v1alpha1/value_pb2.pyi +0 -0
- /mplang/{runtime → v1/runtime}/exceptions.py +0 -0
- /mplang/{runtime → v1/runtime}/http_api.md +0 -0
- /mplang/{simp → v1/simp}/__init__.py +0 -0
- /mplang/{utils → v1/utils}/__init__.py +0 -0
- /mplang/{utils → v1/utils}/crypto.py +0 -0
- /mplang/{utils → v1/utils}/func_utils.py +0 -0
- /mplang/{utils → v1/utils}/spu_utils.py +0 -0
- {mplang_nightly-0.1.dev192.dist-info → mplang_nightly-0.1.dev268.dist-info}/entry_points.txt +0 -0
- {mplang_nightly-0.1.dev192.dist-info → mplang_nightly-0.1.dev268.dist-info}/licenses/LICENSE +0 -0
mplang/runtime/link_comm.py
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Ant Group Co., Ltd.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import logging
|
|
18
|
-
|
|
19
|
-
import spu.libspu as libspu
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class LinkCommunicator:
|
|
23
|
-
"""Minimal wrapper for libspu link context.
|
|
24
|
-
|
|
25
|
-
This class serves only to create and hold a libspu link context for SPU runtime.
|
|
26
|
-
It does NOT provide general-purpose communication methods - those are handled by
|
|
27
|
-
the underlying libspu.link.Context which SPU runtime uses directly.
|
|
28
|
-
|
|
29
|
-
All serialization is handled internally by libspu - no pickle needed here.
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
def __init__(self, rank: int, addrs: list[str], *, mem_link: bool = False):
|
|
33
|
-
"""Initialize link communicator for SPU.
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
rank: Rank of this party
|
|
37
|
-
addrs: List of addresses for all parties
|
|
38
|
-
mem_link: If True, use in-memory link (for testing); otherwise use BRPC
|
|
39
|
-
"""
|
|
40
|
-
self._rank = rank
|
|
41
|
-
self._world_size = len(addrs)
|
|
42
|
-
|
|
43
|
-
desc = libspu.link.Desc() # type: ignore
|
|
44
|
-
desc.recv_timeout_ms = 100 * 1000 # 100 seconds
|
|
45
|
-
desc.http_max_payload_size = 32 * 1024 * 1024 # Default set link payload to 32M
|
|
46
|
-
for rank, addr in enumerate(addrs):
|
|
47
|
-
desc.add_party(f"P{rank}", addr)
|
|
48
|
-
|
|
49
|
-
if mem_link:
|
|
50
|
-
self.lctx = libspu.link.create_mem(desc, self._rank)
|
|
51
|
-
else:
|
|
52
|
-
self.lctx = libspu.link.create_brpc(desc, self._rank)
|
|
53
|
-
|
|
54
|
-
logging.info(
|
|
55
|
-
f"LinkCommunicator initialized: rank={self._rank}, world_size={self._world_size}, "
|
|
56
|
-
f"addrs={addrs}, mem_link={mem_link}"
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
@property
|
|
60
|
-
def rank(self) -> int:
|
|
61
|
-
"""Get rank from underlying link context."""
|
|
62
|
-
return self.lctx.rank # type: ignore[no-any-return]
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
def world_size(self) -> int:
|
|
66
|
-
"""Get world size from underlying link context."""
|
|
67
|
-
return self.lctx.world_size # type: ignore[no-any-return]
|
|
68
|
-
|
|
69
|
-
def get_lctx(self) -> libspu.link.Context:
|
|
70
|
-
"""Get the underlying libspu link context.
|
|
71
|
-
|
|
72
|
-
This is the primary interface - SPU runtime uses this context directly.
|
|
73
|
-
All communication and serialization is handled by libspu internally.
|
|
74
|
-
|
|
75
|
-
Returns:
|
|
76
|
-
The underlying libspu.link.Context instance.
|
|
77
|
-
"""
|
|
78
|
-
return self.lctx
|
mplang/simp/smpc.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Ant Group Co., Ltd.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
from abc import ABC, abstractmethod
|
|
17
|
-
from collections.abc import Callable
|
|
18
|
-
from enum import Enum
|
|
19
|
-
from functools import wraps
|
|
20
|
-
from typing import Any
|
|
21
|
-
|
|
22
|
-
from jax.tree_util import tree_unflatten
|
|
23
|
-
|
|
24
|
-
from mplang.core import Mask, MPObject, Rank, peval, psize
|
|
25
|
-
from mplang.core.context_mgr import cur_ctx
|
|
26
|
-
from mplang.ops import spu
|
|
27
|
-
from mplang.simp import mpi
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class SecureAPI(ABC):
|
|
31
|
-
"""Base class for secure APIs."""
|
|
32
|
-
|
|
33
|
-
@abstractmethod
|
|
34
|
-
def seal(self, obj: MPObject, frm_mask: Mask | None) -> list[MPObject]: ...
|
|
35
|
-
|
|
36
|
-
@abstractmethod
|
|
37
|
-
def sealFrom(self, obj: MPObject, root: Rank) -> MPObject: ...
|
|
38
|
-
|
|
39
|
-
@abstractmethod
|
|
40
|
-
def seval(self, fe_type: str, pyfn: Callable, *args: Any, **kwargs: Any) -> Any:
|
|
41
|
-
"""Run a function in the secure environment."""
|
|
42
|
-
|
|
43
|
-
@abstractmethod
|
|
44
|
-
def reveal(self, obj: MPObject, to_mask: Mask) -> MPObject: ...
|
|
45
|
-
|
|
46
|
-
@abstractmethod
|
|
47
|
-
def revealTo(self, obj: MPObject, to_rank: Rank) -> MPObject: ...
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class Delegation(SecureAPI):
|
|
51
|
-
"""Delegate to a trusted third-party to perform secure operations."""
|
|
52
|
-
|
|
53
|
-
def seal(self, obj: MPObject, frm_mask: Mask | None = None) -> list[MPObject]:
|
|
54
|
-
raise NotImplementedError("TODO")
|
|
55
|
-
|
|
56
|
-
def sealFrom(self, obj: MPObject, root: Rank) -> MPObject:
|
|
57
|
-
raise NotImplementedError("TODO")
|
|
58
|
-
|
|
59
|
-
def seval(self, fe_type: str, pyfn: Callable, *args: Any, **kwargs: Any) -> Any:
|
|
60
|
-
raise NotImplementedError("TODO")
|
|
61
|
-
|
|
62
|
-
def reveal(self, obj: MPObject, to_mask: Mask) -> MPObject:
|
|
63
|
-
raise NotImplementedError("TODO")
|
|
64
|
-
|
|
65
|
-
def revealTo(self, obj: MPObject, to_rank: Rank) -> MPObject:
|
|
66
|
-
raise NotImplementedError("TODO")
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
class SPU(SecureAPI):
|
|
70
|
-
"""Use SPU to perform secure operations."""
|
|
71
|
-
|
|
72
|
-
def get_spu_mask(self) -> Mask:
|
|
73
|
-
spu_devices = cur_ctx().cluster_spec.get_devices_by_kind("SPU")
|
|
74
|
-
if not spu_devices:
|
|
75
|
-
raise ValueError("No SPU device found in the cluster specification")
|
|
76
|
-
if len(spu_devices) > 1:
|
|
77
|
-
raise ValueError("Multiple SPU devices found in the cluster specification")
|
|
78
|
-
spu_device = spu_devices[0]
|
|
79
|
-
spu_mask = Mask.from_ranks([member.rank for member in spu_device.members])
|
|
80
|
-
return spu_mask
|
|
81
|
-
|
|
82
|
-
def seal(self, obj: MPObject, frm_mask: Mask | None = None) -> list[MPObject]:
|
|
83
|
-
spu_mask: Mask = self.get_spu_mask()
|
|
84
|
-
if obj.pmask is None:
|
|
85
|
-
if frm_mask is None:
|
|
86
|
-
# NOTE: The length of the return list is statically determined by obj_mask,
|
|
87
|
-
# so only static masks are supported here.
|
|
88
|
-
raise ValueError("Seal does not support dynamic masks.")
|
|
89
|
-
else:
|
|
90
|
-
# Force seal from the given mask, the runtime will raise error if the mask
|
|
91
|
-
# does not match obj.pmask.
|
|
92
|
-
# TODO(jint): add set_pmask primitive.
|
|
93
|
-
pass
|
|
94
|
-
else:
|
|
95
|
-
if frm_mask is None:
|
|
96
|
-
frm_mask = obj.pmask
|
|
97
|
-
else:
|
|
98
|
-
if not Mask(frm_mask).is_subset(obj.pmask):
|
|
99
|
-
raise ValueError(f"Cannot seal from {frm_mask} to {obj.pmask}, ")
|
|
100
|
-
|
|
101
|
-
# Get the world_size from spu_mask (number of parties in SPU computation)
|
|
102
|
-
world_size = Mask(spu_mask).num_parties()
|
|
103
|
-
pfunc, ins, _ = spu.makeshares(
|
|
104
|
-
obj, world_size=world_size, visibility=spu.Visibility.SECRET
|
|
105
|
-
)
|
|
106
|
-
assert len(ins) == 1
|
|
107
|
-
shares = peval(pfunc, ins, frm_mask)
|
|
108
|
-
|
|
109
|
-
# scatter the shares to each party.
|
|
110
|
-
return [mpi.scatter_m(spu_mask, rank, shares) for rank in Mask(frm_mask)]
|
|
111
|
-
|
|
112
|
-
def sealFrom(self, obj: MPObject, root: Rank) -> MPObject:
|
|
113
|
-
results = seal(obj, frm_mask=Mask.from_ranks(root))
|
|
114
|
-
assert len(results) == 1, f"Expected one result, got {len(results)}"
|
|
115
|
-
return results[0]
|
|
116
|
-
|
|
117
|
-
def seval(self, fe_type: str, pyfn: Callable, *args: Any, **kwargs: Any) -> Any:
|
|
118
|
-
if fe_type != "jax":
|
|
119
|
-
raise ValueError(f"Unsupported fe_type: {fe_type}")
|
|
120
|
-
|
|
121
|
-
spu_mask = self.get_spu_mask()
|
|
122
|
-
pfunc, in_vars, out_tree = spu.jax_compile(pyfn, *args, **kwargs)
|
|
123
|
-
assert all(var.pmask == spu_mask for var in in_vars), in_vars
|
|
124
|
-
out_flat = peval(pfunc, in_vars, spu_mask)
|
|
125
|
-
return tree_unflatten(out_tree, out_flat)
|
|
126
|
-
|
|
127
|
-
def reveal(self, obj: MPObject, to_mask: Mask) -> MPObject:
|
|
128
|
-
spu_mask = self.get_spu_mask()
|
|
129
|
-
|
|
130
|
-
assert obj.pmask == spu_mask, (obj.pmask, spu_mask)
|
|
131
|
-
|
|
132
|
-
# (n_parties, n_shares)
|
|
133
|
-
shares = [mpi.bcast_m(to_mask, rank, obj) for rank in Mask(spu_mask)]
|
|
134
|
-
assert len(shares) == Mask(spu_mask).num_parties(), (shares, spu_mask)
|
|
135
|
-
assert all(share.pmask == to_mask for share in shares)
|
|
136
|
-
|
|
137
|
-
# Reconstruct the original object from shares
|
|
138
|
-
pfunc, ins, _ = spu.reconstruct(*shares)
|
|
139
|
-
return peval(pfunc, ins, to_mask)[0] # type: ignore[no-any-return]
|
|
140
|
-
|
|
141
|
-
def revealTo(self, obj: MPObject, to_rank: Rank) -> MPObject:
|
|
142
|
-
return self.reveal(obj, to_mask=Mask.from_ranks(to_rank))
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
class SEE(Enum):
|
|
146
|
-
"""Secure Execution Environment."""
|
|
147
|
-
|
|
148
|
-
MOCK = 0
|
|
149
|
-
SPU = 1
|
|
150
|
-
TEE = 2
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
# TODO(jint): move me to options.py
|
|
154
|
-
mode: SEE = SEE.SPU
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def _get_sapi() -> SecureAPI:
|
|
158
|
-
"""Get the current secure API based on the mode."""
|
|
159
|
-
if mode == SEE.MOCK:
|
|
160
|
-
return Delegation()
|
|
161
|
-
elif mode == SEE.SPU:
|
|
162
|
-
return SPU()
|
|
163
|
-
elif mode == SEE.TEE:
|
|
164
|
-
raise NotImplementedError("TEE is not implemented yet")
|
|
165
|
-
else:
|
|
166
|
-
raise ValueError(f"Unknown mode: {mode}")
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
# seal :: m a -> [s a]
|
|
170
|
-
def seal(obj: MPObject, frm_mask: Mask | None = None) -> list[MPObject]:
|
|
171
|
-
"""Seal an simp object, result a list of sealed objects, with
|
|
172
|
-
the i'th element as the secret from the i'th party.
|
|
173
|
-
"""
|
|
174
|
-
return _get_sapi().seal(obj, frm_mask=frm_mask)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
# sealFrom :: m a -> m Rank -> s a
|
|
178
|
-
def sealFrom(obj: MPObject, root: Rank) -> MPObject:
|
|
179
|
-
"""Seal an simp object from a specific root party."""
|
|
180
|
-
return _get_sapi().sealFrom(obj, root)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
# reveal :: s a -> m a
|
|
184
|
-
def reveal(obj: MPObject, to_mask: Mask | None = None) -> MPObject:
|
|
185
|
-
"""Reveal a sealed object to pmask'ed parties."""
|
|
186
|
-
to_mask = to_mask or Mask.all(psize())
|
|
187
|
-
return _get_sapi().reveal(obj, to_mask)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
# revealTo :: s a -> m Rank -> m a
|
|
191
|
-
def revealTo(obj: MPObject, to_rank: Rank) -> MPObject:
|
|
192
|
-
return _get_sapi().revealTo(obj, to_rank)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
# srun :: (a -> a) -> s a -> s a
|
|
196
|
-
def srun(pyfn: Callable, *, fe_type: str = "jax") -> Callable:
|
|
197
|
-
@wraps(pyfn)
|
|
198
|
-
def wrapped(*args: Any, **kwargs: Any) -> Any:
|
|
199
|
-
return _get_sapi().seval(fe_type, pyfn, *args, **kwargs)
|
|
200
|
-
|
|
201
|
-
return wrapped
|
mplang/utils/table_utils.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Ant Group Co., Ltd.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
from io import StringIO
|
|
18
|
-
from typing import Any
|
|
19
|
-
|
|
20
|
-
import pandas as pd
|
|
21
|
-
|
|
22
|
-
from mplang.core.table import TableType
|
|
23
|
-
|
|
24
|
-
__all__ = ["csv_to_dataframe", "dataframe_to_csv"]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def dataframe_to_csv(df: Any) -> bytes:
|
|
28
|
-
"""Convert DataFrame to CSV format as bytes.
|
|
29
|
-
|
|
30
|
-
Args:
|
|
31
|
-
df: DataFrame to convert (pandas DataFrame)
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
CSV formatted data as bytes
|
|
35
|
-
|
|
36
|
-
Raises:
|
|
37
|
-
TypeError: If df is not a pandas DataFrame
|
|
38
|
-
ValueError: If DataFrame is empty or has no columns
|
|
39
|
-
"""
|
|
40
|
-
if not isinstance(df, pd.DataFrame):
|
|
41
|
-
raise TypeError(f"Expected pandas DataFrame, got {type(df)}")
|
|
42
|
-
|
|
43
|
-
if len(df.columns) == 0:
|
|
44
|
-
raise ValueError("Cannot convert DataFrame with no columns to CSV")
|
|
45
|
-
|
|
46
|
-
# Convert DataFrame to CSV string, then to bytes
|
|
47
|
-
csv_str: str = df.to_csv(index=False)
|
|
48
|
-
return csv_str.encode("utf-8")
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def csv_to_dataframe(content: bytes, schema: TableType | None = None) -> Any:
|
|
52
|
-
"""Convert CSV bytes to DataFrame.
|
|
53
|
-
|
|
54
|
-
Args:
|
|
55
|
-
content: CSV formatted data as bytes
|
|
56
|
-
schema: Optional TableType to specify which columns to read. If provided,
|
|
57
|
-
only columns specified in the schema will be loaded.
|
|
58
|
-
|
|
59
|
-
Returns:
|
|
60
|
-
pandas DataFrame
|
|
61
|
-
|
|
62
|
-
Raises:
|
|
63
|
-
TypeError: If content is not bytes
|
|
64
|
-
ValueError: If content cannot be parsed as CSV
|
|
65
|
-
"""
|
|
66
|
-
if not isinstance(content, bytes):
|
|
67
|
-
raise TypeError(f"Expected bytes, got {type(content)}")
|
|
68
|
-
|
|
69
|
-
try:
|
|
70
|
-
# Decode bytes to string, then parse as CSV
|
|
71
|
-
csv_str = content.decode("utf-8")
|
|
72
|
-
|
|
73
|
-
# Apply schema projection if provided
|
|
74
|
-
if schema and isinstance(schema, TableType):
|
|
75
|
-
# Extract column names from schema for column selection
|
|
76
|
-
usecols = list(schema.column_names())
|
|
77
|
-
df = pd.read_csv(StringIO(csv_str), usecols=usecols)
|
|
78
|
-
else:
|
|
79
|
-
df = pd.read_csv(StringIO(csv_str))
|
|
80
|
-
|
|
81
|
-
return df
|
|
82
|
-
except UnicodeDecodeError as e:
|
|
83
|
-
raise ValueError(f"Invalid UTF-8 encoding in CSV content: {e}") from e
|
|
84
|
-
except Exception as e:
|
|
85
|
-
raise ValueError(f"Failed to parse CSV content: {e}") from e
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
mplang/__init__.py,sha256=kpmYSJhYqaXlj-YDHxXs1feB2jgYMmSjjvsMBNhV1iE,3199
|
|
2
|
-
mplang/device.py,sha256=4PS3W69sDxIme6PrNnpWGoGg_duce9EEdDHanNKs3xE,12357
|
|
3
|
-
mplang/host.py,sha256=QVxA2PwHBymLFXG4LM6UBxzRqbR35d5KGTQYszAcNK8,4313
|
|
4
|
-
mplang/analysis/__init__.py,sha256=CTHFvRsi-nFngojqjn08UaR3RY9i7CJ7T2UdR95kCrk,1056
|
|
5
|
-
mplang/analysis/diagram.py,sha256=mKHdJDPWt9Xf7Tm9gWVMc-xQZsQiNsLN2KG2diTbS2E,19465
|
|
6
|
-
mplang/core/__init__.py,sha256=8uJ3coQ2RYwM6uxzv8JsiIc_G5g_7jK_LtUqFmfIYmk,3308
|
|
7
|
-
mplang/core/cluster.py,sha256=KrAOc0b5iqgKcKWWayk9gjkUPScYXohZNMD8qFGGNdA,11907
|
|
8
|
-
mplang/core/comm.py,sha256=5wkfKWCSlul5EZWAYAO36LpZzYldp9yZBqM9RLL2nzY,8973
|
|
9
|
-
mplang/core/context_mgr.py,sha256=R0QJAod-1nYduVoOknLfAsxZiy-RtmuQcp-07HABYZU,1541
|
|
10
|
-
mplang/core/dtypes.py,sha256=Qybk-_5WgMZOo8AFUtdBBOUSdPXJ5QdczCJW-wZry9w,10371
|
|
11
|
-
mplang/core/interp.py,sha256=JKjKJGWURU5rlHQ2yG5XNKWzN6hLZsmo--hZuveQgxI,5915
|
|
12
|
-
mplang/core/mask.py,sha256=14DFxaA446lGjN4dzTuQgm9Shcn34rYI87YJHg0YGNQ,10693
|
|
13
|
-
mplang/core/mpir.py,sha256=GQd9ruHg-k31UwEPC7NVGL-HjFylVq3-_RcA1B4bHdo,38260
|
|
14
|
-
mplang/core/mpobject.py,sha256=2t2BtKeVJLnEwMP7Yki8f5BOUYyIZgCP3pqC7pJ9K_g,3733
|
|
15
|
-
mplang/core/mptype.py,sha256=G8OATZan4GIrJe1AgDGKnGy284-_TVsxP8ZFef357rM,13775
|
|
16
|
-
mplang/core/pfunc.py,sha256=WOGmMr4HCUELED5QxYbhhyQJRDXrA5Bk3tPbZWpwmw8,5102
|
|
17
|
-
mplang/core/primitive.py,sha256=ggIKFU0e7AeLyOqEvpjMIzIaaevxtz68lNFE-JqSdcA,36734
|
|
18
|
-
mplang/core/table.py,sha256=HAJNm--n0vnzCLWMowMgjjr-hdSsKF19PohS8cWU3Ko,5893
|
|
19
|
-
mplang/core/tensor.py,sha256=hVhubK2cGdrllxSNBiXhQZwVsnSsRQyeaTa6V_Zeq_E,2362
|
|
20
|
-
mplang/core/tracer.py,sha256=dVMfUeCMmPz4o6tLXewGMW1Kpy5gpZORvr9w4MhwDtM,14288
|
|
21
|
-
mplang/core/expr/__init__.py,sha256=qwiSTUOcanFJLyK8HZ13_L1ZDrybqpPXIlTHAyeumE8,1988
|
|
22
|
-
mplang/core/expr/ast.py,sha256=K-rNqlpgkdjVzwSrLgunYnL4zWl1USJGLOgfz0qJNO4,20959
|
|
23
|
-
mplang/core/expr/evaluator.py,sha256=rpzZQPPVtxBvUuCx-9_bFmzr_7tfAQjPlP_rqpWjgIo,23313
|
|
24
|
-
mplang/core/expr/printer.py,sha256=ONqmkdF1k8TseRxpjvWHcJmM6_kEm36VsLm6K7DOvTs,9661
|
|
25
|
-
mplang/core/expr/transformer.py,sha256=gez9eedVsWoLasSgWvPmGR8WfQnGXPlldWeVFEjqyYo,4904
|
|
26
|
-
mplang/core/expr/utils.py,sha256=VDTJ_-CsdHtVy9wDaGa7XdFxQ7o5lYYaeqcgsAhkbNI,2625
|
|
27
|
-
mplang/core/expr/visitor.py,sha256=2Ge-I5N-wH8VVXy8d2WyNaEv8x6seiRx9peyH9S2BYU,2044
|
|
28
|
-
mplang/core/expr/walk.py,sha256=lXkGJEEuvKGDqQihbxXPxfz2RfR1Q1zYUlt11iooQW0,11889
|
|
29
|
-
mplang/kernels/__init__.py,sha256=eooIUklLSg-cvyGk6uDSwZ3bUAjM6AXtHw_YdbUamYo,1052
|
|
30
|
-
mplang/kernels/base.py,sha256=-YV4Aj5fs6GT4ehS6Tyi8WQ-amxn5edHTFJRQzyjHXY,3826
|
|
31
|
-
mplang/kernels/basic.py,sha256=AoYFhaE4-Gmo4BKNnB556aZdr__4G0EAtFyABz0YzZs,8902
|
|
32
|
-
mplang/kernels/context.py,sha256=jkOv0GozvRjMCtryasRoCzbIHV1t708FonmK9Mu2RUE,13927
|
|
33
|
-
mplang/kernels/crypto.py,sha256=9dBKiGIOr14VqhEAEgjMiEAyHKCK8tDXvgsN8aRAs7k,4317
|
|
34
|
-
mplang/kernels/fhe.py,sha256=n92_Y-hmhs6Xn5MT1tut6FYOiIdGTpBfIu9a1oBHhjg,30769
|
|
35
|
-
mplang/kernels/mock_tee.py,sha256=2VmiamP0vvOuEO22yespQUMdjn6i5PDrPCDb_wFs6cg,2486
|
|
36
|
-
mplang/kernels/phe.py,sha256=qSjwtzIs7pxAwRsPdsvLBDqQ0WfAb-AkXHoCD9y3EBA,72676
|
|
37
|
-
mplang/kernels/spu.py,sha256=QaJmecNKdp1qPfdc2DEV9l4ew6kLElGNabufG_6co94,12477
|
|
38
|
-
mplang/kernels/sql_duckdb.py,sha256=MVte7Fe7sCIbYzYGGrydlwEGW-WE5a7dwOckKw-2INE,1625
|
|
39
|
-
mplang/kernels/stablehlo.py,sha256=0OnYadEwhtdZVGCz0FhWOIK-YhcDFAorZH7yMcMd-sU,3225
|
|
40
|
-
mplang/kernels/value.py,sha256=2NZ0UvaLyRYb3bTCqL_fQXMzbHk1qbQ3j9xiv4v5E0A,20726
|
|
41
|
-
mplang/ops/__init__.py,sha256=QIRs49KTG-vUavhUiRHuYFZWrlKh97kwb2nVGHmxII0,1014
|
|
42
|
-
mplang/ops/base.py,sha256=Ne1PtcixBX03fj9cB3xljFS3xNaGBCNEd0_vlT9leug,18159
|
|
43
|
-
mplang/ops/basic.py,sha256=3cuO-srADWLELwyaUNrgOq_0rdW5NPmvkhAaKJs-Cj8,9207
|
|
44
|
-
mplang/ops/crypto.py,sha256=_r0yax_2b0asewhPhSMqM_a2V5EpzI0WOrBN-f-xWxU,3610
|
|
45
|
-
mplang/ops/fhe.py,sha256=EDOaOng_QYjZMqs3nqaag0G5FJ2Ufqdf1NBacfno4Cc,9512
|
|
46
|
-
mplang/ops/ibis_cc.py,sha256=2Us8mHYGjhCzhT9AvZJLkK9VSyJtD0f_VdjBCc97ll8,4154
|
|
47
|
-
mplang/ops/jax_cc.py,sha256=jx4Va5BPSQ2Hcv-dQAQogsir4Ai6c4ShMzPkJcm9KhI,7741
|
|
48
|
-
mplang/ops/phe.py,sha256=Pd146phPLQCX4SDm7lYU2g0pkKZGbVaD1JG2PAvTIFU,6754
|
|
49
|
-
mplang/ops/spu.py,sha256=hdS6fu8L4yxRp1PZyLWQh9SmFV0kHbCZaTJrSL4W_uE,4921
|
|
50
|
-
mplang/ops/sql_cc.py,sha256=-9uf75gOxLQlFiKjDm75qIx8Gbun7unvkOxezdSLGlE,2112
|
|
51
|
-
mplang/ops/tee.py,sha256=2xrDLNRxEPHZrQX1_b_lauyQqoPa1-Fe_KLUi2XFQpQ,1245
|
|
52
|
-
mplang/protos/v1alpha1/mpir_pb2.py,sha256=Bros37t-4LMJbuUYVSM65rImUYTtZDhNTIADGbZCKp0,7522
|
|
53
|
-
mplang/protos/v1alpha1/mpir_pb2.pyi,sha256=dLxAtFW7mgFR-HYxC4ExI4jbtEWUGTKBvcKhI3BJ8m0,20972
|
|
54
|
-
mplang/protos/v1alpha1/value_pb2.py,sha256=V9fqQTqXNo2efYmlP9xOhC7EpjBUp5jL-05yrJsAvWU,2785
|
|
55
|
-
mplang/protos/v1alpha1/value_pb2.pyi,sha256=47GVvuZfiV5oaVemwh0xTfns8OYTVBT8YnluIQeQPbs,7108
|
|
56
|
-
mplang/runtime/__init__.py,sha256=IRPP3TtpFC4iSt7_uaq-S4dL7CwrXL0XBMeaBoEYLlg,948
|
|
57
|
-
mplang/runtime/cli.py,sha256=wOhpNjf_d0MKOBv1DC1I7d5RniiaYYqiCyYa3xfz-s8,15334
|
|
58
|
-
mplang/runtime/client.py,sha256=v73cFnwN7ePaGJmPi20waizeIq6dlJTjEs6OkybSR2M,15858
|
|
59
|
-
mplang/runtime/communicator.py,sha256=Fac53r-YtQBTr21r8vn_ZWgKsagZQ2-D6H3G6LC_5uo,3967
|
|
60
|
-
mplang/runtime/data_providers.py,sha256=-rnYbmQBLzhr5PJS6pw_dSqE_ZiiGKI4nyx24oCmwvA,8241
|
|
61
|
-
mplang/runtime/driver.py,sha256=UhYeLemlRIyFEVHfl8mdCkIi7h0eZ7h-IJrt9jXzP6k,11602
|
|
62
|
-
mplang/runtime/exceptions.py,sha256=c18U0xK20dRmgZo0ogTf5vXlkix9y3VAFuzkHxaXPEk,981
|
|
63
|
-
mplang/runtime/http_api.md,sha256=-re1DhEqMplAkv_wnqEU-PSs8tTzf4-Ml0Gq0f3Go6s,4883
|
|
64
|
-
mplang/runtime/link_comm.py,sha256=ZHNcis8QDu2rcyyF3rhpxMiJDkczoMA_c0iZ2GDW_bA,2793
|
|
65
|
-
mplang/runtime/server.py,sha256=g8oXOOuydmkWbMk0UHkYFB5jzk8QEE3mv2tG2-r7X3E,16584
|
|
66
|
-
mplang/runtime/session.py,sha256=5Qsa9AVQSn3Xn_GVpbDOqQE-ISE0Lquuyk4bjvnIP38,10747
|
|
67
|
-
mplang/runtime/simulation.py,sha256=_GBKJmstNa2-jEEh1IbIeRSUaySAbPCNaLD5gDX0Ev0,11463
|
|
68
|
-
mplang/simp/__init__.py,sha256=2WE4cmW96Xkzyq2yRRYNww4kZ5o6u6NbPV0BxqZG698,581
|
|
69
|
-
mplang/simp/api.py,sha256=JZQqwvlnmJnKacD6fVweLU2qhB-bMlAqvQ24SWYMfVI,11615
|
|
70
|
-
mplang/simp/mpi.py,sha256=Tcan18iV1_SzAEsQNkwhTjwl7VPRr8l4GZCyXIUs8xI,4748
|
|
71
|
-
mplang/simp/party.py,sha256=jl-_K4CNj9lA9ZW5hgmoxvqtliXcL3PLWRdu3C7i4fo,8211
|
|
72
|
-
mplang/simp/random.py,sha256=-OJ4sJcqb-xDTAZoHRER7dbGRwmaymYz0CT4DPjzMlw,3837
|
|
73
|
-
mplang/simp/smpc.py,sha256=tdH54aU4T-GIDPhpmf9NCeJC0G67PdOYc04cyUkOnwE,7119
|
|
74
|
-
mplang/utils/__init__.py,sha256=2WE4cmW96Xkzyq2yRRYNww4kZ5o6u6NbPV0BxqZG698,581
|
|
75
|
-
mplang/utils/crypto.py,sha256=rvPomBFtznRHc3RPi6Aip9lsU8zW2oxBqGv1K3vn7Rs,1052
|
|
76
|
-
mplang/utils/func_utils.py,sha256=vCJcZmu0bEbqhOQKdpttV2_MBllIcPSN0b8U4WjNGGo,5164
|
|
77
|
-
mplang/utils/spu_utils.py,sha256=S3L9RBkBe2AvSuMSQQ12cBY5Y1NPthubvErSX_7nj1A,4158
|
|
78
|
-
mplang/utils/table_utils.py,sha256=cCDDIL_F8St2hLRR5dmcTjv8-2WYjzUSDtSyJcEkhWM,2729
|
|
79
|
-
mplang_nightly-0.1.dev192.dist-info/METADATA,sha256=1QZCuKtNJT5K6SwjCYAc_-S_yGc7HfO-Ua-TKzXBUMc,16609
|
|
80
|
-
mplang_nightly-0.1.dev192.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
81
|
-
mplang_nightly-0.1.dev192.dist-info/entry_points.txt,sha256=mG1oJT-GAjQR834a62_QIWb7litzWPPyVnwFqm-rWuY,55
|
|
82
|
-
mplang_nightly-0.1.dev192.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
83
|
-
mplang_nightly-0.1.dev192.dist-info/RECORD,,
|
/mplang/{core → v1/core}/mask.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mplang_nightly-0.1.dev192.dist-info → mplang_nightly-0.1.dev268.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{mplang_nightly-0.1.dev192.dist-info → mplang_nightly-0.1.dev268.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|