internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: PaddlePaddle/models

Issue:
resnet50 训练报错
机器环境：linux_centos_cuda10_cudnn7_c++
paddle版本：release1.6
报错信息：
[21:49:25]W:     [Step 1/1] Traceback (most recent call last):
[21:49:25]W:     [Step 1/1]   File "train.py", line 293, in <module>
[21:49:25]W:     [Step 1/1]     main()
[21:49:25]W:     [Step 1/1]   File "train.py", line 289, in main
[21:49:25]W:     [Step 1/1]     train(args)
[21:49:25]W:     [Step 1/1]   File "train.py", line 216, in train
[21:49:25]W:     [Step 1/1]     train_fetch_vars[0], exe)
[21:49:25]W:     [Step 1/1]   File "/paddle/models/PaddleCV/image_classification/utils/utility.py", line 524, in best_strategy_compiled
[21:49:25]W:     [Step 1/1]     build_strategy.fuse_bn_act_ops = args.fuse_bn_act_ops
[21:49:25]W:     [Step 1/1] AttributeError: 'paddle.fluid.core_avx.BuildStrategy' object has no attribute 'fuse_bn_act_ops'
resnet50 训练报错
机器环境：linux_centos_cuda10_cudnn7_c++
paddle版本：release1.6
报错信息：
[21:49:25]W:     [Step 1/1] Traceback (most recent call last):
[21:49:25]W:     [Step 1/1]   File "train.py", line 293, in <module>
[21:49:25]W:     [Step 1/1]     main()
[21:49:25]W:     [Step 1/1]   File "train.py", line 289, in main
[21:49:25]W:     [Step 1/1]     train(args)
[21:49:25]W:     [Step 1/1]   File "train.py", line 216, in train
[21:49:25]W:     [Step 1/1]     train_fetch_vars[0], exe)
[21:49:25]W:     [Step 1/1]   File "/paddle/models/PaddleCV/image_classification/utils/utility.py", line 524, in best_strategy_compiled
[21:49:25]W:     [Step 1/1]     build_strategy.fuse_bn_act_ops = args.fuse_bn_act_ops
[21:49:25]W:     [Step 1/1] AttributeError: 'paddle.fluid.core_avx.BuildStrategy' object has no attribute 'fuse_bn_act_ops'


Discussion:

Resolving patch:
diff --git a/PaddleCV/image_classification/utils/utility.py b/PaddleCV/image_classification/utils/utility.py
--- a/PaddleCV/image_classification/utils/utility.py
+++ b/PaddleCV/image_classification/utils/utility.py
@@ -521,7 +521,12 @@ def best_strategy_compiled(args,
         return program
     else:
         build_strategy = fluid.compiler.BuildStrategy()
-        build_strategy.fuse_bn_act_ops = args.fuse_bn_act_ops
+        try:
+            fluid.require_version(min_version='1.7.0')
+            build_strategy.fuse_bn_act_ops = args.fuse_bn_act_ops
+        except Exception as e:
+            logger.info("PaddlePaddle version 1.7.0 or higher is "
+            "required when you want to fuse batch_norm and activation_op.")
         build_strategy.fuse_elewise_add_act_ops = args.fuse_elewise_add_act_ops
 
         exec_strategy = fluid.ExecutionStrategy()


Test patch:
Repository: PaddlePaddle/models

Issue:
emotion_detection/utils.py代码错误
utils.py第62行：seq_len = max_seq_len  是缩进错误吧？应该包括在else内，否则seq_len不能表示sequence的真实长度


Discussion:
这个地方确实有错误，需要修改，感谢反馈。

Resolving patch:
diff --git a/PaddleNLP/emotion_detection/utils.py b/PaddleNLP/emotion_detection/utils.py
--- a/PaddleNLP/emotion_detection/utils.py
+++ b/PaddleNLP/emotion_detection/utils.py
@@ -59,7 +59,7 @@ def pad_wid(wids, max_seq_len=128, pad_id=0):
             wids.append(pad_id)
     else:
         wids = wids[:max_seq_len]
-    seq_len = max_seq_len
+        seq_len = max_seq_len
     return wids, seq_len
 
 


Test patch:
Repository: optuna/optuna

Issue:
`TPESampler._sample_categorical` fails with PostgreSQL backend
`TPESampler._sample_categorical` fails with PostgreSQL backend. This happens because:
- `TPESampler._sample_categorical` returns an integer as `numpy.int32`.
- The integer value is input to storage class without any cast.
- SQLAlchemy with psycopg2 backend does not support `numpy.int32` input but does `int` one.

**Repro Steps**
With any objective function using categorical sampling (e.g., example one in `chainer_mnist.py`), invoke `minimize` as:
```
study = pfnopt.create_study(storage=SOME_POSTGRES_URL)
pfnopt.minimize(objective, n_trials=100, study=study)
```

It fails after running trials `n_startup_trails` times.


Discussion:

Resolving patch:
diff --git a/pfnopt/samplers/tpe.py b/pfnopt/samplers/tpe.py
--- a/pfnopt/samplers/tpe.py
+++ b/pfnopt/samplers/tpe.py
@@ -80,4 +80,4 @@ def _sample_categorical(self, distribution, below, above):
         idx = _hyperopt.sample_categorical(
             obs_below=below, obs_above=above, prior_weight=self.prior_weight,
             upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)
-        return idx
+        return int(idx)


Test patch:
Repository: optuna/optuna

Issue:
Document or user-friendly error message about psycopg2 installation 
Without psycopg2 or psycopg2-binary installation, RDBStorage does not work with PostgreSQL.

```console
$ pfnopt mkstudy --url postgresql://postgres:mysecretpassword@localhost:15432/postgres
No module named 'psycopg2'
```

Even though psycopg2 is not going to be added as a dependency, we've better clarify in document/error-message that user need an additional pip install for integration with PostgreSQL.


Discussion:

Resolving patch:
diff --git a/pfnopt/storages/rdb/storage.py b/pfnopt/storages/rdb/storage.py
--- a/pfnopt/storages/rdb/storage.py
+++ b/pfnopt/storages/rdb/storage.py
@@ -25,7 +25,14 @@ def __init__(self, url, connect_args=None):
         # type: (str, Optional[Dict[str, Any]]) -> None
 
         connect_args = connect_args or {}
-        self.engine = create_engine(url, connect_args=connect_args)
+
+        try:
+            self.engine = create_engine(url, connect_args=connect_args)
+        except ImportError as e:
+            raise ImportError(
+                'Failed to import DB access module for the specified storage URL. '
+                'Please install appropriate one. (The actual import error is: ' + str(e) + '.)')
+
         self.scoped_session = orm.scoped_session(orm.sessionmaker(bind=self.engine))
         models.BaseModel.metadata.create_all(self.engine)
         self._check_table_schema_compatibility()
@@ -416,4 +423,5 @@ def __del__(self):
         # counters, so it is not guaranteed that they are released by correct threads (for more
         # information, please see the docstring of remove_session).
 
-        self.remove_session()
+        if hasattr(self, 'scoped_session'):
+            self.remove_session()


Test patch:
diff --git a/tests/storages_tests/rdb_tests/test_storage.py b/tests/storages_tests/rdb_tests/test_storage.py
--- a/tests/storages_tests/rdb_tests/test_storage.py
+++ b/tests/storages_tests/rdb_tests/test_storage.py
@@ -1,6 +1,7 @@
 from mock import Mock
 from mock import patch
 import pytest
+import sys
 from typing import Dict  # NOQA
 import uuid
 
@@ -31,6 +32,17 @@ def test_init():
     assert version_info.library_version == version.__version__
 
 
+def test_init_db_module_import_error():
+    # type: () -> None
+
+    expected_msg = 'Failed to import DB access module for the specified storage URL. ' \
+                   'Please install appropriate one.'
+
+    with patch.dict(sys.modules, {'psycopg2': None}):
+        with pytest.raises(ImportError, match=expected_msg):
+            RDBStorage('postgresql://user:password@host/database')
+
+
 def test_create_new_study_id_multiple_studies():
     # type: () -> None
Repository: optuna/optuna

Issue:
params not being converted to internal_repr in FixedTrial suggest_* functions 
FixedTrial's `_suggest` function is missing a call to `distribution.to_internal_repr` before line [L606.](https://github.com/pfnet/optuna/blob/master/optuna/trial.py#L606)

**Conditions**
- Optuna version: 0.11.0
- Python version: 3.5.2
- OS: Ubuntu 16.04
- Machine Learning library to be optimized:

**Code to reproduce**

```
>>> import optuna
>>> trial = optuna.trial.FixedTrial({'test': 'one'})
>>> trial.suggest_categorical('test', ['one', 'two'])
```

**Error messages, stack traces, or logs**

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda3/envs/pjt0/lib/python3.5/site-packages/optuna/trial.py", line 596, in suggest_categorical
    return self._suggest(name, distributions.CategoricalDistribution(choices=choices))
  File "/anaconda3/envs/pjt0/lib/python3.5/site-packages/optuna/trial.py", line 606, in _suggest
    if not distribution._contains(value):
  File "/anaconda3/envs/pjt0/lib/python3.5/site-packages/optuna/distributions.py", line 191, in _contains
    index = int(param_value_in_internal_repr)
ValueError: invalid literal for int() with base 10: 'one'
```

Just adding the following line works.

```
param_value_in_internal_repr = distribution.to_internal_repr(value)
if not distribution._contains(param_value_in_internal_repr):
    ...
```



Discussion:

Resolving patch:
diff --git a/optuna/trial.py b/optuna/trial.py
--- a/optuna/trial.py
+++ b/optuna/trial.py
@@ -603,7 +603,8 @@ def _suggest(self, name, distribution):
                              'the construction of the FixedTrial object.'.format(name))
 
         value = self._params[name]
-        if not distribution._contains(value):
+        param_value_in_internal_repr = distribution.to_internal_repr(value)
+        if not distribution._contains(param_value_in_internal_repr):
             raise ValueError("The value {} of the parameter '{}' is out of "
                              "the range of the distribution {}.".format(value, name, distribution))
 


Test patch:
diff --git a/tests/test_trial.py b/tests/test_trial.py
--- a/tests/test_trial.py
+++ b/tests/test_trial.py
@@ -245,12 +245,20 @@ def test_fixed_trial_suggest_int():
 def test_fixed_trial_suggest_categorical():
     # type: () -> None
 
+    # Integer categories.
     trial = FixedTrial({'x': 1})
     assert trial.suggest_categorical('x', [0, 1, 2, 3]) == 1
 
     with pytest.raises(ValueError):
         trial.suggest_categorical('y', [0, 1, 2, 3])
 
+    # String categories.
+    trial = FixedTrial({'x': 'baz'})
+    assert trial.suggest_categorical('x', ['foo', 'bar', 'baz']) == 'baz'
+
+    with pytest.raises(ValueError):
+        trial.suggest_categorical('y', ['foo', 'bar', 'baz'])
+
 
 def test_fixed_trial_user_attrs():
     # type: () -> None
Repository: optuna/optuna

Issue:
ValueError when calling suggest_categorical with int and str
**Conditions**
- Optuna version: 0.13.0
- Python version: 3.7.3
- OS: Windows 10 Education
- Machine Learning library to be optimized: none

**Code to reproduce**
```
def objective(trial: optuna.Trial):
    x = trial.suggest_categorical("x", [1, "0"])
    print(x)
optuna.create_study( study_name="test_" + now_string(), storage="sqlite:///tmp/example.db").optimize(objective, n_trials=10)
```

**Error messages, stack traces, or logs**

```
Traceback (most recent call last):
  File "C:\Users\imri\github\scoring-model\venv\lib\site-packages\optuna\study.py", line 468, in _run_trial
    result = func(trial)
  File "~\github\scoring-model\tests\TestOptuna.py", line 12, in objective
    x = trial.suggest_categorical("x", [1, "0"])
  File "~\github\scoring-model\venv\lib\site-packages\optuna\trial.py", line 337, in suggest_categorical
    return self._suggest(name, distributions.CategoricalDistribution(choices=choices))
  File "~\github\scoring-model\venv\lib\site-packages\optuna\trial.py", line 457, in _suggest
    return self._set_new_param_or_get_existing(name, param_value, distribution)
  File "~\github\scoring-model\venv\lib\site-packages\optuna\trial.py", line 462, in _set_new_param_or_get_existing
    param_value_in_internal_repr = distribution.to_internal_repr(param_value)
  File "~\github\scoring-model\venv\lib\site-packages\optuna\distributions.py", line 236, in to_internal_repr
    return self.choices.index(param_value_in_external_repr)
ValueError: tuple.index(x): x not in tuple
```




Discussion:

Resolving patch:
diff --git a/optuna/samplers/random.py b/optuna/samplers/random.py
--- a/optuna/samplers/random.py
+++ b/optuna/samplers/random.py
@@ -69,6 +69,7 @@ def sample_independent(self, study, trial, param_name, param_distribution):
             return self.rng.randint(param_distribution.low, param_distribution.high + 1)
         elif isinstance(param_distribution, distributions.CategoricalDistribution):
             choices = param_distribution.choices
-            return self.rng.choice(choices)
+            index = self.rng.randint(0, len(choices))
+            return choices[index]
         else:
             raise NotImplementedError


Test patch:
diff --git a/tests/samplers_tests/test_samplers.py b/tests/samplers_tests/test_samplers.py
--- a/tests/samplers_tests/test_samplers.py
+++ b/tests/samplers_tests/test_samplers.py
@@ -120,7 +120,7 @@ def test_int(sampler_class, distribution):
 
 
 @parametrize_sampler
-@pytest.mark.parametrize('choices', [(1, 2, 3), ('a', 'b', 'c')])
+@pytest.mark.parametrize('choices', [(1, 2, 3), ('a', 'b', 'c'), (1, 'a')])
 def test_categorical(sampler_class, choices):
     # type: (typing.Callable[[], BaseSampler], typing.Tuple[T, ...]) -> None
Repository: optuna/optuna

Issue:
Dashboard only supports direction="minimize"

![image](https://user-images.githubusercontent.com/13174805/66481128-821b3980-eaa0-11e9-835e-34f47db3c2a6.png)

I used `optuna create-study --direction maximize --storage sqlite:///example.db` to create my study but the curve on the dashboard tracks only the minimum, not the maximum.

Maybe this is an error of `create-study` that doesn't take my argument into account…


Discussion:

Resolving patch:
diff --git a/optuna/dashboard.py b/optuna/dashboard.py
--- a/optuna/dashboard.py
+++ b/optuna/dashboard.py
@@ -52,16 +52,21 @@
 if _available:
 
     class _CompleteTrialsWidget(object):
-        def __init__(self, trials):
-            # type: (List[optuna.structs.FrozenTrial]) -> None
+        def __init__(self, trials, direction):
+            # type: (List[optuna.structs.FrozenTrial], optuna.structs.StudyDirection) -> None
 
             complete_trials = [
                 trial for trial in trials if trial.state == optuna.structs.TrialState.COMPLETE
             ]
             self.trial_ids = set([trial.trial_id for trial in complete_trials])
 
+            self.direction = direction
             values = [trial.value for trial in complete_trials]
-            best_values = np.minimum.accumulate(values, axis=0)
+            if direction == optuna.structs.StudyDirection.MINIMIZE:
+                best_values = np.minimum.accumulate(values, axis=0)
+            else:
+                best_values = np.maximum.accumulate(values, axis=0)
+
             self.cds = bokeh.models.ColumnDataSource({
                 '#': list(range(len(complete_trials))),
                 'value': values,
@@ -92,7 +97,10 @@ def update(self, new_trials):
                     continue
                 stream_dict['#'].append(len(self.trial_ids))
                 stream_dict['value'].append(trial.value)
-                self.best_value = min(self.best_value, trial.value)
+                if self.direction == optuna.structs.StudyDirection.MINIMIZE:
+                    self.best_value = min(self.best_value, trial.value)
+                else:
+                    self.best_value = max(self.best_value, trial.value)
                 stream_dict['best_value'].append(self.best_value)
                 self.trial_ids.add(trial.trial_id)
 
@@ -170,7 +178,8 @@ def __call__(self, doc):
             self.current_trials = \
                 self.study.trials  # type: Optional[List[optuna.structs.FrozenTrial]]
             self.new_trials = None  # type: Optional[List[optuna.structs.FrozenTrial]]
-            self.complete_trials_widget = _CompleteTrialsWidget(self.current_trials)
+            self.complete_trials_widget = _CompleteTrialsWidget(
+                self.current_trials, self.study.direction)
             self.all_trials_widget = _AllTrialsWidget(self.current_trials)
 
             self.doc.title = 'Optuna Dashboard (Beta)'


Test patch:
Repository: optuna/optuna

Issue:
Use OrderedDict to keep the order of intermediate values.
This PR addresses #886. 

I think it has two issues.

1. `dict` does not keep the order of keys

The current implementation of `FrozenTrial.intermediate_values` employs `dict`. The order of keys is not ensured if the users use Python 3.6 or older. This PR uses `OrderedDict` for `FrozenTrial.intermediate_values`.

2. RDBs do not ensure the order of results if a query has no `order by` clause.

This PR arranges the intermediate values when they are retrieved from databases.
Please note that the results are not necessarily ordered by primary keys when queries do not contain `order by`. (c.f., ['When no 'Order by' is specified, what order does a query choose for your record set?'](https://stackoverflow.com/questions/20050341/when-no-order-by-is-specified-what-order-does-a-query-choose-for-your-record))


Discussion:
Thanks for the swift PR. What do you think of documenting this expected behavior in the attribute description of the `FrozenTrial`? I was actually wondering what the expected behavior should be if the user reports values not in a non-strictly-ascending (e.g. some random) step order. Should the order be kept by insertion (implementation of this PR I think), or ordered by step? 

Resolving patch:
diff --git a/optuna/visualization/intermediate_values.py b/optuna/visualization/intermediate_values.py
--- a/optuna/visualization/intermediate_values.py
+++ b/optuna/visualization/intermediate_values.py
@@ -67,9 +67,10 @@ def _get_intermediate_plot(study):
     traces = []
     for trial in trials:
         if trial.intermediate_values:
+            sorted_intermediate_values = sorted(trial.intermediate_values.items())
             trace = go.Scatter(
-                x=tuple(trial.intermediate_values.keys()),
-                y=tuple(trial.intermediate_values.values()),
+                x=tuple((x for x, _ in sorted_intermediate_values)),
+                y=tuple((y for _, y in sorted_intermediate_values)),
                 mode='lines+markers',
                 marker={
                     'maxdisplayed': 10


Test patch:
Repository: optuna/optuna

Issue:
Axis labels of parallel coordinate plots overlap if the parameter names are long.
As you can see in the following image, axis labels overlap when parameter names are too long. I think we can solve this issue if we limit the maximum length of the labels and/or tilt the labels.

![newplot (39)](https://user-images.githubusercontent.com/3255979/66977250-19efd780-f0e0-11e9-87ba-a6616083da31.png)

**Conditions**
- Optuna version: 0.17.1
- Python version: 3.7.2
- OS: macOS 10.13

**Code to reproduce**

```python
import optuna

def objective(trial):
    x = trial.suggest_uniform('x' * 100, -10, 10)
    y = trial.suggest_uniform('y' * 100, -10, 10)
    return x - y

study = optuna.create_study()
study.optimize(objective, n_trials=20)

optuna.visualization.plot_parallel_coordinate(study)
```


Discussion:
FYI: `go.Parcoords` have a parameter `labelangle` in `line` option here.
https://github.com/pfnet/optuna/blob/master/optuna/visualization.py#L435-L443

Though the title overlaps with feature names, it can improve this visualization like below (this is the case when `labelangle=30`)
![image](https://user-images.githubusercontent.com/6898958/67848031-3d3a6e00-fb47-11e9-8e97-cfde9ab02232.png)


Resolving patch:
diff --git a/optuna/visualization/parallel_coordinate.py b/optuna/visualization/parallel_coordinate.py
--- a/optuna/visualization/parallel_coordinate.py
+++ b/optuna/visualization/parallel_coordinate.py
@@ -93,6 +93,7 @@ def _get_parallel_coordinate_plot(study, params=None):
             "range": (min([t.value for t in trials]), max([t.value for t in trials])),
         }
     ]  # type: List[Dict[str, Any]]
+
     for p_name in sorted_params:
         values = []
         for t in trials:
@@ -105,7 +106,11 @@ def _get_parallel_coordinate_plot(study, params=None):
             vocab = defaultdict(lambda: len(vocab))  # type: DefaultDict[str, int]
             values = [vocab[v] for v in values]
             is_categorical = True
-        dim = {"label": p_name, "values": tuple(values), "range": (min(values), max(values))}
+        dim = {
+            "label": p_name if len(p_name) < 20 else "{}...".format(p_name[:17]),
+            "values": tuple(values),
+            "range": (min(values), max(values)),
+        }  # type: Dict[str, object]
         if is_categorical:
             dim["tickvals"] = list(range(len(vocab)))
             dim["ticktext"] = list(sorted(vocab.items(), key=lambda x: x[1]))
@@ -114,6 +119,8 @@ def _get_parallel_coordinate_plot(study, params=None):
     traces = [
         go.Parcoords(
             dimensions=dims,
+            labelangle=30,
+            labelside="bottom",
             line={
                 "color": dims[0]["values"],
                 "colorscale": "blues",


Test patch:
Repository: optuna/optuna

Issue:
Order dependencies in `setup.py` alphabetically.
The libraries in `setup.py` are not arranged in alphabetical order. I think it would be helpful for developers if we fix it.

Examples:

https://github.com/optuna/optuna/blob/master/setup.py#L30-L41
```python
def get_install_requires() -> List[str]:

    return [
        'alembic',
        'cliff',
        'colorlog',
        'numpy',
        'scipy!=1.4.0',
        'sqlalchemy>=1.1.0',
        'tqdm',
        'joblib',
    ]
```

https://github.com/optuna/optuna/blob/master/setup.py#L61-L66
```python
        'doctest': [
            'pandas',
            'cma',
            'scikit-learn>=0.19.0',
            'plotly>=4.0.0',
        ],
```


Order dependencies in `setup.py` alphabetically.
The libraries in `setup.py` are not arranged in alphabetical order. I think it would be helpful for developers if we fix it.

Examples:

https://github.com/optuna/optuna/blob/master/setup.py#L30-L41
```python
def get_install_requires() -> List[str]:

    return [
        'alembic',
        'cliff',
        'colorlog',
        'numpy',
        'scipy!=1.4.0',
        'sqlalchemy>=1.1.0',
        'tqdm',
        'joblib',
    ]
```

https://github.com/optuna/optuna/blob/master/setup.py#L61-L66
```python
        'doctest': [
            'pandas',
            'cma',
            'scikit-learn>=0.19.0',
            'plotly>=4.0.0',
        ],
```




Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -33,11 +33,11 @@ def get_install_requires() -> List[str]:
         'alembic',
         'cliff',
         'colorlog',
+        'joblib',
         'numpy',
         'scipy!=1.4.0',
         'sqlalchemy>=1.1.0',
         'tqdm',
-        'joblib',
     ]
 
 
@@ -59,10 +59,10 @@ def get_extras_require() -> Dict[str, List[str]]:
             'pytest-cov',
         ],
         'doctest': [
-            'pandas',
             'cma',
-            'scikit-learn>=0.19.0',
+            'pandas',
             'plotly>=4.0.0',
+            'scikit-learn>=0.19.0',
             'scikit-optimize',
         ],
         'document': [


Test patch: