Commit 760b022a authored by Chris Jewell's avatar Chris Jewell
Browse files

Fixed doc and refactored ModelGenerator -> CodeGenerator to more accurately...

Fixed doc and refactored ModelGenerator -> CodeGenerator to more accurately reflect what the class is doing.
parent 6837b1b2
Pipeline #240 passed with stage
in 4 minutes and 57 seconds
......@@ -80,9 +80,9 @@ To illustrate our description of semantic analysis, it is useful to consider a G
Semantic analysis currently consists of 3 stages which are executed sequentially:
1. Symbol Declaration (:class:`ParseDeclarations <gem.gemlang.symbol_resolve.ParseDeclarations>`)
1. Symbol Declaration (:class:`ParseDeclarations <gem.gemlang.symbol\_resolve.ParseDeclarations>`)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In this stage, a symbol table is built containing builtin GEM symbols as well as symbols declared in the GEM program.
:class:`ParseDeclarations <gem.gemlang.symbol_resolve>` In this stage, a symbol table is built containing builtin GEM symbols as well as symbols declared in the GEM program.
Since gemlang is implicitly typed, symbols representing variables are declared when they are first assigned.
In the :ref:`example <gemprog>` code, symbols `mu`, `beta`, `S`, `I`, and `epi` are pushed into the symbol table on
their first assignment (lines 1, 2, 4, 5, 8 respectively).
......
......@@ -11,14 +11,6 @@ Subpackages
Submodules
----------
gem.gemlang.ast\_semantics module
---------------------------------
.. automodule:: gem.gemlang.ast_semantics
:members:
:undoc-members:
:show-inheritance:
gem.gemlang.ast\_walker module
------------------------------
......@@ -27,18 +19,18 @@ gem.gemlang.ast\_walker module
:undoc-members:
:show-inheritance:
gem.gemlang.parse\_gemlang module
---------------------------------
gem.gemlang.model\_generator module
----------------------------------
.. automodule:: gem.gemlang.parse_gemlang
.. automodule:: gem.gemlang.model_generator
:members:
:undoc-members:
:show-inheritance:
gem.gemlang.parsetree2ast module
--------------------------------
gem.gemlang.parse\_gemlang module
---------------------------------
.. automodule:: gem.gemlang.parsetree2ast
.. automodule:: gem.gemlang.parse_gemlang
:members:
:undoc-members:
:show-inheritance:
......@@ -51,14 +43,6 @@ gem.gemlang.symbol module
:undoc-members:
:show-inheritance:
gem.gemlang.tf\_model\_writer module
------------------------------------
.. automodule:: gem.gemlang.tf_model_writer
:members:
:undoc-members:
:show-inheritance:
gem.gemlang.tf\_output module
-----------------------------
......
......@@ -31,11 +31,11 @@ def error_pos(msg, meta):
return "{} at line {} column {}".format(msg, meta.line, meta.column)
class ModelGenerator(ASTWalker):
class CodeGenerator(ASTWalker):
"""Walks an AST, rewriting it as Outputter objects.
:param random_vars an object with field `free` and `observed` with lists of random vars.
:return an Outputter object
:param symtab: a fully populated symbol table
:returns: an ModelGenerator object
"""
# pylint: disable=invalid-name,missing-docstring
......
......@@ -27,7 +27,7 @@ import tensorflow_probability as tfp
from tensorflow_probability import edward2 as ed
from gem.gemlang import gemparse
from gem.gemlang.model_generator import ModelGenerator
from gem.gemlang.model_generator import CodeGenerator
from gem.gemlang.symbol_resolve import ParseDeclarations, ResolveSymbols, \
InjectData, get_random_vars
from gem.model.edward2_extn import make_value_setter, TransformedRVBijector
......@@ -94,7 +94,7 @@ class GEM:
ast, self.__symtab = ParseDeclarations().walk(ast)
ast, self.__symtab = ResolveSymbols(self.__symtab).walk(ast)
ast = InjectData(self.gem_external).walk(ast)
self.__pyprog = ModelGenerator(self.__symtab).walk(ast)
self.__pyprog = CodeGenerator(self.__symtab).walk(ast)
except Exception as e:
print(f"An error occurred during model compilation: {e}")
raise e
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment