Skip to content

Commit

Permalink
upgrade dependency and fix clang-tidy error (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinkle23897 authored Dec 29, 2022
1 parent 1f1c12f commit 76e1c86
Show file tree
Hide file tree
Showing 44 changed files with 138 additions and 163 deletions.
16 changes: 4 additions & 12 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,15 @@ Checks: '
performance-*,
portability-*,
readability-*,
-clang-diagnostic-delete-non-abstract-non-virtual-dtor,
-google-runtime-references,
-modernize-use-trailing-return-type,
-readability-magic-numbers,
-readability-static-accessed-through-instance,
-readability-uppercase-literal-suffix,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-google-readability-casting,
-modernize-return-braced-init-list,
-modernize-use-default-member-init,
-performance-no-int-to-ptr,
-modernize-use-trailing-return-type,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-redundant-smartptr-get,
-readability-simplify-boolean-expr,
-readability-magic-numbers,
-readability-static-accessed-through-instance,
-readability-uppercase-literal-suffix,
'
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
release:
runs-on: ubuntu-latest
container: trinkle23897/envpool-release:2022-12-28-e857ca2
container: trinkle23897/envpool-release:2022-12-29-03c3d95
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cpplint-install:
$(call check_install, cpplint)

clang-format-install:
command -v clang-format-11 || sudo apt-get install -y clang-format-11
command -v clang-format || sudo apt-get install -y clang-format

clang-tidy-install:
command -v clang-tidy || sudo apt-get install -y clang-tidy
Expand Down Expand Up @@ -77,7 +77,7 @@ cpplint: cpplint-install
cpplint $(CPP_FILES)

clang-format: clang-format-install
clang-format-11 --style=file -i $(CPP_FILES) -n --Werror
clang-format --style=file -i $(CPP_FILES) -n --Werror

# bazel file linter

Expand All @@ -87,10 +87,10 @@ buildifier: buildifier-install
# bazel build/test

bazel-pip-requirement-dev:
cp third_party/pip_requirements/requirements-dev.txt third_party/pip_requirements/requirements.txt
cd third_party/pip_requirements && (cmp requirements.txt requirements-dev.txt || ln -sf requirements-dev.txt requirements.txt)

bazel-pip-requirement-release:
cp third_party/pip_requirements/requirements-release.txt third_party/pip_requirements/requirements.txt
cd third_party/pip_requirements && (cmp requirements.txt requirements-release.txt || ln -sf requirements-release.txt requirements.txt)

clang-tidy: clang-tidy-install bazel-pip-requirement-dev
bazel build $(BAZELOPT) //... --config=clang-tidy --config=test
Expand Down Expand Up @@ -142,7 +142,7 @@ lint: buildifier flake8 py-format clang-format cpplint clang-tidy mypy docstyle
format: py-format-install clang-format-install buildifier-install addlicense-install
isort $(PYTHON_FILES)
yapf -ir $(PYTHON_FILES)
clang-format-11 -style=file -i $(CPP_FILES)
clang-format -style=file -i $(CPP_FILES)
buildifier -r -lint=fix $(BAZEL_FILES)
addlicense -c $(COPYRIGHT) -l apache -y 2023 $(PROJECT_FOLDER)

Expand All @@ -157,16 +157,16 @@ docker-ci-push: docker-ci
docker push $(DOCKER_USER)/$(PROJECT_NAME):$(DOCKER_TAG)

docker-ci-launch: docker-ci
docker run --network=host -v /home/ubuntu:/home/github-action -it $(PROJECT_NAME):$(DOCKER_TAG) bash
docker run --network=host -v /home/ubuntu:/home/github-action --shm-size=4gb -it $(PROJECT_NAME):$(DOCKER_TAG) bash

docker-dev: docker-ci
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(DOCKER_TAG) bash
docker run --network=host -v /:/host --shm-size=4gb -it $(PROJECT_NAME):$(DOCKER_TAG) bash

# for mainland China
docker-dev-cn:
docker build --network=host -t $(PROJECT_NAME):$(DOCKER_TAG) -f docker/dev-cn.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME):$(DOCKER_TAG)
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(DOCKER_TAG) bash
docker run --network=host -v /:/host --shm-size=4gb -it $(PROJECT_NAME):$(DOCKER_TAG) bash

docker-release:
docker build --network=host -t $(PROJECT_NAME)-release:$(DOCKER_TAG) -f docker/release.dockerfile .
Expand All @@ -177,7 +177,7 @@ docker-release-push: docker-release
docker push $(DOCKER_USER)/$(PROJECT_NAME)-release:$(DOCKER_TAG)

docker-release-launch: docker-release
docker run --network=host -v /:/host -it $(PROJECT_NAME)-release:$(DOCKER_TAG) bash
docker run --network=host -v /:/host --shm-size=4gb -it $(PROJECT_NAME)-release:$(DOCKER_TAG) bash

pypi-wheel: auditwheel-install bazel-release
ls dist/*.whl -Art | tail -n 1 | xargs auditwheel repair --plat manylinux_2_17_x86_64
Expand Down
2 changes: 1 addition & 1 deletion docker/dev-cn.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG HOME=/root
ARG PATH=$PATH:$HOME/go/bin

RUN apt-get update \
&& apt-get install -y python3-pip python3-dev golang-1.18 clang-format-11 git wget swig tmux clang-tidy \
&& apt-get install -y python3-pip python3-dev golang-1.18 clang-format-11 git wget swig tmux clang-tidy vim \
&& rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go
Expand Down
2 changes: 1 addition & 1 deletion docker/dev.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG HOME=/root
ARG PATH=$PATH:$HOME/go/bin

RUN apt-get update \
&& apt-get install -y python3-pip python3-dev golang-1.18 clang-format-11 git wget swig tmux clang-tidy \
&& apt-get install -y python3-pip python3-dev golang-1.18 clang-format-11 git wget swig tmux clang-tidy vim \
&& rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go
Expand Down
2 changes: 1 addition & 1 deletion envpool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
register,
)

__version__ = "0.6.7"
__version__ = "0.7.0"
__all__ = [
"register",
"make",
Expand Down
10 changes: 4 additions & 6 deletions envpool/atari/atari_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@

namespace atari {

bool TurnOffVerbosity() {
auto TurnOffVerbosity() {
ale::Logger::setMode(ale::Logger::Error);
return true;
}

static bool verbosity_off = TurnOffVerbosity();

std::string GetRomPath(const std::string& base_path, const std::string& task) {
auto GetRomPath(const std::string& base_path, const std::string& task) {
std::stringstream ss;
// hardcode path here :(
ss << base_path << "/atari/roms/" << task << ".bin";
Expand Down Expand Up @@ -88,9 +88,9 @@ class AtariEnv : public Env<AtariEnvSpec> {
std::unique_ptr<ale::ALEInterface> env_;
ale::ActionVect action_set_;
int max_episode_steps_, elapsed_step_, stack_num_, frame_skip_;
bool fire_reset_, reward_clip_, zero_discount_on_life_loss_;
bool fire_reset_{false}, reward_clip_, zero_discount_on_life_loss_;
bool gray_scale_, episodic_life_, use_inter_area_resize_;
bool done_;
bool done_{true};
int lives_;
FrameSpec raw_spec_, resize_spec_, transpose_spec_;
std::deque<Array> stack_buf_;
Expand All @@ -107,13 +107,11 @@ class AtariEnv : public Env<AtariEnvSpec> {
elapsed_step_(max_episode_steps_ + 1),
stack_num_(spec.config["stack_num"_]),
frame_skip_(spec.config["frame_skip"_]),
fire_reset_(false),
reward_clip_(spec.config["reward_clip"_]),
zero_discount_on_life_loss_(spec.config["zero_discount_on_life_loss"_]),
gray_scale_(spec.config["gray_scale"_]),
episodic_life_(spec.config["episodic_life"_]),
use_inter_area_resize_(spec.config["use_inter_area_resize"_]),
done_(true),
raw_spec_({kRawHeight, kRawWidth, gray_scale_ ? 1 : 3}),
resize_spec_({spec.config["img_height"_], spec.config["img_width"_],
gray_scale_ ? 1 : 3}),
Expand Down
4 changes: 1 addition & 3 deletions envpool/box2d/bipedal_walker_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ BipedalWalkerBox2dEnv::BipedalWalkerBox2dEnv(bool hardcore,
: max_episode_steps_(max_episode_steps),
elapsed_step_(max_episode_steps + 1),
hardcore_(hardcore),
done_(true),
world_(new b2World(b2Vec2(0.0, -10.0))),
hull_(nullptr) {
world_(new b2World(b2Vec2(0.0, -10.0))) {
for (const auto* p : kHullPoly) {
hull_poly_.emplace_back(Vec2(p[0] / kScaleDouble, p[1] / kScaleDouble));
}
Expand Down
4 changes: 2 additions & 2 deletions envpool/box2d/bipedal_walker_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class BipedalWalkerBox2dEnv {
protected:
int max_episode_steps_, elapsed_step_;
float reward_, prev_shaping_;
bool hardcore_, done_;
bool hardcore_, done_{true};
std::array<float, 24> obs_;
// info
float scroll_;
std::vector<float> path2_, path4_, path5_;

// box2d related
std::unique_ptr<b2World> world_;
b2Body* hull_;
b2Body* hull_{nullptr};
std::vector<b2Vec2> hull_poly_;
std::vector<b2Body*> terrain_;
std::array<b2Body*, 4> legs_;
Expand Down
6 changes: 3 additions & 3 deletions envpool/box2d/car_dynamics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ b2PolygonShape GeneratePolygon(const float (*poly)[2], int size) { // NOLINT

Car::Car(std::shared_ptr<b2World> world, float init_angle, float init_x,
float init_y)
: world_(std::move(world)), hull_(nullptr), fuel_spent_(0) {
: world_(std::move(world)) {
// Create hull
b2BodyDef bd;
bd.position.Set(init_x, init_y);
Expand Down Expand Up @@ -186,7 +186,7 @@ void Car::Step(float dt) {
} else if (w->skid_start == nullptr) {
w->skid_start = std::make_unique<b2Vec2>(w->body->GetPosition());
} else {
w->skid_particle = CreateParticle(*(w->skid_start.get()),
w->skid_particle = CreateParticle(*(w->skid_start.get()), // NOLINT
w->body->GetPosition(), grass);
w->skid_start = nullptr;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ void Car::Draw(const cv::Mat& surf, float zoom,
cv::fillPoly(surf, poly, color);

auto* user_data =
reinterpret_cast<UserData*>(body->GetUserData().pointer);
reinterpret_cast<UserData*>(body->GetUserData().pointer); // NOLINT
if (user_data == nullptr || user_data->type != WHEEL_TYPE) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions envpool/box2d/car_dynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ class Car {
std::deque<std::shared_ptr<Particle>> particles_;
std::vector<b2Body*> drawlist_;
std::shared_ptr<b2World> world_;
b2Body* hull_;
b2Body* hull_{nullptr};
std::vector<Wheel*> wheels_;
float fuel_spent_;
float fuel_spent_{0};

std::shared_ptr<Particle> CreateParticle(b2Vec2 point1, b2Vec2 point2,
bool grass);
Expand Down
5 changes: 2 additions & 3 deletions envpool/box2d/car_racing_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void CarRacingFrictionDetector::Contact(b2Contact* contact, bool begin) {
Tile* tile = nullptr;
Wheel* obj = nullptr;

auto* u1 = reinterpret_cast<UserData*>(
auto* u1 = reinterpret_cast<UserData*>( // NOLINT
contact->GetFixtureA()->GetBody()->GetUserData().pointer);
auto* u2 = reinterpret_cast<UserData*>(
auto* u2 = reinterpret_cast<UserData*>( // NOLINT
contact->GetFixtureB()->GetBody()->GetUserData().pointer);

if (u1 == nullptr || u2 == nullptr) {
Expand Down Expand Up @@ -84,7 +84,6 @@ CarRacingBox2dEnv::CarRacingBox2dEnv(int max_episode_steps,
: lap_complete_percent_(lap_complete_percent),
max_episode_steps_(max_episode_steps),
elapsed_step_(max_episode_steps + 1),
done_(true),
world_(new b2World(b2Vec2(0.0, 0.0))) {
b2PolygonShape shape;
std::array<b2Vec2, 4> vertices = {b2Vec2(0, 0), b2Vec2(1, 0), b2Vec2(1, -1),
Expand Down
2 changes: 1 addition & 1 deletion envpool/box2d/car_racing_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CarRacingBox2dEnv {
float reward_{0};
float prev_reward_{0};
float step_reward_{0};
bool done_;
bool done_{true};

cv::Mat surf_;
cv::Mat img_array_;
Expand Down
5 changes: 1 addition & 4 deletions envpool/box2d/lunar_lander_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ LunarLanderBox2dEnv::LunarLanderBox2dEnv(bool continuous, int max_episode_steps)
: max_episode_steps_(max_episode_steps),
elapsed_step_(max_episode_steps + 1),
continuous_(continuous),
done_(true),
world_(new b2World(b2Vec2(0.0, -10.0))),
moon_(nullptr),
lander_(nullptr) {
world_(new b2World(b2Vec2(0.0, -10.0))) {
for (const auto* p : kLanderPoly) {
lander_poly_.emplace_back(Vec2(p[0] / kScale, p[1] / kScale));
}
Expand Down
4 changes: 2 additions & 2 deletions envpool/box2d/lunar_lander_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class LunarLanderBox2dEnv {
protected:
int max_episode_steps_, elapsed_step_;
float reward_, prev_shaping_;
bool continuous_, done_;
bool continuous_, done_{true};
std::array<float, 8> obs_;

// box2d related
std::unique_ptr<b2World> world_;
b2Body *moon_, *lander_;
b2Body *moon_{nullptr}, *lander_{nullptr};
std::vector<b2Body*> particles_;
std::vector<b2Vec2> lander_poly_;
std::array<b2Body*, 2> legs_;
Expand Down
4 changes: 2 additions & 2 deletions envpool/box2d/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace box2d {

b2Vec2 Vec2(double x, double y) {
return b2Vec2(static_cast<float>(x), static_cast<float>(y));
return {static_cast<float>(x), static_cast<float>(y)};
}

float Sign(double val, double eps) {
Expand All @@ -43,7 +43,7 @@ b2Vec2 RotateRad(const b2Vec2& v, float angle) {
b2Vec2 Multiply(const b2Transform& trans, const b2Vec2& v) {
float x = (trans.q.c * v.x - trans.q.s * v.y) + trans.p.x;
float y = (trans.q.s * v.x + trans.q.c * v.y) + trans.p.y;
return b2Vec2(x, y);
return {x, y};
}

} // namespace box2d
11 changes: 5 additions & 6 deletions envpool/classic_control/acrobot.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class AcrobotEnv : public Env<AcrobotEnvSpec> {
V5(double s0, double s1, double s2, double s3, double s4)
: s0(s0), s1(s1), s2(s2), s3(s3), s4(s4) {}
V5 operator+(const V5& v) const {
return V5(s0 + v.s0, s1 + v.s1, s2 + v.s2, s3 + v.s3, s4 + v.s4);
return {s0 + v.s0, s1 + v.s1, s2 + v.s2, s3 + v.s3, s4 + v.s4};
}
V5 operator*(double v) const {
return V5(s0 * v, s1 * v, s2 * v, s3 * v, s4 * v);
return {s0 * v, s1 * v, s2 * v, s3 * v, s4 * v};
}
};

Expand All @@ -74,15 +74,14 @@ class AcrobotEnv : public Env<AcrobotEnvSpec> {
int max_episode_steps_, elapsed_step_;
V5 s_;
std::uniform_real_distribution<> dist_;
bool done_;
bool done_{true};

public:
AcrobotEnv(const Spec& spec, int env_id)
: Env<AcrobotEnvSpec>(spec, env_id),
max_episode_steps_(spec.config["max_episode_steps"_]),
elapsed_step_(max_episode_steps_ + 1),
dist_(-kInitRange, kInitRange),
done_(true) {}
dist_(-kInitRange, kInitRange) {}

bool IsDone() override { return done_; }

Expand Down Expand Up @@ -164,7 +163,7 @@ class AcrobotEnv : public Env<AcrobotEnvSpec> {
kM * kL * kLC * dtheta1 * dtheta1 * std::sin(theta2) - phi2) /
(kM * kLC * kLC + kI - d2 * d2 / d1);
double ddtheta1 = -(d2 * ddtheta2 + phi1) / d1;
return V5(dtheta1, dtheta2, ddtheta1, ddtheta2, 0);
return {dtheta1, dtheta2, ddtheta1, ddtheta2, 0};
}

void WriteState(float reward) {
Expand Down
5 changes: 2 additions & 3 deletions envpool/classic_control/cartpole.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ class CartPoleEnv : public Env<CartPoleEnvSpec> {
int max_episode_steps_, elapsed_step_;
double x_, x_dot_, theta_, theta_dot_;
std::uniform_real_distribution<> dist_;
bool done_;
bool done_{true};

public:
CartPoleEnv(const Spec& spec, int env_id)
: Env<CartPoleEnvSpec>(spec, env_id),
max_episode_steps_(spec.config["max_episode_steps"_]),
elapsed_step_(max_episode_steps_ + 1),
dist_(-kInitRange, kInitRange),
done_(true) {}
dist_(-kInitRange, kInitRange) {}

bool IsDone() override { return done_; }

Expand Down
5 changes: 2 additions & 3 deletions envpool/classic_control/mountain_car.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ class MountainCarEnv : public Env<MountainCarEnvSpec> {
int max_episode_steps_, elapsed_step_;
double pos_, vel_;
std::uniform_real_distribution<> dist_;
bool done_;
bool done_{true};

public:
MountainCarEnv(const Spec& spec, int env_id)
: Env<MountainCarEnvSpec>(spec, env_id),
max_episode_steps_(spec.config["max_episode_steps"_]),
elapsed_step_(max_episode_steps_ + 1),
dist_(-0.6, -0.4),
done_(true) {}
dist_(-0.6, -0.4) {}

bool IsDone() override { return done_; }

Expand Down
Loading

0 comments on commit 76e1c86

Please sign in to comment.