title: How to tune conditional objective function using optuna or hyperopt
body: <p>I tried to use optuna to tune hyperparameters. But my objective function is conditional which creates issues in getting optimal parameters.</p>
  
  <p>i want to get cwc only if the condtion is met otherwise continue trial for next hyperparameters.
  But i guess since the condition is not met and objective func reurns cwc it gives error</p>
  
  <p>UnboundLocalError: local variable 'cwc_train' referenced before assignment</p>
  
  <pre><code>define objective (trial):
      k_dis = trial.suggest_uniform('k_dis', 0.0, 5.0)
      l_dis = trial.suggest_uniform('l_dis', 0.0, 5.0)
      k_bound = trial.suggest_uniform('k_bound', 0.0, 5.0)
      l_bound = trial.suggest_uniform('l_bound', 0.0, 5.0) 
  
      picp = .....
      pinrw = .....
  
  
      if picp_train &gt;= 0.8 and pinrw_train &lt; 0.18: 
          cwc_train = fc.CWC_proposed(predict_bound_train, Y_train)
      else:
          print("error = ")
      return  cwc_train
  study = optuna.create_study()
  study.optimize(objective, n_trials=100)
  </code></pre>
  
  <p>UnboundLocalError: local variable 'cwc_train' referenced before assignment</p>