Skip to content

Commit

Permalink
merging by resolving conflict on test_make_cache.py
Browse files Browse the repository at this point in the history
  • Loading branch information
marota committed Dec 21, 2021
2 parents 915be38 + 5d33d32 commit c30c2e7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 16 deletions.
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
# The python orb contains a set of prepackaged CircleCI configuration you can use repeatedly in your configuration files
# Orb commands and jobs help you with common scripting around a language/tool
# so you dont have to copy and paste it everywhere.
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python
python: circleci/[email protected]

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build-and-test: # This is the name of the job, feel free to change it to better match what you're trying to do!
# These next lines defines a Docker executors: https://circleci.com/docs/2.0/executor-types/
# You can specify an image from Dockerhub or use one of the convenience images from CircleCI's Developer Hub
# A list of available CircleCI Docker convenience images are available here: https://circleci.com/developer/images/image/cimg/python
# The executor is the environment in which the steps below will be executed - below will use a python 3.8 container
# Change the version below to your required version of python
docker:
- image: cimg/python:3.8
# Checkout the code as the first step. This is a dedicated CircleCI step.
# The python orb's install-packages step will install the dependencies from a Pipfile via Pipenv by default.
# Here we're making sure we use just use the system-wide pip. By default it uses the project root's requirements.txt.
# Then run your tests!
# CircleCI will report the results back to your VCS provider.
steps:
- checkout
- python/install-packages:
pkg-manager: pip
# app-dir: ~/project/package-directory/ # If you're requirements.txt isn't in the root directory.
# pip-dependency-file: test-requirements.txt # if you have a different name for your requirements file, maybe one that combines your runtime and test requirements.
- run:
name: Run tests
# This assumes pytest is installed via the install-package step above
command: pytest tests --ignore tests/test_simulation.py --ignore tests/test_simulation_expert_system.py -v

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
sample: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- build-and-test
31 changes: 28 additions & 3 deletions grid2viz/app_jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
It will generate the layout of a given page and handle the routing
"""

activate_simulation=False #turn it to True to activate Simulation tab. You will need Grid2op related environment in additions to the scenario logs

import dash_bootstrap_components as dbc
import warnings
import sys

# from dash import Dash
from jupyter_dash import JupyterDash
Expand All @@ -30,7 +34,6 @@
) # as overview_clbk
from grid2viz.src.macro.macro_clbk import register_callbacks_macro # as macro_clbk
from grid2viz.src.micro.micro_clbk import register_callbacks_micro # as micro_clbk

"""
End Warning
"""
Expand All @@ -41,17 +44,39 @@
app.server.secret_key = "Grid2Viz"

##create layout
layout(app)
layout(app,activate_simulation=activate_simulation)


##create callbaks
register_callbacks_main(app)
register_callbacks_episodes(app)
register_callbacks_overview(app)
register_callbacks_macro(app)
register_callbacks_micro(app)
if activate_simulation:
from grid2viz.src.simulation.simulation_clbk import register_callbacks_simulation

try:
from grid2viz.src.simulation.ExpertAssist import Assist
except (ImportError, ModuleNotFoundError):
from grid2viz.src.simulation.simulation_assist import EmptyAssist as Assist

warnings.warn(
"ExpertOp4Grid is not installed and the assist feature will not be available."
" To use the Assist feature, you can install ExpertOp4Grid by "
"\n\t{} -m pip install ExpertOp4Grid\n".format(sys.executable)
)

assistant = Assist()
register_callbacks_simulation(app, assistant)
assistant.register_callbacks(app)




def app_run(port=8050, debug=False):
def app_run(port=8050, debug=False, page=None):
if page is not None:
print(f"Warm start is running on http://127.0.0.1:{port}/{page}")
app.run_server(port=port, debug=debug)


Expand Down
5 changes: 4 additions & 1 deletion grid2viz/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def main():
app_run(args.port, args.debug, page)


def make_cache():
def make_cache(agent_selection=None):
from grid2viz.src.manager import (
scenarios,
agents,
Expand All @@ -188,6 +188,9 @@ def make_cache():
cache_dir,
)

if(agent_selection is not None):
agents=[agent for agent in agents if agent in agent_selection]

from pathos.multiprocessing import ProcessPool

if not os.path.exists(cache_dir):
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ Grid2Op = "^1.6.4"
imageio = "^2.9.0"
jupyter-dash = "^0.3.1"
pathos = "^0.2.7"
pandapower = "2.4.0"
pandapower = "^2.2.0"
matplotlib = "^3.3.3"
numpy = "^1.18.4"
seaborn = "^0.11.0"
nbgitpuller = "^0.9.0"
jupyter-server-proxy = "^1.5.0"
ExpertOp4grid = { git = "https://github.com/marota/ExpertOp4Grid.git", branch = "master" }
ExpertOp4grid = { version = "^0.0.1", optional = true }

[tool.poetry.dev-dependencies]
black = "^20.8b1"
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ numpy == 1.19.3
seaborn == 0.11.0
nbgitpuller == 0.9.0
jupyter-server-proxy == 1.5.0
pytest

41 changes: 31 additions & 10 deletions tests/test_make_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,41 @@
import shutil
import subprocess
import unittest
from grid2viz.main import make_cache

# We need to make this below so that the manager.py finds the config.ini
os.environ["GRID2VIZ_ROOT"] = os.path.join(
pathlib.Path(__file__).parent.absolute(), "data"
)

agents_path = os.path.join(pathlib.Path(__file__).parent.absolute(), "data", "agents")

#config_file_path = os.path.join(os.environ["GRID2VIZ_ROOT"], "config.ini")

class TestMakeCache(unittest.TestCase):
def setUp(self):
self.agent_path = os.path.join(
pathlib.Path(__file__).parent.absolute(), "data", "agents"
)
if os.path.isdir(os.path.join(self.agent_path, "_cache")):
shutil.rmtree(os.path.join(self.agent_path, "_cache"))
self.agent_path = agents_path
self.agent="greedy-baseline"
cache_file_path=os.path.join(self.agent_path, "_cache", "000",self.agent+".dill")
if os.path.exists(cache_file_path):
os.remove(cache_file_path)
#if os.path.isdir(os.path.join(self.agent_path, "_cache")):
# shutil.rmtree(os.path.join(self.agent_path, "_cache"))

def test_make_cache(self):
print(self.agent_path)
cmd = ["grid2viz", "--agents_path", self.agent_path, "--cache"]
rv = subprocess.run(
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE #, shell=True
)
self.assertEqual(rv.returncode, 0)
try:
make_cache(agent_selection=[self.agent])#to run the test quicker
except Exception as e:
print(e)
assert(False)

#calling grid2viz cli does not work when testing on circle ci
#cmd = ["grid2viz", "--agents_path", self.agent_path, "--cache"]
#rv=os.system("grid2viz --agents_path "+self.agent_path+" --cache")
#rv = subprocess.run(
# cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE#, shell=True
#)
#self.assertEqual(rv.returncode, 0)
#self.assertEqual(rv, 0)

0 comments on commit c30c2e7

Please sign in to comment.