From 1d524264d68a4633a709235d4a58090db7edee86 Mon Sep 17 00:00:00 2001
From: Yangge Li <li213@illinois.edu>
Date: Thu, 23 Jun 2022 17:22:14 -0500
Subject: [PATCH] add empty controllerir

---
 dryvr_plus_plus/example/example_agent/car_agent.py   |  8 +++-----
 dryvr_plus_plus/example/example_agent/sign_agent.py  |  4 ++--
 dryvr_plus_plus/scene_verifier/code_parser/parser.py | 10 +++++++++-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/dryvr_plus_plus/example/example_agent/car_agent.py b/dryvr_plus_plus/example/example_agent/car_agent.py
index d27131c8..87cc2892 100644
--- a/dryvr_plus_plus/example/example_agent/car_agent.py
+++ b/dryvr_plus_plus/example/example_agent/car_agent.py
@@ -1,7 +1,8 @@
 # Example agent.
 from typing import Tuple, List
 
-import numpy as np 
+import numpy as np
+from pkg_resources import EmptyProvider 
 from scipy.integrate import ode
 
 from dryvr_plus_plus.scene_verifier.agents.base_agent import BaseAgent
@@ -11,10 +12,7 @@ from dryvr_plus_plus.scene_verifier.code_parser.parser import ControllerIR, Stat
 class NPCAgent(BaseAgent):
     def __init__(self, id):
         self.id = id
-        controller = Lambda(args = [('ego', 'State'),('others', 'State')], body = {})
-        state_defs = {'State':StateDef(cont=[], disc=[], static=[])}
-        mode_defs = {'NullMode':ModeDef(modes=['Null'])}
-        self.controller = ControllerIR(controller, state_defs, mode_defs)
+        self.controller:ControllerIR = ControllerIR.EmptyControllerIR()
 
     @staticmethod
     def dynamic(t, state, u):
diff --git a/dryvr_plus_plus/example/example_agent/sign_agent.py b/dryvr_plus_plus/example/example_agent/sign_agent.py
index 2b97fa27..71be3f61 100644
--- a/dryvr_plus_plus/example/example_agent/sign_agent.py
+++ b/dryvr_plus_plus/example/example_agent/sign_agent.py
@@ -1,11 +1,11 @@
 from dryvr_plus_plus.scene_verifier.agents.base_agent import BaseAgent
 import numpy as np
-from dryvr_plus_plus.scene_verifier.code_parser.pythonparser import EmptyAst
+from dryvr_plus_plus.scene_verifier.code_parser.parser import ControllerIR
 
 class SignAgent(BaseAgent):
     def __init__(self, id):
         self.id = id
-        self.controller = EmptyAst()
+        self.controller:ControllerIR = ControllerIR.EmptyControllerIR()
 
     def TC_simulate(self, mode, init, time_horizon, time_step, map=None):
         number_points = int(np.ceil(float(time_horizon)/time_step))
diff --git a/dryvr_plus_plus/scene_verifier/code_parser/parser.py b/dryvr_plus_plus/scene_verifier/code_parser/parser.py
index f919f916..cab195d9 100644
--- a/dryvr_plus_plus/scene_verifier/code_parser/parser.py
+++ b/dryvr_plus_plus/scene_verifier/code_parser/parser.py
@@ -84,7 +84,7 @@ class ReductionType(Enum):
         }[self]
 
 @dataclass(unsafe_hash=True)
-class Reduction(ast.AST):
+class Reduction(ast.expr):
     """A simple reduction. Must be a reduction function (see `ReductionType`) applied to a generator
     with a single clause over a iterable"""
     op: ReductionType
@@ -169,6 +169,14 @@ class ControllerIR:
     state_defs: Dict[str, StateDef]
     mode_defs: Dict[str, ModeDef]
 
+    @classmethod
+    def EmptyControllerIR(cls):
+        controller = Lambda(args = [('ego', 'State'),('others', 'State')], body = {})
+        state_defs = {'State':StateDef(cont=[], disc=[], static=[])}
+        mode_defs = {'NullMode':ModeDef(modes=['Null'])}
+        return cls(controller, state_defs, mode_defs)
+
+
     @staticmethod
     def parse(code: Optional[str] = None, fn: Optional[str] = None) -> "ControllerIR":
         return Env.parse(code, fn).to_ir()
-- 
GitLab