Skip to content

Commit

Permalink
[ci] Quality of life updates (#888)
Browse files Browse the repository at this point in the history
## Summary of Changes

- Makes the `Can Produce` field in the model coverage reports clearer by
specifying which target is being generated.
- Adds color to "✓" and "✗" characters to make it clearer at a glance if
a particular file could be ingested
- Updated the default values of Environment Variables in skema.rest to
remove dependency on Lum.AI deployment
- Adds mathjax server to ci to support tests that previously relied on
lum deployment
### Related issues
Resolves #882
Resolves #883
Resolves #885

---------

Co-authored-by: Gus Hahn-Powell <ghp@lum.ai> a6df9ef
  • Loading branch information
github-actions[bot] committed Apr 30, 2024
1 parent c81d138 commit 783a197
Show file tree
Hide file tree
Showing 10,752 changed files with 163,783 additions and 127,791 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
19 changes: 9 additions & 10 deletions api/python/skema/img2mml/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h1 class="title">Module <code>skema.img2mml.api</code></h1>
from PIL import Image
from io import BytesIO

from huggingface_hub import hf_hub_download

def retrieve_model(model_path=None) -&gt; str:
&#34;&#34;&#34;
Expand All @@ -54,7 +55,7 @@ <h1 class="title">Module <code>skema.img2mml.api</code></h1>
str: Path to the loaded model file.
&#34;&#34;&#34;
cwd = Path(__file__).parents[0]
MODEL_BASE_ADDRESS = &#34;https://artifacts.askem.lum.ai/skema/img2mml/models&#34;
REPO_NAME = &#34;lum-ai/img2mml&#34;
MODEL_NAME = &#34;cnn_xfmer_arxiv_im2mml_with_fonts_boldface_best.pt&#34;
# If the model path is none or doesn&#39;t exist, the default model will be downloaded from server.
if model_path is None or not os.path.exists(model_path):
Expand All @@ -63,10 +64,9 @@ <h1 class="title">Module <code>skema.img2mml.api</code></h1>
# Check if the model file already exists
if not os.path.exists(model_path):
# If the file doesn&#39;t exist, download it from the specified URL
url = f&#34;{MODEL_BASE_ADDRESS}/{MODEL_NAME}&#34;
print(f&#34;Downloading the model checkpoint from {url}...&#34;)
urllib.request.urlretrieve(url, model_path)

print(f&#34;Downloading the model checkpoint from HuggingFace...&#34;)
hf_hub_download(repo_id=REPO_NAME, filename=MODEL_NAME, local_dir=model_path.parent, local_dir_use_symlinks=False)

return str(model_path)


Expand Down Expand Up @@ -695,7 +695,7 @@ <h2 id="returns">Returns</h2>
str: Path to the loaded model file.
&#34;&#34;&#34;
cwd = Path(__file__).parents[0]
MODEL_BASE_ADDRESS = &#34;https://artifacts.askem.lum.ai/skema/img2mml/models&#34;
REPO_NAME = &#34;lum-ai/img2mml&#34;
MODEL_NAME = &#34;cnn_xfmer_arxiv_im2mml_with_fonts_boldface_best.pt&#34;
# If the model path is none or doesn&#39;t exist, the default model will be downloaded from server.
if model_path is None or not os.path.exists(model_path):
Expand All @@ -704,10 +704,9 @@ <h2 id="returns">Returns</h2>
# Check if the model file already exists
if not os.path.exists(model_path):
# If the file doesn&#39;t exist, download it from the specified URL
url = f&#34;{MODEL_BASE_ADDRESS}/{MODEL_NAME}&#34;
print(f&#34;Downloading the model checkpoint from {url}...&#34;)
urllib.request.urlretrieve(url, model_path)

print(f&#34;Downloading the model checkpoint from HuggingFace...&#34;)
hf_hub_download(repo_id=REPO_NAME, filename=MODEL_NAME, local_dir=model_path.parent, local_dir_use_symlinks=False)

return str(model_path)</code></pre>
</details>
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ <h3>Instance variables</h3>
<h3>Methods</h3>
<dl>
<dt id="skema.img2mml.models.decoders.xfmer_decoder.Transformer_Decoder.create_pad_mask"><code class="name flex">
<span>def <span class="ident">create_pad_mask</span></span>(<span>self, matrix: <built-in method tensor of type object at 0x7efcca35b500>, pad_token: int) ‑> <built-in method tensor of type object at 0x7efcca35b500></span>
<span>def <span class="ident">create_pad_mask</span></span>(<span>self, matrix: <built-in method tensor of type object at 0x7f2a5d15b500>, pad_token: int) ‑> <built-in method tensor of type object at 0x7f2a5d15b500></span>
</code></dt>
<dd>
<div class="desc"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h3>Class variables</h3>
<h3>Methods</h3>
<dl>
<dt id="skema.img2mml.models.encoding.positional_encoding_for_xfmer.PositionalEncoding.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x: <built-in method tensor of type object at 0x7efcca35b500>) ‑> <built-in method tensor of type object at 0x7efcca35b500></span>
<span>def <span class="ident">forward</span></span>(<span>self, x: <built-in method tensor of type object at 0x7f2a5d15b500>) ‑> <built-in method tensor of type object at 0x7f2a5d15b500></span>
</code></dt>
<dd>
<div class="desc"><p>Defines the computation performed at every call.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ <h1 class="title">Module <code>skema.program_analysis.model_coverage_report.html
def add_table_data_field(self, table_row_tag, field_data: str, anchored=False, anchor_text=None):
&#34;&#34;&#34;Adds a new field to a table row&#34;&#34;&#34;
field_tag = self.soup.new_tag(&#34;td&#34;)
if field_data == &#34;✓&#34;:
field_tag[&#34;class&#34;] = &#34;green&#34;
elif field_data == &#34;✗&#34;:
field_tag[&#34;class&#34;] = &#34;red&#34;

if anchored:
anchor_tag = self.soup.new_tag(&#34;a&#34;)
Expand Down Expand Up @@ -82,7 +86,7 @@ <h1 class="title">Module <code>skema.program_analysis.model_coverage_report.html
new_model_table_header_basic = self.soup.new_tag(&#34;tr&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;File Name&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Num Lines&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Ingest&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Produce Gromet&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Tree-Sitter Parse Tree&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;CAST&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Gromet&#34;)
Expand Down Expand Up @@ -118,7 +122,7 @@ <h1 class="title">Module <code>skema.program_analysis.model_coverage_report.html

new_model_table_header_basic = self.soup.new_tag(&#34;tr&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;File Name&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Ingest&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Produce AMR&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;AMR&#34;)

# Append the elements to each other
Expand Down Expand Up @@ -261,6 +265,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
def add_table_data_field(self, table_row_tag, field_data: str, anchored=False, anchor_text=None):
&#34;&#34;&#34;Adds a new field to a table row&#34;&#34;&#34;
field_tag = self.soup.new_tag(&#34;td&#34;)
if field_data == &#34;✓&#34;:
field_tag[&#34;class&#34;] = &#34;green&#34;
elif field_data == &#34;✗&#34;:
field_tag[&#34;class&#34;] = &#34;red&#34;

if anchored:
anchor_tag = self.soup.new_tag(&#34;a&#34;)
Expand Down Expand Up @@ -293,7 +301,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
new_model_table_header_basic = self.soup.new_tag(&#34;tr&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;File Name&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Num Lines&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Ingest&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Produce Gromet&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Tree-Sitter Parse Tree&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;CAST&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Gromet&#34;)
Expand Down Expand Up @@ -329,7 +337,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>

new_model_table_header_basic = self.soup.new_tag(&#34;tr&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;File Name&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Ingest&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Produce AMR&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;AMR&#34;)

# Append the elements to each other
Expand Down Expand Up @@ -557,7 +565,7 @@ <h3>Methods</h3>
new_model_table_header_basic = self.soup.new_tag(&#34;tr&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;File Name&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Num Lines&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Ingest&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Produce Gromet&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Tree-Sitter Parse Tree&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;CAST&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Gromet&#34;)
Expand Down Expand Up @@ -593,7 +601,7 @@ <h3>Methods</h3>

new_model_table_header_basic = self.soup.new_tag(&#34;tr&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;File Name&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Ingest&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;Can Produce AMR&#34;)
self.add_table_header_field(new_model_table_header_basic, &#34;AMR&#34;)

# Append the elements to each other
Expand Down Expand Up @@ -665,6 +673,10 @@ <h3>Methods</h3>
<pre><code class="python">def add_table_data_field(self, table_row_tag, field_data: str, anchored=False, anchor_text=None):
&#34;&#34;&#34;Adds a new field to a table row&#34;&#34;&#34;
field_tag = self.soup.new_tag(&#34;td&#34;)
if field_data == &#34;✓&#34;:
field_tag[&#34;class&#34;] = &#34;green&#34;
elif field_data == &#34;✗&#34;:
field_tag[&#34;class&#34;] = &#34;red&#34;

if anchored:
anchor_tag = self.soup.new_tag(&#34;a&#34;)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ <h1 class="title">Module <code>skema.program_analysis.model_coverage_report.mode
from skema.rest.utils import fn_preprocessor
from skema.rest.workflows import code_snippets_to_pn_amr
from skema.utils.fold import del_nulls, dictionary_to_gromet_json
from skema.data.program_analysis import MODEL_ZIP_ROOT_PATH
from skema.utils.change_dir_back import change_dir_back
from skema.skema_py.server import System


# Constants for file paths
THIS_PATH = Path(__file__).parent.resolve()
MODEL_YAML_PATH = THIS_PATH / &#34;models.yaml&#34;
Expand Down Expand Up @@ -178,11 +180,12 @@ <h1 class="title">Module <code>skema.program_analysis.model_coverage_report.mode
&#34;&#34;&#34;Generate an HTML report for a single model&#34;&#34;&#34;
html.add_model(model_name)

if model_name in MODEL_YAML:
model_url = MODEL_YAML[model_name][&#34;zip_archive&#34;]
response = requests.get(model_url)

zip = ZipFile(BytesIO(response.content))
if not model_name in MODEL_YAML:
return

model_path = MODEL_ZIP_ROOT_PATH.resolve() / MODEL_YAML[model_name][&#34;zip_archive&#34;]

zip = ZipFile(BytesIO(model_path.read_bytes()))
with TemporaryDirectory() as temp:
# We need to write all the files to the temporary directory before processing
# This is because some steps may require additional files, such as include directories in Fortran
Expand Down Expand Up @@ -326,7 +329,8 @@ <h1 class="title">Module <code>skema.program_analysis.model_coverage_report.mode
try:
supported, total = process_single_model(html, output_dir, model_name)
model_line_coverage[model_name] = (supported, total)
except:
except Exception as e:
print(e)
continue
return model_line_coverage

Expand Down Expand Up @@ -576,7 +580,8 @@ <h2 class="section-title" id="header-functions">Functions</h2>
try:
supported, total = process_single_model(html, output_dir, model_name)
model_line_coverage[model_name] = (supported, total)
except:
except Exception as e:
print(e)
continue
return model_line_coverage</code></pre>
</details>
Expand All @@ -594,11 +599,12 @@ <h2 class="section-title" id="header-functions">Functions</h2>
&#34;&#34;&#34;Generate an HTML report for a single model&#34;&#34;&#34;
html.add_model(model_name)

if model_name in MODEL_YAML:
model_url = MODEL_YAML[model_name][&#34;zip_archive&#34;]
response = requests.get(model_url)

zip = ZipFile(BytesIO(response.content))
if not model_name in MODEL_YAML:
return

model_path = MODEL_ZIP_ROOT_PATH.resolve() / MODEL_YAML[model_name][&#34;zip_archive&#34;]

zip = ZipFile(BytesIO(model_path.read_bytes()))
with TemporaryDirectory() as temp:
# We need to write all the files to the temporary directory before processing
# This is because some steps may require additional files, such as include directories in Fortran
Expand Down
9 changes: 4 additions & 5 deletions api/python/skema/program_analysis/tests/test_code2fn.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ <h1 class="title">Module <code>skema.program_analysis.tests.test_code2fn</code><

from skema.program_analysis.multi_file_ingester import process_file_system
from skema.gromet.fn import GrometFNModuleCollection
from skema.data.program_analysis import MODEL_ZIP_ROOT_PATH

BUCKY_ZIP_URL = &#34;https://artifacts.askem.lum.ai/askem/data/models/zip-archives/Bucky.zip&#34;
BUCKY_ZIP_URL = MODEL_ZIP_ROOT_PATH.resolve() / &#34;Bucky.zip&#34;

def test_code2fn():
&#34;&#34;&#34;This is simply a smokescreen test to see if the PA pipeline runs to
Expand All @@ -48,8 +49,7 @@ <h1 class="title">Module <code>skema.program_analysis.tests.test_code2fn</code><
flag or postprocessing function to be able to compare two GroMEts modulo
their random components.&#34;&#34;&#34;

response = requests.get(BUCKY_ZIP_URL)
zip = zipfile.ZipFile(io.BytesIO(response.content))
zip = zipfile.ZipFile(io.BytesIO(BUCKY_ZIP_URL.read_bytes()))

with TemporaryDirectory() as temp:
system_filepaths_path = Path(temp) / &#34;system_filepaths.txt&#34;
Expand Down Expand Up @@ -100,8 +100,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
flag or postprocessing function to be able to compare two GroMEts modulo
their random components.&#34;&#34;&#34;

response = requests.get(BUCKY_ZIP_URL)
zip = zipfile.ZipFile(io.BytesIO(response.content))
zip = zipfile.ZipFile(io.BytesIO(BUCKY_ZIP_URL.read_bytes()))

with TemporaryDirectory() as temp:
system_filepaths_path = Path(temp) / &#34;system_filepaths.txt&#34;
Expand Down
Loading

0 comments on commit 783a197

Please sign in to comment.