Skip to content

Commit

Permalink
Removing billed cost display; adding real_cost function for user
Browse files Browse the repository at this point in the history
  • Loading branch information
momchil-flex committed Mar 1, 2023
1 parent 0d3da03 commit 6a25bc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tidy3d/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys

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
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
Expand Down
27 changes: 22 additions & 5 deletions tidy3d/web/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ def monitor_preprocess() -> None:
if verbose:
est_flex_unit = get_estimated_cost()
if est_flex_unit is not None and est_flex_unit > 0:
log.info(f"Maximum FlexUnit cost: {est_flex_unit:1.3f}")
log.info(
f"Maximum FlexUnit cost: {est_flex_unit:1.3f}. Use 'web.real_cost(task_id)' to "
"get the billed FlexUnit cost after a simulation run."
)
log.info("starting up solver")

# while running but before the percentage done is available, keep waiting
Expand Down Expand Up @@ -350,10 +353,6 @@ def monitor_preprocess() -> None:
while get_status() not in break_statuses:
time.sleep(REFRESH_TIME)

# show final billed cost
if verbose:
log.info(f"Billed FlexUnit cost: {get_info(task_id).realFlexUnit:1.3f}")


def download(task_id: TaskId, path: str = "simulation_data.hdf5", verbose: bool = True) -> None:
"""Download results of task and log to file.
Expand Down Expand Up @@ -609,6 +608,24 @@ def estimate_cost(task_id: str) -> float:
return resp.get("flex_unit")


def real_cost(task_id: str) -> float:
"""Get the billed cost for given task after it has been run.
Note
----
The billed cost may not be immediately available when the task status is set to ``success``,
but should be available shortly after.
"""

flex_unit = get_info(task_id).realFlexUnit
if not flex_unit:
log.warning(
f"Billed FlexUnit for task '{task_id}'' is not available. If the task has been "
"successfully run, it should be available shortly."
)
return flex_unit


def _query_or_create_folder(folder_name) -> Folder:
log.debug("query folder")
method = f"tidy3d/project?projectName={folder_name}"
Expand Down

0 comments on commit 6a25bc1

Please sign in to comment.