diff --git a/bolero/controller/controller.py b/bolero/controller/controller.py index 24e9054d..62deaf6e 100644 --- a/bolero/controller/controller.py +++ b/bolero/controller/controller.py @@ -237,8 +237,8 @@ def episode(self, meta_parameter_keys=(), meta_parameters=()): return feedbacks - def episode_with(self, behavior, meta_parameter_keys=[], - meta_parameters=[], record=True): + def episode_with(self, behavior, meta_parameter_keys=(), + meta_parameters=(), record=True): """Execute a behavior in the environment. Parameters @@ -319,7 +319,7 @@ class ContextualController(Controller): * test_contexts (array-like) - the upper-level policy will be evaluated in these contexts """ - def __init__(self, config={}, environment=None, behavior_search=None, + def __init__(self, config=None, environment=None, behavior_search=None, **kwargs): super(ContextualController, self).__init__( config, environment, behavior_search, **kwargs) diff --git a/bolero/environment/openaigym.py b/bolero/environment/openaigym.py index 83217ab3..e21b3a22 100644 --- a/bolero/environment/openaigym.py +++ b/bolero/environment/openaigym.py @@ -143,7 +143,7 @@ def step_action(self): self.done = self.done or done self.step += 1 - if self.step >= self.env.spec.timestep_limit: + if self.step >= self.env.spec.max_episode_steps: self.done = True if self.log_to_stdout or self.log_to_file: diff --git a/bolero/environment/optimum_trajectory.py b/bolero/environment/optimum_trajectory.py index 6e6b9ecb..87a29cf3 100644 --- a/bolero/environment/optimum_trajectory.py +++ b/bolero/environment/optimum_trajectory.py @@ -86,10 +86,15 @@ def __init__(self, self.g = g self.execution_time = execution_time self.dt = dt + task_space_dim = len(x0) if obstacles is None: - self.obstacles = np.empty((0, len(x0))) + self.obstacles = np.empty((0, task_space_dim)) else: - self.obstacles = np.vstack(obstacles) + if len(obstacles[:]) % task_space_dim != 0: + raise ValueError("Obstacles defined by %d values. A multiple of %d (task space dimension) is required." + % (len(obstacles[:]), task_space_dim)) + self.obstacles = np.asarray(obstacles).reshape([-1, task_space_dim]) + assert self.obstacles.shape[1] == 2 self.obstacle_dist = obstacle_dist self.penalty_start_dist = penalty_start_dist self.penalty_goal_dist = penalty_goal_dist diff --git a/bolero/representation/promp_behavior.py b/bolero/representation/promp_behavior.py index 43f0a546..a9220289 100644 --- a/bolero/representation/promp_behavior.py +++ b/bolero/representation/promp_behavior.py @@ -290,7 +290,7 @@ def get_n_params(self): if self.learn_covariance: correlation_coefficients = ( len(self.data.covariance_) - random_variables) / 2 - return 2 * random_variables + correlation_coefficients + return int(2 * random_variables + correlation_coefficients) else: return random_variables diff --git a/bootstrap_bolero.sh b/bootstrap_bolero.sh index 0c6b2dea..bb891d6f 100755 --- a/bootstrap_bolero.sh +++ b/bootstrap_bolero.sh @@ -6,6 +6,13 @@ then echo -e "\e[31mPython '$PYTHON' not found.\e[0m" exit 1 fi +CYTHON_AVAILABLE=1 +`$PYTHON -c "import Cython" 2> /dev/null` || CYTHON_AVAILABLE=0 +if [ CYTHON_AVAILABLE == 0 ]; +then + echo "Cython for $PYTHON not available, trying to install it with '$PYTHON -m pip install Cython'" + $PYTHON -m pip install Cython +fi echo -e "\e[31mUsing Python: $PYTHON (located at `which $PYTHON`)\e[0m" # checking minimal dependencies on Ubuntu systems... diff --git a/examples/optimizer/plot_cmaes.py b/examples/optimizer/plot_cmaes.py index f68ccf9a..7333b0de 100644 --- a/examples/optimizer/plot_cmaes.py +++ b/examples/optimizer/plot_cmaes.py @@ -71,7 +71,7 @@ def plot_ellipse(cov, mean, color): plt.figure(figsize=(n_generations * 3 / n_rows, 3 * n_rows)) path = [] for it in range(n_generations): - plt.subplot(n_rows, n_generations / n_rows, it + 1) + plt.subplot(n_rows, int(n_generations / n_rows, it + 1)) plot_objective() last_mean = cmaes.mean.copy() path.append(last_mean) diff --git a/examples/optimizer/plot_contextual_optimization.py b/examples/optimizer/plot_contextual_optimization.py index e448069d..86b2bace 100644 --- a/examples/optimizer/plot_contextual_optimization.py +++ b/examples/optimizer/plot_contextual_optimization.py @@ -72,7 +72,7 @@ def plot_objective(): colors = {"C-CMA-ES": "r", "C-REPS": "g"} plt.figure(figsize=(n_generations * 3 / n_rows, 3 * n_rows)) for it in range(n_generations): - plt.subplot(n_rows, n_generations / n_rows, it + 1) + plt.subplot(n_rows, int(n_generations / n_rows, it + 1)) plot_objective() contexts = random_state.rand(n_samples_per_update, 1) * 10.0 - 5.0