Device Analysis

Now we will run a power envelope analysis on the device data we uploaded in the previous notebook.

As before, make sure you have the following environment variables set or added to a .env file:

GDSFACTORY_HUB_API_URL="https://{org}.gdsfactoryhub.com"
GDSFACTORY_HUB_QUERY_URL="https://query.{org}.gdsfactoryhub.com"
GDSFACTORY_HUB_KEY="<your-gdsfactoryplus-api-key>"
import getpass

from tqdm.auto import tqdm

import gdsfactoryhub as gfh
project_id = f"spirals-{getpass.getuser()}"
client = gfh.create_client_from_env(project_id=project_id)
api = client.api()
query = client.query()

Device Analysis

You can either trigger analysis automatically by defining it in the design manifest, using the UI or using the Python DoData library.

device_data = query.device_data().limit(1).execute().data[0]
from gdsfactoryhub.functions.device_data import rolling_window

rolling_window.run?
rolling_window.run(
    device_data_pkey=device_data["pk"],
    xname="wavelength",
    yname="output_power",
    xlabel="Wavelength [nm]",
    ylabel="Power [mW]",
    x0=1550,
)
result = api.validate_function(
    function_id="rolling-window",
    target_model="device_data",
    test_target_model_pk=device_data["pk"],
    file=gfh.get_module_path(rolling_window),
    test_kwargs={
        "xname": "wavelength",
        "yname": "output_power",
        "xlabel": "Wavelength [nm]",
        "ylabel": "Power [mW]",
        "x0": 1550,
    },
)
result.summary_plot()

Once the function is validated, it can be uploaded to the server. So you can reuse it in other analysis functions.

with gfh.suppress_api_error():
    result = api.upload_function(
        function_id="rolling-window",
        target_model="device_data",
        file=gfh.get_module_path(rolling_window),
    )
device_datas = query.device_data().execute().data

task_ids = []
for device_data in (pb := tqdm(device_datas)):
    task_id = api.start_analysis(
        analysis_id="power_envelope",
        function_id="rolling-window",
        target_model="device_data",
        target_model_pk=device_data["pk"],
        kwargs={
            "xname": "wavelength",
            "yname": "output_power",
            "xlabel": "Wavelength [nm]",
            "ylabel": "Power [mW]",
            "x0": 1550,
        },
    )
    task_ids.append(task_id)
result = api.wait_for_result(task_ids[-1])
result.summary_plot()
On This Page