Skip to content

Commit

Permalink
Merge pull request #5383 from FederatedAI/feature-2.0.0-rc-add-contex…
Browse files Browse the repository at this point in the history
…t-create-helper

feature 2.0.0 rc add context create helper
  • Loading branch information
talkingwallace authored Dec 27, 2023
2 parents e18ef6b + 80959d2 commit 1e9758b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/fate/arch/computing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ._builder import ComputingBuilder
from ._builder import ComputingBuilder, ComputingEngine
2 changes: 1 addition & 1 deletion python/fate/arch/computing/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
def build(self, t: ComputingEngine, conf: dict):
if t == ComputingEngine.STANDALONE:
data_dir = cfg.get_option(conf, "computing.standalone.data_dir")
options = cfg.get_option(conf, "computing.standalone.options")
options = cfg.get_option(conf, "computing.standalone.options", None)
return self.build_standalone(data_dir=data_dir, options=options)
elif t == ComputingEngine.EGGROLL:
host = cfg.get_option(conf, "computing.eggroll.host")
Expand Down
3 changes: 2 additions & 1 deletion python/fate/arch/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
from ._context import Context
from ._namespace import NS
from ._parties import Parties
from ._context_helper import create_context

__all__ = ["Context", "CipherKit", "PHECipher", "PHECipherPublic", "NS", "Parties"]
__all__ = ["Context", "CipherKit", "PHECipher", "PHECipherPublic", "NS", "Parties", "create_context"]
35 changes: 35 additions & 0 deletions python/fate/arch/context/_context_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import Tuple, List

from fate.arch.computing import ComputingBuilder, ComputingEngine
from fate.arch.context import Context
from fate.arch.federation import FederationBuilder, FederationType


def create_context(
local_party: Tuple[str, str],
parties: List[Tuple[str, str]],
federation_session_id,
federation_engine=FederationType.STANDALONE,
federation_conf: dict = None,
computing_session_id=None,
computing_engine=ComputingEngine.STANDALONE,
computing_conf=None,
):
if federation_conf is None:
federation_conf = {}
if computing_conf is None:
computing_conf = {}
if ComputingEngine.STANDALONE == computing_engine:
if "computing.standalone.data_dir" not in computing_conf:
computing_conf["computing.standalone.data_dir"] = "/tmp"
if computing_session_id is None:
computing_session_id = f"{federation_session_id}_{local_party[0]}_{local_party[1]}"
computing_session = ComputingBuilder(computing_session_id=computing_session_id).build(
computing_engine, computing_conf
)
federation_session = FederationBuilder(
federation_id=federation_session_id,
party=local_party,
parties=parties,
).build(computing_session, federation_engine, federation_conf)
return Context(computing=computing_session, federation=federation_session)
4 changes: 2 additions & 2 deletions python/fate/arch/federation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ._builder import FederationBuilder, FederationMode
from ._builder import FederationBuilder, FederationMode, FederationType
from .api import Federation, FederationDataType, TableMeta

__all__ = ["Federation", "FederationDataType", "FederationBuilder", "FederationMode"]
__all__ = ["Federation", "FederationDataType", "FederationBuilder", "FederationMode", "FederationType", "TableMeta"]

0 comments on commit 1e9758b

Please sign in to comment.