Skip to content

Commit

Permalink
Dev/mip 941/validate proper parallel execution (#496)
Browse files Browse the repository at this point in the history
* Fixed a bug on logistic regression's client.

* Added a test that validates the parallel execution of flower algorithms.
  • Loading branch information
KFilippopolitis authored Oct 5, 2024
1 parent 878262f commit 39a249d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exareme2/algorithms/flower/logistic_regression/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def evaluate(self, parameters, config):
fl.client.start_client(
server_address=os.environ["SERVER_ADDRESS"], client=client.to_client()
)
FLOWER_LOGGER.debug("Connection successful on attempt", attempts + 1)
FLOWER_LOGGER.debug(f"Connection successful on attempt: {attempts + 1}")
break
except Exception as e:
FLOWER_LOGGER.warning(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import concurrent.futures
import json

import pytest
import requests

from tests.standalone_tests.conftest import ALGORITHMS_URL


@pytest.mark.slow
def test_parallel_requests_in_algorithm_flow(
globalworker_worker_service,
localworker1_worker_service,
load_data_localworker1,
load_test_data_globalworker,
controller_service_with_localworker1,
):
algorithm_name = "logistic_regression"
request_dict = {
"inputdata": {
"y": ["gender"],
"x": ["lefthippocampus"],
"data_model": "dementia:0.1",
"datasets": [
"ppmi0",
"ppmi1",
"ppmi2",
"ppmi3",
],
"validation_datasets": ["ppmi_test"],
"filters": None,
},
"type": "flower",
}

algorithm_url = ALGORITHMS_URL + "/" + algorithm_name

headers = {"Content-type": "application/json", "Accept": "text/plain"}

num_requests = 5 # Number of parallel requests

def send_request():
response = requests.post(
algorithm_url,
data=json.dumps(request_dict),
headers=headers,
)
assert response.status_code == 200
return response.json()

with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(send_request) for _ in range(num_requests)]
results = [
future.result() for future in concurrent.futures.as_completed(futures)
]

expected_result = {"accuracy": 0.63}

for result in results:
assert result == expected_result

0 comments on commit 39a249d

Please sign in to comment.