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

Align configs. #952

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
117 changes: 0 additions & 117 deletions tests/test_web/test_auth.py

This file was deleted.

1 change: 1 addition & 0 deletions tests/test_web/test_tidy3d_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

test_env = EnvironmentConfig(
name="test",
s3_region="test",
web_api_endpoint="https://test",
website_endpoint="https://test",
)
Expand Down
5 changes: 2 additions & 3 deletions tidy3d/plugins/dispersion/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ...components.types import Ax, ArrayFloat1D
from ...constants import C_0, HBAR, MICROMETER
from ...exceptions import ValidationError, WebError, SetupError
from ...web.config import DEFAULT_CONFIG as Config
from ...web.environment import Env


class DispersionFitter(Tidy3dBaseModel):
Expand Down Expand Up @@ -649,8 +649,7 @@ def from_url(cls, url_file: str, delimiter: str = ",", ignore_k: bool = False, *
:class:`DispersionFitter`
A :class:`DispersionFitter` instance.
"""

resp = requests.get(url_file, verify=Config.ssl_verify)
resp = requests.get(url_file, verify=Env.current.ssl_verify)

try:
resp.raise_for_status()
Expand Down
28 changes: 10 additions & 18 deletions tidy3d/plugins/dispersion/fit_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
from ...components.medium import PoleResidue
from ...constants import MICROMETER, HERTZ
from ...exceptions import WebError, Tidy3dError, SetupError
from ...web.environment import Env
from ...web.httputils import get_headers
from ...web.config import DEFAULT_CONFIG as Config
from .fit import DispersionFitter


BOUND_MAX_FACTOR = 10


Expand Down Expand Up @@ -139,8 +138,8 @@ class FitterData(AdvancedFitterParam):

URL_ENV = {
"local": "http://127.0.0.1:8000",
"dev": "https://tidy3d-service.dev-simulation.cloud",
"prod": "https://tidy3d-service.simulation.cloud",
Env.dev: "https://tidy3d-service.dev-simulation.cloud",
Env.prod: "https://tidy3d-service.simulation.cloud",
}


Expand All @@ -152,25 +151,18 @@ class ExceptionCodes(Enum):


class StableDispersionFitter(DispersionFitter):

"""Stable fitter based on web service"""

@staticmethod
def _set_url(config_env: Literal["default", "dev", "prod", "local"] = "default"):
def _set_url(_: Literal["default", "dev", "prod", "local"] = "default"):
"""Set the url of python web service

Parameters
----------
config_env : Literal["default", "dev", "prod", "local"], optional
_ : Literal["default", "dev", "prod", "local"], optional
Service environment to pick from
"""

_env = config_env
if _env == "default":
from ...web.config import DEFAULT_CONFIG # pylint:disable=import-outside-toplevel

_env = "dev" if "dev" in DEFAULT_CONFIG.web_api_endpoint else "prod"
return URL_ENV[_env]
return URL_ENV[Env.current]

@staticmethod
def _setup_server(url_server: str):
Expand All @@ -184,12 +176,12 @@ def _setup_server(url_server: str):

try:
# test connection
resp = requests.get(f"{url_server}/health", verify=Config.ssl_verify)
resp = requests.get(f"{url_server}/health", verify=Env.current.ssl_verify)
resp.raise_for_status()
except (requests.exceptions.SSLError, ssl.SSLError):
log.info("disable the ssl verify and retry")
Config.ssl_verify = False
resp = requests.get(f"{url_server}/health", verify=Config.ssl_verify)
Env.current.ssl_verify = False
resp = requests.get(f"{url_server}/health", verify=Env.current.ssl_verify)
except Exception as e:
raise WebError("Connection to the server failed. Please try again.") from e

Expand Down Expand Up @@ -293,7 +285,7 @@ def fit( # pylint:disable=arguments-differ, too-many-locals
f"{url_server}/dispersion/fit",
headers=headers,
data=web_data.json(),
verify=Config.ssl_verify,
verify=Env.current.ssl_verify,
)

try:
Expand Down
1 change: 0 additions & 1 deletion tidy3d/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .webapi import run, upload, get_info, start, monitor, delete, download, load, estimate_cost
from .webapi import get_tasks, delete_old, download_json, download_log, load_simulation, real_cost
from .container import Job, Batch, BatchData
from .auth import get_credentials
from .cli import tidy3d_cli
from .cli.app import configure_fn as configure
from .asynchronous import run_async
Expand Down
Loading