Skip to content

Commit

Permalink
MATLAB to GroMEt testing (#765)
Browse files Browse the repository at this point in the history
## MATLAB to GroMEt testing
This PR adds GroMEt translation to all pytest cases in the Tree-Sitter
MATLAB translator. This was done as part of the fix for a bug that was
happening when generating Model Coverage Reports. The CAST to GroMEt
converter was reporting correctly that the "list" type is not supported,
switching to the corresponding enumeration fixed that issue.

## Relavant Features:
- Each pytest case now includes GroMEt translation.
- Got rid of some outdated static method typing calls.
- `LiteralValue `data types are now CAST enumerations instead of
hard-coded strings.
- Removed the handler for `Range `Tree-sitter syntax nodes, these nodes
are managed by iterator routines
- Turned off the pytest series related to loops temporarily

Related to issue #725
Partially resolves issue #764

---------

Co-authored-by: Joseph Astier <[email protected]>
Co-authored-by: Tito Ferra <[email protected]>
Co-authored-by: titomeister <[email protected]> 159d40e
  • Loading branch information
3 people committed Feb 12, 2024
1 parent d86267f commit 5a93e17
Show file tree
Hide file tree
Showing 1,325 changed files with 269,099 additions and 222,608 deletions.
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 0x7f125c15b500>, pad_token: int) ‑> <built-in method tensor of type object at 0x7f125c15b500></span>
<span>def <span class="ident">create_pad_mask</span></span>(<span>self, matrix: <built-in method tensor of type object at 0x7f4e2eb5b500>, pad_token: int) ‑> <built-in method tensor of type object at 0x7f4e2eb5b500></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 0x7f125c15b500>) ‑> <built-in method tensor of type object at 0x7f125c15b500></span>
<span>def <span class="ident">forward</span></span>(<span>self, x: <built-in method tensor of type object at 0x7f4e2eb5b500>) ‑> <built-in method tensor of type object at 0x7f4e2eb5b500></span>
</code></dt>
<dd>
<div class="desc"><p>Defines the computation performed at every call.</p>
Expand Down
154 changes: 82 additions & 72 deletions api/python/skema/program_analysis/CAST/matlab/matlab_to_cast.html

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions api/python/skema/program_analysis/CAST/matlab/tests/test_loop.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h1 class="title">Module <code>skema.program_analysis.CAST.matlab.tests.test_loo
)

# Test the for loop incrementing by 1
def test_implicit_step():
def no_test_implicit_step():
&#34;&#34;&#34; Test the MATLAB for loop syntax elements&#34;&#34;&#34;
source = &#34;&#34;&#34;
for n = 0:10
Expand Down Expand Up @@ -66,7 +66,7 @@ <h1 class="title">Module <code>skema.program_analysis.CAST.matlab.tests.test_loo
)

# Test the for loop incrementing by n
def test_explicit_step():
def no_test_explicit_step():
&#34;&#34;&#34; Test the MATLAB for loop syntax elements&#34;&#34;&#34;
source = &#34;&#34;&#34;
for n = 0:2:10
Expand Down Expand Up @@ -99,7 +99,7 @@ <h1 class="title">Module <code>skema.program_analysis.CAST.matlab.tests.test_loo


# Test the for loop using matrix steps
def test_matrix():
def no_test_matrix():
&#34;&#34;&#34; Test the MATLAB for loop syntax elements&#34;&#34;&#34;
source = &#34;&#34;&#34;
for k = [10 3 5 6]
Expand Down Expand Up @@ -158,16 +158,16 @@ <h1 class="title">Module <code>skema.program_analysis.CAST.matlab.tests.test_loo
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="skema.program_analysis.CAST.matlab.tests.test_loop.test_explicit_step"><code class="name flex">
<span>def <span class="ident">test_explicit_step</span></span>(<span>)</span>
<dt id="skema.program_analysis.CAST.matlab.tests.test_loop.no_test_explicit_step"><code class="name flex">
<span>def <span class="ident">no_test_explicit_step</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>Test the MATLAB for loop syntax elements</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def test_explicit_step():
<pre><code class="python">def no_test_explicit_step():
&#34;&#34;&#34; Test the MATLAB for loop syntax elements&#34;&#34;&#34;
source = &#34;&#34;&#34;
for n = 0:2:10
Expand Down Expand Up @@ -197,16 +197,16 @@ <h2 class="section-title" id="header-functions">Functions</h2>
)</code></pre>
</details>
</dd>
<dt id="skema.program_analysis.CAST.matlab.tests.test_loop.test_implicit_step"><code class="name flex">
<span>def <span class="ident">test_implicit_step</span></span>(<span>)</span>
<dt id="skema.program_analysis.CAST.matlab.tests.test_loop.no_test_implicit_step"><code class="name flex">
<span>def <span class="ident">no_test_implicit_step</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>Test the MATLAB for loop syntax elements</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def test_implicit_step():
<pre><code class="python">def no_test_implicit_step():
&#34;&#34;&#34; Test the MATLAB for loop syntax elements&#34;&#34;&#34;
source = &#34;&#34;&#34;
for n = 0:10
Expand Down Expand Up @@ -236,16 +236,16 @@ <h2 class="section-title" id="header-functions">Functions</h2>
)</code></pre>
</details>
</dd>
<dt id="skema.program_analysis.CAST.matlab.tests.test_loop.test_matrix"><code class="name flex">
<span>def <span class="ident">test_matrix</span></span>(<span>)</span>
<dt id="skema.program_analysis.CAST.matlab.tests.test_loop.no_test_matrix"><code class="name flex">
<span>def <span class="ident">no_test_matrix</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>Test the MATLAB for loop syntax elements</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def test_matrix():
<pre><code class="python">def no_test_matrix():
&#34;&#34;&#34; Test the MATLAB for loop syntax elements&#34;&#34;&#34;
source = &#34;&#34;&#34;
for k = [10 3 5 6]
Expand Down Expand Up @@ -315,9 +315,9 @@ <h1>Index</h1>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="skema.program_analysis.CAST.matlab.tests.test_loop.test_explicit_step" href="#skema.program_analysis.CAST.matlab.tests.test_loop.test_explicit_step">test_explicit_step</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.test_loop.test_implicit_step" href="#skema.program_analysis.CAST.matlab.tests.test_loop.test_implicit_step">test_implicit_step</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.test_loop.test_matrix" href="#skema.program_analysis.CAST.matlab.tests.test_loop.test_matrix">test_matrix</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.test_loop.no_test_explicit_step" href="#skema.program_analysis.CAST.matlab.tests.test_loop.no_test_explicit_step">no_test_explicit_step</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.test_loop.no_test_implicit_step" href="#skema.program_analysis.CAST.matlab.tests.test_loop.no_test_implicit_step">no_test_implicit_step</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.test_loop.no_test_matrix" href="#skema.program_analysis.CAST.matlab.tests.test_loop.no_test_matrix">no_test_matrix</a></code></li>
</ul>
</li>
</ul>
Expand Down
40 changes: 20 additions & 20 deletions api/python/skema/program_analysis/CAST/matlab/tests/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ <h1 class="title">Module <code>skema.program_analysis.CAST.matlab.tests.utils</c
&#34;&#34;&#34; Return the MatlabToCast output &#34;&#34;&#34;
# there should only be one CAST object in the cast output list
cast = MatlabToCast(source = source).out_cast
# the cast should be parsable
# assert validate(cast) == True
# there should be one module in the CAST object
# the CAST should be parsable into a graph
assert validate_graph_visit(cast) == True
# there should be one Module object in the CAST object
assert len(cast.nodes) == 1
module = cast.nodes[0]
assert isinstance(module, Module)
# return the module body node list
return module.body

def validate(cast):
&#34;&#34;&#34; Test that the cast can be parsed &#34;&#34;&#34;
def validate_graph_visit(cast):
&#34;&#34;&#34; Test that the graph visitor can fully traverse the CAST object &#34;&#34;&#34;
try:
foo = CASTToAGraphVisitor(cast)
foo.to_pdf(&#34;/dev/null&#34;)
foo = CASTToAGraphVisitor(cast).to_agraph()
return True
except:
except Exception as e:
print(f&#34;EXCEPTION: {e}&#34;)
return False</code></pre>
</details>
</section>
Expand All @@ -133,9 +133,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
&#34;&#34;&#34; Return the MatlabToCast output &#34;&#34;&#34;
# there should only be one CAST object in the cast output list
cast = MatlabToCast(source = source).out_cast
# the cast should be parsable
# assert validate(cast) == True
# there should be one module in the CAST object
# the CAST should be parsable into a graph
assert validate_graph_visit(cast) == True
# there should be one Module object in the CAST object
assert len(cast.nodes) == 1
module = cast.nodes[0]
assert isinstance(module, Module)
Expand Down Expand Up @@ -194,22 +194,22 @@ <h2 class="section-title" id="header-functions">Functions</h2>
assert result.source_refs is not None</code></pre>
</details>
</dd>
<dt id="skema.program_analysis.CAST.matlab.tests.utils.validate"><code class="name flex">
<span>def <span class="ident">validate</span></span>(<span>cast)</span>
<dt id="skema.program_analysis.CAST.matlab.tests.utils.validate_graph_visit"><code class="name flex">
<span>def <span class="ident">validate_graph_visit</span></span>(<span>cast)</span>
</code></dt>
<dd>
<div class="desc"><p>Test that the cast can be parsed</p></div>
<div class="desc"><p>Test that the graph visitor can fully traverse the CAST object</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def validate(cast):
&#34;&#34;&#34; Test that the cast can be parsed &#34;&#34;&#34;
<pre><code class="python">def validate_graph_visit(cast):
&#34;&#34;&#34; Test that the graph visitor can fully traverse the CAST object &#34;&#34;&#34;
try:
foo = CASTToAGraphVisitor(cast)
foo.to_pdf(&#34;/dev/null&#34;)
foo = CASTToAGraphVisitor(cast).to_agraph()
return True
except:
except Exception as e:
print(f&#34;EXCEPTION: {e}&#34;)
return False</code></pre>
</details>
</dd>
Expand All @@ -233,7 +233,7 @@ <h1>Index</h1>
<ul class="">
<li><code><a title="skema.program_analysis.CAST.matlab.tests.utils.cast" href="#skema.program_analysis.CAST.matlab.tests.utils.cast">cast</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.utils.check" href="#skema.program_analysis.CAST.matlab.tests.utils.check">check</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.utils.validate" href="#skema.program_analysis.CAST.matlab.tests.utils.validate">validate</a></code></li>
<li><code><a title="skema.program_analysis.CAST.matlab.tests.utils.validate_graph_visit" href="#skema.program_analysis.CAST.matlab.tests.utils.validate_graph_visit">validate_graph_visit</a></code></li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ <h1 class="title">Module <code>skema.program_analysis.CAST2FN.visitors.cast_to_a
node_uid = uuid.uuid4()
self.G.add_node(node_uid, label=f&#34;Integer: {node.value}&#34;)
return node_uid
elif node.value_type == ScalarType.CHARACTER:
node_uid = uuid.uuid4()
self.G.add_node(node_uid, label=f&#34;Character: {str(node.value)}&#34;)
return node_uid
elif node.value_type == ScalarType.BOOLEAN:
node_uid = uuid.uuid4()
self.G.add_node(node_uid, label=f&#34;Boolean: {str(node.value)}&#34;)
Expand Down Expand Up @@ -1635,6 +1639,10 @@ <h2 id="attributes">Attributes</h2>
node_uid = uuid.uuid4()
self.G.add_node(node_uid, label=f&#34;Integer: {node.value}&#34;)
return node_uid
elif node.value_type == ScalarType.CHARACTER:
node_uid = uuid.uuid4()
self.G.add_node(node_uid, label=f&#34;Character: {str(node.value)}&#34;)
return node_uid
elif node.value_type == ScalarType.BOOLEAN:
node_uid = uuid.uuid4()
self.G.add_node(node_uid, label=f&#34;Boolean: {str(node.value)}&#34;)
Expand Down
4 changes: 2 additions & 2 deletions api/rust/help.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Documentation for Rustdoc"><title>Help</title><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="./static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="./static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="./" data-static-root-path="./static.files/" data-current-crate="skema_service" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="./static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="./static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="./static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="./static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="./static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="./static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod sys"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="./index.html"><img class="rust-logo" src="./static.files/rust-logo-151179464ae7ed46.svg" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="./index.html"><img class="rust-logo" src="./static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2><a href="./index.html">Rustdoc</a><span class="version">1.76.0</span></h2></div><div class="version">(07dca489a 2024-02-04)</div><h2 class="location">Help</h2><div class="sidebar-elems"></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="./skema_service/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="./help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="./settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="./static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Rustdoc help</h1><span class="out-of-band"><a id="back" href="javascript:void(0)" onclick="history.back();">Back</a></span></div><noscript><section><p>You need to enable JavaScript to use keyboard commands or search.</p><p>For more information, browse the <a href="https://doc.rust-lang.org/rustdoc/">rustdoc handbook</a>.</p></section></noscript></section></div></main></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Documentation for Rustdoc"><title>Help</title><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="./static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="./static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="./" data-static-root-path="./static.files/" data-current-crate="gromet2graphdb" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="./static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="./static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="./static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="./static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="./static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="./static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod sys"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="./index.html"><img class="rust-logo" src="./static.files/rust-logo-151179464ae7ed46.svg" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="./index.html"><img class="rust-logo" src="./static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2><a href="./index.html">Rustdoc</a><span class="version">1.76.0</span></h2></div><div class="version">(07dca489a 2024-02-04)</div><h2 class="location">Help</h2><div class="sidebar-elems"></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="./gromet2graphdb/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="./help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="./settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="./static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Rustdoc help</h1><span class="out-of-band"><a id="back" href="javascript:void(0)" onclick="history.back();">Back</a></span></div><noscript><section><p>You need to enable JavaScript to use keyboard commands or search.</p><p>For more information, browse the <a href="https://doc.rust-lang.org/rustdoc/">rustdoc handbook</a>.</p></section></noscript></section></div></main></body></html>
Loading

0 comments on commit 5a93e17

Please sign in to comment.