Repository: AgnostiqHQ/covalent
Pull request #1610 (2023-04-29 23:46:45)

open UI page and print URL with draw()
Closes https://github.com/AgnostiqHQ/covalent/issues/836

- [x] I have added the tests to cover my changes.
- [x] I have updated the documentation and CHANGELOG accordingly.
- [x] I have read the CONTRIBUTING document.


madhur-tandon: CC: @kessler-frost @santoshkumarradha @AlejandroEsquivel 
codecov[bot]: ## [Codecov](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1610?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) Report
> Merging [#1610](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1610?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (448b78c) into [develop](https://codecov.io/gh/AgnostiqHQ/covalent/commit/5172f98c8b967f15364a2f6c35d47294eff4ba7b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (5172f98) will **increase** coverage by `1.35%`.
> The diff coverage is `100.00%`.

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1610/graphs/tree.svg?width=650&height=150&src=pr&token=YGHCB3DE4P&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1610?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)

```diff
@@             Coverage Diff             @@
##           develop    #1610      +/-   ##
===========================================
+ Coverage    85.94%   87.29%   +1.35%     
===========================================
  Files          159       83      -76     
  Lines         6658     4975    -1683     
  Branches       145        0     -145     
===========================================
- Hits          5722     4343    -1379     
+ Misses         834      632     -202     
+ Partials       102        0     -102     
```

| Flag | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| Dispatcher | `87.28% <ø> (ø)` | | Carriedforward from [5172f98](https://codecov.io/gh/AgnostiqHQ/covalent/commit/5172f98c8b967f15364a2f6c35d47294eff4ba7b?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) |
| Functional_Tests | `?` | | |
| SDK | `87.30% <100.00%> (-0.01%)` | :arrow_down: | |
| UI_Frontend | `?` | | |

*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) to find out more.

</details>

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5629ac56..8e551db4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Raise error on dispatching a non-lattice
 - Helpful message when trying to dispatch a workflow when covalent server is not available
+- Open UI preview of transport graph when `lattice.draw()` is invoked and print URL of the same
 
 ### Authors
 
diff --git a/covalent/_workflow/lattice.py b/covalent/_workflow/lattice.py
index e75dd8e1..0da77e57 100644
--- a/covalent/_workflow/lattice.py
+++ b/covalent/_workflow/lattice.py
@@ -23,6 +23,7 @@
 import json
 import os
 import warnings
+import webbrowser
 from builtins import list
 from contextlib import redirect_stdout
 from copy import deepcopy
@@ -267,9 +268,15 @@ class Lattice:
         """
 
         import covalent_ui.result_webhook as result_webhook
+        from covalent_ui.result_webhook import get_ui_url
 
         self.build_graph(*args, **kwargs)
         result_webhook.send_draw_request(self)
+        draw_preview_url = get_ui_url("/preview")
+        message = f"To preview the transport graph of the lattice, visit {draw_preview_url}"
+        app_log.info(message)
+        print(message)
+        webbrowser.open(draw_preview_url)
 
     def __call__(self, *args, **kwargs):
         """Execute lattice as an ordinary function for testing purposes."""
diff --git a/covalent_ui/result_webhook.py b/covalent_ui/result_webhook.py
index c3a392dd..94e9aabb 100644
--- a/covalent_ui/result_webhook.py
+++ b/covalent_ui/result_webhook.py
@@ -29,7 +29,8 @@ from covalent._shared_files import logger
 from covalent._shared_files.config import get_config
 from covalent_dispatcher._db.dispatchdb import encode_dict, extract_graph, extract_metadata
 
-DEFAULT_PORT = get_config("user_interface.port")
+DEFAULT_UI_ADDRESS = get_config("user_interface.address")
+DEFAULT_UI_PORT = get_config("user_interface.port")
 
 app_log = logger.app_log
 
@@ -37,7 +38,7 @@ app_log = logger.app_log
 
 
 def get_ui_url(path):
-    baseUrl = f"http://localhost:{DEFAULT_PORT}"
+    baseUrl = f"http://{DEFAULT_UI_ADDRESS}:{DEFAULT_UI_PORT}"
     return f"{baseUrl}{path}"
 
 


Test patch:
diff --git a/tests/covalent_tests/workflow/lattice_test.py b/tests/covalent_tests/workflow/lattice_test.py
index b4eb3377..56a1bf2d 100644
--- a/tests/covalent_tests/workflow/lattice_test.py
+++ b/tests/covalent_tests/workflow/lattice_test.py
@@ -26,12 +26,15 @@ import pytest
 
 import covalent as ct
 from covalent._shared_files.defaults import DefaultMetadataValues, postprocess_prefix
+from covalent_ui.result_webhook import get_ui_url
 
 DEFAULT_METADATA_VALUES = asdict(DefaultMetadataValues())
 
 
-def test_lattice_draw(mocker):
+def test_lattice_draw(mocker, capsys):
+    draw_preview_url = get_ui_url("/preview")
     mock_send_draw_req = mocker.patch("covalent_ui.result_webhook.send_draw_request")
+    mock_webbrowser_open = mocker.patch("webbrowser.open")
 
     @ct.electron
     def task(x):
@@ -43,7 +46,14 @@ def test_lattice_draw(mocker):
 
     workflow.draw(2)
 
+    captured = capsys.readouterr()
+    assert (
+        captured.out
+        == f"To preview the transport graph of the lattice, visit {draw_preview_url}\n"
+    )
+
     mock_send_draw_req.assert_called_once()
+    mock_webbrowser_open.assert_called_once()
 
 
 def test_lattice_workflow_executor_settings():