Skip to content

Commit

Permalink
Merge pull request #103 from volkamerlab/fix-klifs-parallelization
Browse files Browse the repository at this point in the history
KLIFS module: RecursionError with parallelization... again!
  • Loading branch information
dominiquesydow authored Sep 16, 2021
2 parents bab881d + 11526c8 commit cdd450b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion opencadd/databases/klifs/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
FIELDS,
POCKET_KLIFS_REGIONS,
)
from .utils import KLIFS_CLIENT, PATH_DATA, metadata_to_filepath, filepath_to_metadata
from .utils import PATH_DATA, metadata_to_filepath, filepath_to_metadata
from .remote import KLIFS_CLIENT
from .exceptions import KlifsPocketIncompleteError, KlifsPocketUnequalSequenceStructure
from opencadd.io import DataFrame, Rdkit

Expand Down
6 changes: 6 additions & 0 deletions opencadd/databases/klifs/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def __getstate__(self, *args):
}


KLIFS_API_DEFINITIONS = "https://dev.klifs.net/swagger_v2/swagger.json"
KLIFS_CLIENT = SerializableSwaggerClient.from_url(
KLIFS_API_DEFINITIONS, config={"validate_responses": False}
)


class RemoteInitializer:
"""
Base class used to define __init__ for all remote classes.
Expand Down
2 changes: 1 addition & 1 deletion opencadd/databases/klifs/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from . import remote
from . import local
from .utils import KLIFS_CLIENT
from .remote import KLIFS_CLIENT


class Session:
Expand Down
5 changes: 0 additions & 5 deletions opencadd/databases/klifs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
from pathlib import Path
import re

from bravado.client import SwaggerClient

_logger = logging.getLogger(__name__)

KLIFS_API_DEFINITIONS = "https://dev.klifs.net/swagger_v2/swagger.json"
KLIFS_CLIENT = SwaggerClient.from_url(KLIFS_API_DEFINITIONS, config={"validate_responses": False})

PATH_DATA = Path(__file__).parent / ".." / ".." / "data"


Expand Down
35 changes: 35 additions & 0 deletions opencadd/tests/databases/test_klifs_remote_parallelization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Tests for opencadd.databases.klifs.remote parallelization!
"""

from itertools import repeat
from multiprocessing import Pool

import pytest

from opencadd.databases.klifs import setup_remote

# Set local session
REMOTE = setup_remote()


@pytest.mark.parametrize(
"klifs_session, structure_klifs_ids, n_cores",
[(REMOTE, [111, 113], 2)],
)
def test_remote_parallelization(klifs_session, structure_klifs_ids, n_cores):

pool = Pool(processes=n_cores)

pool.starmap(_parallelize_klifs_session, zip(structure_klifs_ids, repeat(klifs_session)))
pool.close()
pool.join()


def _parallelize_klifs_session(structure_klifs_id, klifs_session):
"""
Dummy function that simulates a function that takes the KLIFS session as input;
shall be used in our test where we want to pass a single klifs_session to multiple functions
that are called in a parallelized process.
"""
return klifs_session.structures.by_structure_klifs_id(structure_klifs_id)
2 changes: 1 addition & 1 deletion opencadd/tests/databases/test_sync_klifs_and_opencadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
If errors are raised, it is time to update opencadd.
"""

from opencadd.databases.klifs.utils import KLIFS_CLIENT
from opencadd.databases.klifs.remote import KLIFS_CLIENT
from opencadd.databases.klifs.schema import FIELDS


Expand Down

0 comments on commit cdd450b

Please sign in to comment.