Skip to content

Commit

Permalink
FEDN_PACKAGE_DIR added
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Mar 27, 2024
1 parent 107d5b5 commit 3b289fe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion fedn/cli/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"FEDN_TOKEN",
"FEDN_AUTH_SCHEME",
"FEDN_CONTROLLER_URL",
"FEDN_PACKAGE_PATH"
"FEDN_PACKAGE_DIR"
]


Expand Down
20 changes: 13 additions & 7 deletions fedn/cli/run_cmd.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import threading
import uuid

import os
import click
import yaml

from fedn.common.exceptions import InvalidClientConfig
from fedn.common.log_config import logger
from fedn.network.clients.client import Client
from fedn.network.combiner.combiner import Combiner

from .main import main
from .shared import CLIENT_DEFAULTS, COMBINER_DEFAULTS, CONTROLLER_DEFAULTS, get_client_package_path
from .shared import CLIENT_DEFAULTS, COMBINER_DEFAULTS, CONTROLLER_DEFAULTS, get_client_package_dir


def get_statestore_config_from_file(init):
Expand Down Expand Up @@ -118,7 +117,7 @@ def run_cmd(ctx):
@click.option('-n', '--name', required=False, default="client" + str(uuid.uuid4())[:8])
@click.option('-i', '--client_id', required=False)
@click.option('--local-package', is_flag=True, help='Enable local compute package')
@click.option('-pp', '--package-path', required=False, help='Path to local package')
@click.option('-pd', '--package-dir', required=False, help='Path to local package')
@click.option('--force-ssl', is_flag=True, help='Force SSL/TLS for REST service')
@click.option('-u', '--dry-run', required=False, default=False)
@click.option('-s', '--secure', required=False, default=False)
Expand All @@ -135,7 +134,7 @@ def run_cmd(ctx):
@click.option('--reconnect-after-missed-heartbeat', required=False, default=30)
@click.option('--verbosity', required=False, default='INFO', type=click.Choice(['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'], case_sensitive=False))
@click.pass_context
def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_package, package_path, force_ssl, dry_run, secure, preshared_cert,
def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_package, package_dir, force_ssl, dry_run, secure, preshared_cert,
verify, preferred_combiner, validator, trainer, init, logfile, heartbeat_interval, reconnect_after_missed_heartbeat,
verbosity):
"""
Expand All @@ -161,13 +160,20 @@ def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_pa
"""
remote = False if local_package else True

package_path = get_client_package_path(package_path)
package_dir = get_client_package_dir(package_dir)

working_dir = package_dir or f"{os.getcwd()}/client"

if not remote and not os.path.exists(working_dir):
click.echo("fedn.yaml not found. Either set --package-dir or FEDN_PACKAGE_DIR.")
click.echo(f"If neither of these are set, the current working directory will be used. Package dir set to: {working_dir}")
exit(-1)

config = {'discover_host': discoverhost, 'discover_port': discoverport, 'token': token, 'name': name,
'client_id': client_id, 'remote_compute_context': remote, 'force_ssl': force_ssl, 'dry_run': dry_run, 'secure': secure,
'preshared_cert': preshared_cert, 'verify': verify, 'preferred_combiner': preferred_combiner,
'validator': validator, 'trainer': trainer, 'init': init, 'logfile': logfile, 'heartbeat_interval': heartbeat_interval,
'reconnect_after_missed_heartbeat': reconnect_after_missed_heartbeat, 'verbosity': verbosity, 'package_path': package_path}
'reconnect_after_missed_heartbeat': reconnect_after_missed_heartbeat, 'verbosity': verbosity, 'package_dir': package_dir}

if init:
apply_config(config)
Expand Down
4 changes: 2 additions & 2 deletions fedn/cli/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def get_token(token: str) -> str:
return f"{scheme} {_token}"


def get_client_package_path(path: str) -> str:
return path or os.environ.get('FEDN_PACKAGE_PATH', None)
def get_client_package_dir(path: str) -> str:
return path or os.environ.get('FEDN_PACKAGE_DIR', None)
12 changes: 7 additions & 5 deletions fedn/fedn/network/clients/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,17 @@ def _initialize_dispatcher(self, config):
except Exception as e:
logger.error(f"Caught exception: {type(e).__name__}")
else:
run_path: str
from_path: str = None
run_path: str = None

if "package_path" in config and config["package_path"]:
run_path = f"{config['package_path']}/client"
if "package_dir" in config and config["package_dir"]:
path = f"{config['package_dir']}"
run_path = f"{config['package_dir']}"
from_path = path
else:
run_path = os.path.join(os.getcwd(), 'client')


self.dispatcher = pr.dispatcher(run_path)
self.dispatcher = pr.dispatcher(run_path, from_path=from_path)

def get_model_from_combiner(self, id, timeout=20):
"""Fetch a model from the assigned combiner.
Expand Down
8 changes: 5 additions & 3 deletions fedn/fedn/network/clients/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,20 @@ def unpack(self):
logger.error("Error extracting files.")
return False

def dispatcher(self, run_path):
def dispatcher(self, run_path: str, from_path: str = None):
""" Dispatch the compute package
:param run_path: path to dispatch the compute package
:type run_path: str
:param from_path: path to the compute package
:type from_path: str
:return: Dispatcher object
:rtype: :class:`fedn.utils.dispatcher.Dispatcher`
"""
from_path = os.path.join(os.getcwd(), 'client')
_from_path = from_path or os.path.join(os.getcwd(), 'client')

# preserve_times=False ensures compatibility with Gramine LibOS
copy_tree(from_path, run_path, preserve_times=False)
copy_tree(_from_path, run_path, preserve_times=False)

try:
cfg = None
Expand Down

0 comments on commit 3b289fe

Please sign in to comment.