Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change setup.py #449

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
exclude =
venv
max-line-length = 88
extend-ignore = E231
5 changes: 1 addition & 4 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: setup PYTHONPATH
run: |
export PYTHONPATH=${PWD}:${PYTHONPATH}
- name: Lint with flake8
run: |
# stop the build if flake8 fails.
flake8 . --count --show-source --statistics
flake8 . --extend-ignore=E231 --count --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --statistics
- name: Test with python unittest
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ We can synthesize neural-network controllers with Lyapunov stability guarantees.
## Python requirements
We use python 3 in this project. You could first install the packages in requirements.txt.

## Install gurobi
Please download gurobi from https://www.gurobi.com/products/gurobi-optimizer/. We require at least gurobi 9.5. After downloading the software, please install its Python API by following https://www.gurobi.com/documentation/9.0/quickstart_mac/the_grb_python_interface_f.html

To check your gurobi installation, type the following command in your terminal:
## Installation
Please run
```
$ python3 -c "import gurobipy"
pip install -e .
```
There should be no error thrown when executing the command.
to install the package together with the dependencies.

## Setup environment variable
In the terminal, please run
```
$ python3 setup.py
```
It will print out the command to setup the environment variables. Execute that command in your terminal.
## Setup gurobi
Please refer to https://support.gurobi.com/hc/en-us/articles/360044290292-How-do-I-install-Gurobi-for-Python- on setting up Gurobi. Note that by default Gurobi ships with a limited license that has size limits on the optimization problem. Please refer to https://support.gurobi.com/hc/en-us/articles/360051597492 on using your own academic or commential license.

## Run a toy example
You could run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def compute_delta_pos(model, network_input):


if __name__ == "__main__":
raise Exception("Dubins car cannot be stabilized by a continuous controller, refer" +
"to https://arxiv.org/pdf/math/9902026.pdf for a proof. Using" +
"neural-network controllers is doomed to fail for Dubins car.")
raise Exception("Dubins car cannot be stabilized by a continuous controller," +
"referto https://arxiv.org/pdf/math/9902026.pdf for a proof." +
"Using neural-network controllers is doomed to fail for Dubins" +
"car.")
parser = argparse.ArgumentParser(
description="Acceleration car training demo")
parser.add_argument("--generate_dynamics_data", action="store_true")
Expand Down
7 changes: 4 additions & 3 deletions neural_network_lyapunov/examples/car/train_unicycle_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ def compute_v(model, x):


if __name__ == "__main__":
raise Exception("Dubins car cannot be stabilized by a continuous controller, refer" +
"to https://arxiv.org/pdf/math/9902026.pdf for a proof. Using" +
"neural-network controllers is doomed to fail for Dubins car.")
raise Exception("Dubins car cannot be stabilized by a continuous controller," +
" refer to https://arxiv.org/pdf/math/9902026.pdf for a proof." +
" Using neural-network controllers is doomed to fail for Dubins" +
" car.")
parser = argparse.ArgumentParser(description="Unicycle training demo")
parser.add_argument("--generate_dynamics_data", action="store_true")
parser.add_argument("--load_dynamics_data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def get_mesh_markers(traj, num_markers):
args = parser.parse_args()

traj = np.load(args.file)
assert(isinstance(traj, np.ndarray))
assert(len(traj.shape) == 2)
assert(traj.shape[0] >= 6)
assert(traj.shape[1] >= 2)
assert (isinstance(traj, np.ndarray))
assert (len(traj.shape) == 2)
assert (traj.shape[0] >= 6)
assert (traj.shape[1] >= 2)

mesh_pub = rospy.Publisher('animated_mesh', Marker, queue_size=10)
traj_line_pub = rospy.Publisher('traj_line', Marker, queue_size=10)
Expand Down
2 changes: 1 addition & 1 deletion neural_network_lyapunov/examples/rl/td3.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def test_agent(epoch):
mean_ret = 0.
for j in range(num_test_episodes):
o, d, ep_ret, ep_len = test_env.reset(), False, 0, 0
while not(d or (ep_len == max_ep_len)):
while not (d or (ep_len == max_ep_len)):
# Take deterministic actions at test time (noise_scale=0)
o, r, d, _ = test_env.step(get_action(o, 0))
ep_ret += r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def generate_dataset(cfg, mb, actuation_mask):
j += 1
else:
tau[i] = 0
assert(j == u_dim)
assert (j == u_dim)

mb.q = q
mb.qd = qd
Expand Down
1 change: 0 additions & 1 deletion neural_network_lyapunov/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ def leaky_relu_interval(negative_slope, x_lo, x_up):
[output_lo, output_up]
"""
assert (x_up > x_lo)
assert (type(x_lo) == type(x_up))
if (negative_slope >= 0):
if x_lo >= 0:
if isinstance(x_lo, torch.Tensor):
Expand Down
10 changes: 7 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pytorch >= 1.8
cvxpy >= 1.1
flake8
gurobipy == 10.0
matplotlib
numpy >= 1.18
pybullet
torch
scipy >= 1.4
tensorboard >= 2.3
pybullet
cvxpy >= 1.1
wandb
36 changes: 12 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import os

from os.path import dirname, abspath, isdir


def main():
cur_dir = dirname(abspath(__file__))
# Now add this folder to PYTHONPATH
setup_script = cur_dir + "/config/setup_environments.sh"
if not isdir(cur_dir+"/config"):
print("create config folder")
os.mkdir(cur_dir+"/config")
with open(setup_script, "a") as f:
f.write(f"""
export PYTHONPATH={cur_dir}:${{PYTHONPATH}}
""")
print("""
To use neural_network_lyapunov functionality:
source ./config/setup_environments.sh
""")


if __name__ == "__main__":
main()
from setuptools import setup, find_packages

# Read the contents of requirements file
with open("requirements.txt") as f:
requirements = f.read().splitlines()

setup(
name="neural-network-lyapunov",
version="0.1",
packages=find_packages(),
install_requires=requirements,
)
Loading