Skip to content

webapi refactor #665

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,61 @@ The source code for our documentation is [here](https://github.com/flexcompute-r
Note that while this front end package is open source, to run simulations on Flexcompute servers requires an account with credits.
You can sign up [here](https://client.simulation.cloud/register-waiting). While it's currently a waitlist for new users, we will be rolling out to many more users in the coming weeks! See [this page](https://flexcompute-tidy3ddocumentation.readthedocs-hosted.com/quickstart.html) in our documentation for more details.

### Installing the package using pip
### Installing the front end

#### Using pip (recommended)

The easiest way to install tidy3d is through [pip](https://pip.pypa.io/en/stable/).

```
pip install tidy3d
```

### (Alternativelty) installing from source
### Installing from source

For development purposes, you can download and install the package from source as:
For development purposes, and to get the latest development versions, you can download and install the package from source as:

```
git clone https://github.com/flexcompute/tidy3d.git
cd tidy3d
pip install -e .
```

### Did it work?
### Configuring and authentication

Authentication (linking the front end to your account) will be done via an API key moving forward.

You can find your API key in the web interface http://tidy3d.simulation.cloud

After signing in, copy the API key for the next steps.

To set up the API key to work with Tidy3D, we need to store it either in the `~/.tidy3d/config` file or an environment variable.

You can set it up using one of three following options.

#### Command line (recommended)

``tidy3d configure`` and then enter your API key when prompted.

#### Manually

For an API key of `{your_api_key}`, you may run

``echo 'apikey = "{your_api_key}"' > ~/.tidy3d/config``

You can verify the installation worked by running:
or manually insert the line `'apikey = "{your_api_key}"` in the `~/.tidy3d/config` file.

#### Environment Variable

Set the `SIMCLOUD_API_KEY` environment variable to your API key (in quotes).

``export SIMCLOUD_API_KEY="{your_api_key}"``

### Testing the installation and authentication

#### Front end package

You can verify the front end installation worked by running:

```
python -c "import tidy3d as td; print(td.__version__)"
Expand All @@ -61,6 +95,14 @@ and it should print out the version number, for example:
1.0.0
```

#### Authentication

To test the web / authentication

```
python -c "import tidy3d.web"
```

## Issues / Feedback / Bug Reporting

Your feedback helps us immensely!
Expand Down
3 changes: 2 additions & 1 deletion requirements/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ matplotlib
shapely>=2.0
pydantic>=1.10.0
PyYAML
dask
dask
toml
1 change: 0 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-r core.txt

# required for development
click==8.0.3
black==22.3.0
pylint
tox
Expand Down
4 changes: 3 additions & 1 deletion requirements/web.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

boto3==1.23.1
requests
pyjwt
pyjwt
click==8.0.3
responses
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import setuptools
from distutils.util import convert_path


PACKAGE_NAME = "tidy3d"
REPO_NAME = "tidy3d"

Expand Down Expand Up @@ -51,4 +50,9 @@ def read_requirements(req_file: str):
python_requires=">=3.7",
install_requires=core_required,
extras_require={"dev": dev_required},
entry_points={
"console_scripts": [
"tidy3d = tidy3d.web.cli:tidy3d_cli",
],
},
)
23 changes: 23 additions & 0 deletions tests/test_web/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os.path
import shutil

from click.testing import CliRunner

from tidy3d.web.cli import tidy3d_cli
from tidy3d.web.cli.app import CONFIG_FILE


def test_tidy3d_cli():

if os.path.exists(CONFIG_FILE):
shutil.move(CONFIG_FILE, f"{CONFIG_FILE}.bak")

runner = CliRunner()
result = runner.invoke(tidy3d_cli, ["configure"], input="apikey")

assert result.exit_code == 0
if os.path.exists(CONFIG_FILE):
os.remove(CONFIG_FILE)

if os.path.exists(f"{CONFIG_FILE}.bak"):
shutil.move(f"{CONFIG_FILE}.bak", CONFIG_FILE)
62 changes: 62 additions & 0 deletions tests/test_web/test_material_fitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import re

import responses
from tidy3d.plugins import DispersionFitter

from tidy3d.web.environment import Env
from tidy3d.web.material_fitter import FitterOptions, MaterialFitterTask

Env.dev.active()


@responses.activate
def test_material_fitter(monkeypatch):
fitter = DispersionFitter.from_file("tests/data/nk_data.csv", skiprows=1, delimiter=",")

monkeypatch.setattr("tidy3d.web.material_fitter.uuid4", lambda: "fitter_id")

responses.add(
responses.GET,
re.compile(f"{Env.current.web_api_endpoint}/tidy3d/fitter/.*"),
json={"data": "https://example.com"},
status=200,
)
responses.add(
responses.PUT,
"https://example.com",
json={"data": "url"},
status=200,
)

responses.add(
responses.POST,
f"{Env.current.web_api_endpoint}/tidy3d/fitter/fit",
json={
"data": {
"id": "1234",
"status": "RUNNING",
"fileName": "filename",
"resourcePath": "path",
}
},
status=200,
)
task = MaterialFitterTask.submit(fitter, FitterOptions())

responses.add(
responses.GET,
re.compile(f"{Env.current.web_api_endpoint}/tidy3d/fitter/1234"),
json={"data": {"status": "running"}},
status=200,
)
task.sync_status()
task.status == "running"

responses.add(
responses.POST,
f"{Env.current.web_api_endpoint}/tidy3d/fitter/save",
json={"data": True},
status=200,
)
task.status = "COMPLETED"
assert task.save_to_library("test")
57 changes: 57 additions & 0 deletions tests/test_web/test_tidy3d_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import responses
from responses import matchers

from tidy3d.web.simulation_task import Folder
from tidy3d.web.environment import Env

Env.dev.active()


@responses.activate
def test_list_folders():
responses.add(
responses.GET,
f"{Env.current.web_api_endpoint}/tidy3d/projects",
json={"data": [{"projectId": "1234", "projectName": "default"}]},
status=200,
)
resp = Folder.list()
assert resp is not None


@responses.activate
def test_get_folder():
responses.add(
responses.GET,
f"{Env.current.web_api_endpoint}/tidy3d/project?projectName=default",
json={"data": {"projectId": "1234", "projectName": "default"}},
status=200,
)
resp = Folder.get("default")
assert resp is not None


@responses.activate
def test_create_and_remove_folder():
responses.add(
responses.GET,
f"{Env.current.web_api_endpoint}/tidy3d/project",
match=[matchers.query_param_matcher({"projectName": "test folder2"})],
status=404,
)
responses.add(
responses.POST,
f"{Env.current.web_api_endpoint}/tidy3d/projects",
match=[matchers.json_params_matcher({"projectName": "test folder2"})],
json={"data": {"projectId": "1234", "projectName": "test folder2"}},
status=200,
)
responses.add(
responses.DELETE,
f"{Env.current.web_api_endpoint}/tidy3d/projects/1234",
status=200,
)
resp = Folder.create("test folder2")

assert resp is not None
resp.delete()
19 changes: 19 additions & 0 deletions tests/test_web/test_tidy3d_material_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import responses

from tidy3d.web.environment import Env
from tidy3d.web.material_libray import MaterialLibray

Env.dev.active()


@responses.activate
def test_lib():
responses.add(
responses.GET,
f"{Env.current.web_api_endpoint}/tidy3d/libraries",
json={"data": [{"id": "3eb06d16-208b-487b-864b-e9b1d3e010a7", "name": "medium1"}]},
status=200,
)
libs = MaterialLibray.list()
lib = libs[0]
assert lib.name == "medium1"
Loading