Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mdip226/gillespy2.remote #948

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ff975c6
typo I think
mdip226 May 28, 2023
07143f8
mass import
mdip226 May 28, 2023
2e609b3
save draft
mdip226 May 29, 2023
a28eb72
initial port done!
mdip226 May 29, 2023
b84ee86
basically switch naming
mdip226 May 29, 2023
4e6d990
decisons
mdip226 May 29, 2023
5c4bb13
typing typing typing
mdip226 May 29, 2023
9341a3c
namespaces
mdip226 May 29, 2023
9b7cf09
break
mdip226 May 29, 2023
432bf43
save
mdip226 May 29, 2023
3ea5baa
quicksave
mdip226 Jun 12, 2023
7d09018
consolidate
mdip226 Jun 14, 2023
7be4288
save
mdip226 Jun 14, 2023
4a45bfc
accept request object
mdip226 Jul 18, 2023
818d2fb
cleanup
mdip226 Jul 19, 2023
fab953a
typo
mdip226 Jul 19, 2023
1b3286a
debug stuff
mdip226 Jul 19, 2023
7278e93
cut out
mdip226 Jul 19, 2023
65cbc6a
handle it here!
mdip226 Jul 19, 2023
ed66fd8
still need to do is_cached
mdip226 Jul 19, 2023
9cf79c7
typo
mdip226 Jul 19, 2023
c311757
moved check
mdip226 Jul 19, 2023
e8b697e
handy dev feature
mdip226 Jul 19, 2023
a56acdf
update version
mdip226 Jul 19, 2023
bfd0ffa
fix imports
mdip226 Jul 19, 2023
d3b8a33
adding parallelization
mdip226 Jul 19, 2023
7e501ed
parallelization
mdip226 Jul 19, 2023
962973b
for erroneous status stuff
mdip226 Jul 20, 2023
75ccc58
handling ex.
mdip226 Jul 20, 2023
4d7e0d2
formatting
mdip226 Jul 20, 2023
31f1b47
new parameter
mdip226 Jul 20, 2023
1dca5f7
put namespace logic here
mdip226 Jul 20, 2023
1a3ee3b
quicksave
mdip226 Jul 20, 2023
14af776
namespace
mdip226 Jul 20, 2023
6d68058
finish namespace
mdip226 Jul 20, 2023
e4a3cad
unneeded?
mdip226 Jul 24, 2023
7724e4f
new option
mdip226 Jul 24, 2023
5ca07e9
add endpoints
mdip226 Jul 24, 2023
fee1652
new endpoints
mdip226 Jul 24, 2023
41cad70
cleanup
mdip226 Jul 24, 2023
0a78403
factory method
mdip226 Jul 24, 2023
a5010ee
run_distributed
mdip226 Jul 24, 2023
6b82c38
cleanup
mdip226 Jul 24, 2023
6514095
debug and cleanup
mdip226 Jul 24, 2023
b4b79f5
init
mdip226 Jul 24, 2023
4b62fa1
silences those logs
mdip226 Jul 24, 2023
413fd7e
typo
mdip226 Jul 24, 2023
785fcdc
add handlers
mdip226 Jul 24, 2023
3714782
cleanup
mdip226 Jul 24, 2023
4c1d786
new handler
mdip226 Jul 24, 2023
ff192b1
new handler
mdip226 Jul 24, 2023
b0e5723
debug
mdip226 Jul 24, 2023
d4a4f5b
cleanup and debug
mdip226 Jul 24, 2023
6cd00c1
cleanup
mdip226 Jul 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ __pycache__
htmlcov
/build
.idea

env/
23 changes: 23 additions & 0 deletions gillespy2/remote/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
gillespy2.remote
'''
# Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


from gillespy2.remote.client import *
from gillespy2.remote.core import *
from gillespy2.remote.server import *
from gillespy2.remote.cloud import *
38 changes: 38 additions & 0 deletions gillespy2/remote/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# '''
# gillespy2.remote.__version__
# '''
# # StochSS-Compute is a tool for running and caching GillesPy2 simulations remotely.
# # Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# # This program is free software: you can redistribute it and/or modify
# # it under the terms of the GNU General Public License as published by
# # the Free Software Foundation, either version 3 of the License, or
# # (at your option) any later version.

# # This program is distributed in the hope that it will be useful,
# # but WITHOUT ANY WARRANTY; without even the implied warranty of
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# # GNU General Public License for more details.

# # You should have received a copy of the GNU General Public License
# # along with this program. If not, see <http://www.gnu.org/licenses/>.


# # =============================================================================
# # @file __version__.py
# # @brief stochss-compute version info
# # @license Please see the file named LICENSE.md in parent directory
# # @website https://github.com/StochSS/stochss-compute
# # =============================================================================


# __version__ = '1.0.1'

# __title__ = "stochss-compute"
# __description__ = "A compute delegation package for the StochSS family of stochastic simulators"
# __url__ = "https://github.com/StochSS/stochss-compute"
# __download_url__ = "https://pypi.org/project/stochss-compute/#files"
# __author__ = "See CONTRIBUTORS.md"
# __email__ = "[email protected]"
# __license__ = "GPLv3"
# __copyright__ = "Copyright (C) 2017-2023"
19 changes: 19 additions & 0 deletions gillespy2/remote/client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'''
gillespy2.remote.client
'''
# Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .compute_server import ComputeServer
46 changes: 46 additions & 0 deletions gillespy2/remote/client/compute_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'''
ComputeServer(Server)
'''
# StochSS-Compute is a tool for running and caching GillesPy2 simulations remotely.
# Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from gillespy2.remote.client.server import Server

class ComputeServer(Server):
'''
Simple object representing a remote instance of StochSS-Compute.

:param host: Address of the remote server.
:type host: str

:param port: Port on which to connect. Defaults to 29681.
:type port: int
'''
# pylint: disable=super-init-not-called
def __init__(self, host: str, port: int = 29681):
host = host.replace('http://','')
host = host.split(':')[0]
self._address = f"http://{host}:{port}"
# pylint: enable=super-init-not-called

@property
def address(self) -> str:
"""
The server's IP address and port.

:returns: "http://{host}:{port}"
"""
return self._address
30 changes: 30 additions & 0 deletions gillespy2/remote/client/endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'''
Endpoint(Enum)
'''
# StochSS-Compute is a tool for running and caching GillesPy2 simulations remotely.
# Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from enum import Enum

class Endpoint(Enum):
'''
API Endpoints.
'''
SIMULATION_GILLESPY2 = 1
CLOUD = 2
CACHE = 3
DASK = 4

135 changes: 135 additions & 0 deletions gillespy2/remote/client/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
'''
Server(ABC)
'''
# StochSS-Compute is a tool for running and caching GillesPy2 simulations remotely.
# Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from time import sleep
from abc import ABC, abstractmethod
import requests
from gillespy2.remote.client.endpoint import Endpoint
from gillespy2.remote.core.messages.base import Request

from gillespy2.remote.core.utils.log_config import init_logging
log = init_logging(__name__)

class Server(ABC):
'''
Abstract Server class with hard coded endpoints.

:raises TypeError: Server cannot be instantiated directly. Must be ComputeServer or Cluster.
'''

_endpoints = {
Endpoint.SIMULATION_GILLESPY2: "/api/v3/simulation/gillespy2",
Endpoint.CLOUD: "/api/v3/cloud",
Endpoint.CACHE: "/api/v3/cache",
Endpoint.DASK: '/api/v3/dask',
}

def __init__(self) -> None:
raise TypeError('Server cannot be instantiated directly. Must be ComputeServer or Cluster.')

@property
@abstractmethod
def address(self):
'''
NotImplemented
'''
return NotImplemented

def get(self, endpoint: Endpoint, sub: str, request: Request = None):
'''
Send a GET request to endpoint.

:param endpoint: The API endpoint.
:type endpoint: Endpoint

:param sub: Final part of url string.
:type sub: str

:param request: An object that inherits from Request.
:type request: Request

:returns: The HTTP response.
:rtype: requests.Response
'''
if request is not None:
log.debug(request.encode())
url = f"{self.address}{self._endpoints[endpoint]}{sub}"
log.debug(url)
n_try = 1
sec = 3
while n_try <= 3:
try:
if request is not None:
return requests.get(url, timeout=30, params=request.encode())
return requests.get( url, timeout=30)

except ConnectionError:
print(f"Connection refused by server. Retrying in {sec} seconds....")
sleep(sec)
n_try += 1
sec *= n_try
except Exception as err:
print(f"Unknown error: {err}. Retrying in {sec} seconds....")
sleep(sec)
n_try += 1
sec *= n_try

def post(self, endpoint: Endpoint, sub: str, request: Request = None):
'''
Send a POST request to endpoint.

:param endpoint: The API endpoint.
:type endpoint: Endpoint

:param sub: Final part of url string.
:type sub: str

:param request: An object that inherits from Request.
:type request: Request

:returns: The HTTP response.
:rtype: requests.Response
'''
log.debug(request.encode())

if self.address is NotImplemented:
raise NotImplementedError

url = f"{self.address}{self._endpoints[endpoint]}{sub}"
log.debug(url)
n_try = 1
sec = 3
while n_try <= 3:
try:
if request is None:
print(f"[POST] {url}")
return requests.post(url, timeout=30)
print(f"[{type(request).__name__}] {url}")
return requests.post(url, json=request.encode(), timeout=30)

except ConnectionError:
print(f"Connection refused by server. Retrying in {sec} seconds....")
sleep(sec)
n_try += 1
sec *= n_try
except Exception as err:
print(f"Unknown error: {err}. Retrying in {sec} seconds....")
sleep(sec)
n_try += 1
sec *= n_try
21 changes: 21 additions & 0 deletions gillespy2/remote/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''
gillespy2.remote.cloud
'''
# StochSS-Compute is a tool for running and caching GillesPy2 simulations remotely.
# Copyright (C) 2019-2023 GillesPy2 and StochSS developers.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .ec2 import EC2Cluster
from .ec2_config import EC2LocalConfig, EC2RemoteConfig
Loading