Skip to content

Commit

Permalink
CICD (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmenzenbach committed Feb 10, 2021
1 parent b216547 commit caee3a1
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 125 deletions.
10 changes: 10 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ ignore:
- "Pyrado/pyrado/environments/mujoco"
- "Pyrado/scripts"
- "Pyrado/tests"
comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false # if true: only post the comment if coverage changes
require_base: no # [yes :: must have a base report to post]
require_head: yes # [yes :: must have a head report to post]
branches: # branch names that can post comment
- "master"
github_checks:
annotations: false
52 changes: 0 additions & 52 deletions .github/workflows/build_docs.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy Documentation

on:
workflow_run:
workflows: ["Publish Docker Images"]
branches: [cicd]
types:
- completed
- requested

jobs:
build-docs:
runs-on: ubuntu-latest
needs: build-images
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.PAT }}
- name: Build Docs
continue-on-error: true
run: |
mkdir public
export PUBLIC=$(realpath ./public)
docker run --rm -u 1000:1000 -v $PUBLIC:/var/www ghcr.io/famura/simurlacra:sacher conda run -n pyrado bash -c "./build_docs.sh;sudo mkdir /var/www/pyrado; sudo cp -r Pyrado/doc/build/* /var/www/pyrado;mv RcsPySim/build/doc/html RcsPySim/build/doc/rcspysim; sudo cp -r RcsPySim/build/doc/rcspysim /var/www"
echo $PUBLIC
ls $PUBLIC quietioet
- name: Deploy
continue-on-error: true
uses: JamesIves/github-pages-deploy-action@3.5.9
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: public
8 changes: 5 additions & 3 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: Build Image
run: |
docker pull simurlacra/simurlacra:sacher
docker build . -t simurlacra:test --build-arg OPTION=sacher
- name: Execute tests
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
docker pull simurlacra/simurlacra:sacher
docker build . -t simurlacra:test --build-arg OPTION=sacher --cache-from simurlacra/simurlacra:sacher
export COVPATH=$(realpath .)
docker run --rm -i -v $COVPATH:/cov simurlacra:test conda run -n pyrado bash -c "pytest Pyrado/tests --cov=./Pyrado --cov-report=xml -v -m 'not visualization' -n 4; sudo cp ./coverage.xml /cov"
docker run --rm -i -v $COVPATH:/cov simurlacra:test bash -c "pytest Pyrado --cov=./Pyrado --cov-report=xml --verbose -n 2 -m 'not visualization'; sudo cp ./coverage.xml /cov"
sudo mkdir /home/user/
sudo mkdir /home/user/SimuRLacra
sudo ln -s $COVPATH /home/user/SimuRLacra
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/run_tests_future.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Tests (future)

on:
push:
branches: [cicd_future]
pull_request:
branches: [cicd_future]

jobs:
build-images:
runs-on: ubuntu-latest
strategy:
matrix:
flavor: [sacher]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
outputs: |
type=docker
tags: |
simurlacra:test
build-args: |
OPTION=${{ matrix.flavor }}
cache-from: type=registry,ref=simurlacra/simurlacra:${{ matrix.flavor }}
- name: Inspect
run: |
docker image inspect simurlacra:test
- name: Execute tests
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
export COVPATH=$(realpath .)
docker run --rm -i -v $COVPATH:/cov simurlacra:test conda run -n pyrado bash -c "pytest Pyrado/tests --cov=./Pyrado --cov-report=xml -n 4 --verbose -m 'not visualization'; sudo cp ./coverage.xml /cov"
sudo mkdir /home/user/
sudo mkdir /home/user/SimuRLacra
sudo ln -s $COVPATH /home/user/SimuRLacra
cd Pyrado
- name: Send Coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: coverage.xml # optional
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v2.7.5
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: |
coverage.xml:cobertura
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ USER user
WORKDIR /home/user

# Setup conda
RUN echo "export PATH=/home/user/miniconda3/bin:$PATH" >> ~/.bashrc

RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
RUN echo "export PATH=/home/user/miniconda3/bin:$PATH" >> ~/.bashrc \
&& wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm Miniconda3-latest-Linux-x86_64.sh

Expand All @@ -71,7 +70,7 @@ RUN conda create -n pyrado python=3.7 blas cmake lapack libgcc-ng mkl mkl-includ
SHELL ["conda", "run", "-n", "pyrado", "/bin/bash", "-c"]

RUN pip install argparse black box2d colorama coverage cython glfw gym joblib prettyprinter matplotlib numpy optuna pandas pycairo pytest pytest-cov pytest-xdist pyyaml scipy seaborn sphinx sphinx-math-dollar sphinx_rtd_theme tabulate tensorboard tqdm vpython git+https://github.com/Xfel/init-args-serializer.git@master; \
conda init bashL; rm -fr /home/user/.cache
conda init bash ; rm -fr /home/user/.cache

# Add env variables
ENV PATH /home/user/miniconda3/envs/pyrado/bin:$PATH
Expand Down
10 changes: 5 additions & 5 deletions Pyrado/pyrado/algorithms/meta/adr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from typing import Optional, Sequence

import numpy as np
import pyrado
import torch as to
from init_args_serializer import Serializable
from torch import nn as nn
from tqdm import tqdm
from typing import Sequence, Optional

import pyrado
from pyrado.algorithms.base import Algorithm
from pyrado.algorithms.step_based.svpg import SVPG
from pyrado.domain_randomization.domain_parameter import DomainParam
Expand All @@ -48,6 +46,8 @@
from pyrado.sampling.step_sequence import StepSequence
from pyrado.spaces.box import BoxSpace
from pyrado.utils.data_types import EnvSpec
from torch import nn as nn
from tqdm import tqdm


class ADR(Algorithm):
Expand Down
42 changes: 25 additions & 17 deletions Pyrado/pyrado/algorithms/meta/bayrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,37 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import numpy as np
import os
import os.path as osp
from typing import Optional, Union

import numpy as np
import pyrado
import torch as to
from botorch.models import SingleTaskGP
from botorch.acquisition import ExpectedImprovement, PosteriorMean, ProbabilityOfImprovement, UpperConfidenceBound
from botorch.fit import fit_gpytorch_model
from botorch.acquisition import UpperConfidenceBound, ExpectedImprovement, ProbabilityOfImprovement, PosteriorMean
from botorch.models import SingleTaskGP
from botorch.optim import optimize_acqf
from gpytorch.constraints import GreaterThan
from gpytorch.mlls import ExactMarginalLogLikelihood
from tabulate import tabulate
from typing import Optional, Union

import pyrado
from pyrado.algorithms.base import Algorithm, InterruptableAlgorithm
from pyrado.algorithms.utils import until_thold_exceeded
from pyrado.logger.step import StepLogger
from pyrado.spaces import BoxSpace
from pyrado.environment_wrappers.base import EnvWrapper
from pyrado.environment_wrappers.domain_randomization import MetaDomainRandWrapper
from pyrado.environment_wrappers.utils import inner_env, typed_env
from pyrado.environments.real_base import RealEnv
from pyrado.environments.sim_base import SimEnv
from pyrado.logger.step import StepLogger
from pyrado.policies.base import Policy
from pyrado.sampling.bootstrapping import bootstrap_ci
from pyrado.sampling.parallel_rollout_sampler import ParallelRolloutSampler
from pyrado.sampling.rollout import rollout
from pyrado.utils.order import natural_sort
from pyrado.spaces import BoxSpace
from pyrado.utils.data_processing import standardize
from pyrado.utils.input_output import print_cbt
from pyrado.utils.math import UnitCubeProjector
from pyrado.utils.data_processing import standardize
from pyrado.utils.order import natural_sort
from tabulate import tabulate


class BayRn(InterruptableAlgorithm):
Expand Down Expand Up @@ -159,7 +159,8 @@ def __init__(
self._subrtn.save_name = "subrtn"
self.ddp_space = ddp_space
self.ddp_projector = UnitCubeProjector(
to.from_numpy(self.ddp_space.bound_lo), to.from_numpy(self.ddp_space.bound_up)
to.from_numpy(self.ddp_space.bound_lo).to(dtype=to.get_default_dtype()),
to.from_numpy(self.ddp_space.bound_up).to(dtype=to.get_default_dtype()),
)
self.cands = None # called x in the context of GPs
self.cands_values = None # called y in the context of GPs
Expand Down Expand Up @@ -405,13 +406,16 @@ def step(self, snapshot_mode: str = "latest", meta_info: dict = None):
raise pyrado.ValueErr(given=self.acq_fcn_type, eq_constraint="'UCB', 'EI', 'PI'")

# Optimize acquisition function and get new candidate point
cand_norm, acq_value = optimize_acqf(
cand_norm, _ = optimize_acqf(
acq_function=acq_fcn,
bounds=to.stack([to.zeros(self.ddp_space.flat_dim), to.ones(self.ddp_space.flat_dim)]),
bounds=to.stack([to.zeros(self.ddp_space.flat_dim), to.ones(self.ddp_space.flat_dim)]).to(
dtype=to.float32
),
q=1,
num_restarts=self.acq_restarts,
raw_samples=self.acq_samples,
)
cand_norm = cand_norm.to(dtype=to.get_default_dtype())
next_cand = self.ddp_projector.project_back(cand_norm)
print_cbt(f"Found the next candidate: {next_cand.numpy()}", "g")
self.cands = to.cat([self.cands, next_cand], dim=0)
Expand Down Expand Up @@ -484,7 +488,10 @@ def argmax_posterior_mean(
raise pyrado.TypeErr(given=ddp_space, expected_type=BoxSpace)

# Normalize the input data and standardize the output data
uc_projector = UnitCubeProjector(to.from_numpy(ddp_space.bound_lo), to.from_numpy(ddp_space.bound_up))
uc_projector = UnitCubeProjector(
to.from_numpy(ddp_space.bound_lo).to(dtype=to.get_default_dtype()),
to.from_numpy(ddp_space.bound_up).to(dtype=to.get_default_dtype()),
)
cands_norm = uc_projector.project_to(cands)
cands_values_stdized = standardize(cands_values)

Expand All @@ -503,14 +510,15 @@ def argmax_posterior_mean(
fit_gpytorch_model(mll)

# Find position with maximal posterior mean
cand_norm, acq_value = optimize_acqf(
cand_norm, _ = optimize_acqf(
acq_function=PosteriorMean(gp),
bounds=to.stack([to.zeros(ddp_space.flat_dim), to.ones(ddp_space.flat_dim)]),
bounds=to.stack([to.zeros(ddp_space.flat_dim), to.ones(ddp_space.flat_dim)]).to(dtype=to.float32),
q=1,
num_restarts=num_restarts,
raw_samples=num_samples,
)

cand_norm = cand_norm.to(dtype=to.get_default_dtype())
cand = uc_projector.project_back(cand_norm.detach())
print_cbt(f"Converged to argmax of the posterior mean: {cand.numpy()}", "g", bright=True)
return cand
Expand Down
Loading

0 comments on commit caee3a1

Please sign in to comment.