fast-aircraft-design / FAST-OAD

FAST-OAD: An open source framework for rapid Overall Aircraft Design
GNU General Public License v3.0
51 stars 25 forks source link

Optimization viewer crashes #381

Closed christophe-david closed 2 years ago

christophe-david commented 3 years ago

Describe the bug With a fresh install of FAST-OAD (i.e. up-to-date packages), Optimization viewer cannot be displayed.

To Reproduce Run the tutorial notebook. When it comes to oad.optimization_viewer(CONFIGURATION_FILE), nothing is displayed and the following error message appears:

Error message

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/39/nj6qqdrj0fv10nzb969d6ktw0000gq/T/ipykernel_59335/1505126528.py in <module>
----> 1 oad.optimization_viewer(CONFIGURATION_FILE)

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/fastoad/cmd/api.py in optimization_viewer(configuration_file_path)
    471     viewer.load(conf)
    472 
--> 473     return viewer.display()
    474 
    475 

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/fastoad/gui/optimization_viewer.py in display(self)
    219         """
    220         self._create_save_load_buttons()
--> 221         return self._render_ui()
    222 
    223     def load_variables(self, variables: VariableList, attribute_to_column: Dict[str, str] = None):

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/fastoad/gui/optimization_viewer.py in _render_ui(self, change)
    440         """
    441         clear_output(wait=True)
--> 442         self._update_sheet()
    443         ui = widgets.VBox(
    444             [

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/fastoad/gui/optimization_viewer.py in _update_sheet(self)
    414         constraint_df = self.dataframe[self.dataframe["Type"] == "constraint"]
    415         constraint_df = constraint_df.drop(columns=["Type", "Initial Value"])
--> 416         self._constraint_sheet = self._df_to_sheet(constraint_df)
    417         objective_df = self.dataframe[self.dataframe["Type"] == "objective"]
    418         objective_df = objective_df.drop(columns=["Type", "Initial Value", "Lower", "Upper"])

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/fastoad/gui/optimization_viewer.py in _df_to_sheet(self, df)
    294 
    295                     cells.append(
--> 296                         sh.Cell(
    297                             value=value,
    298                             row_start=row_idx,

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in __init__(self, **kwargs)
    413 
    414         Widget._call_widget_constructed(self)
--> 415         self.open()
    416 
    417     def __del__(self):

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in open(self)
    436                 args['comm_id'] = self._model_id
    437 
--> 438             self.comm = Comm(**args)
    439 
    440     @observe('comm')

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/ipykernel/comm/comm.py in __init__(self, target_name, data, metadata, buffers, **kwargs)
     55             if self.primary:
     56                 # I am primary, open my peer.
---> 57                 self.open(data=data, metadata=metadata, buffers=buffers)
     58             else:
     59                 self._closed = False

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/ipykernel/comm/comm.py in open(self, data, metadata, buffers)
     89         comm_manager.register_comm(self)
     90         try:
---> 91             self._publish_msg('comm_open',
     92                               data=data, metadata=metadata, buffers=buffers,
     93                               target_name=self.target_name,

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/ipykernel/comm/comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
     64         metadata = {} if metadata is None else metadata
     65         content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
---> 66         self.kernel.session.send(self.kernel.iopub_socket, msg_type,
     67             content,
     68             metadata=json_clean(metadata),

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/jupyter_client/session.py in send(self, stream, msg_or_type, content, parent, ident, buffers, track, header, metadata)
    828         if self.adapt_version:
    829             msg = adapt(msg, self.adapt_version)
--> 830         to_send = self.serialize(msg, ident)
    831         to_send.extend(buffers)
    832         longest = max([len(s) for s in to_send])

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/jupyter_client/session.py in serialize(self, msg, ident)
    702             content = self.none
    703         elif isinstance(content, dict):
--> 704             content = self.pack(content)
    705         elif isinstance(content, bytes):
    706             # content is already packed, as in a relayed message

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/jupyter_client/session.py in json_packer(obj)
     93 
     94 def json_packer(obj):
---> 95     return jsonapi.dumps(
     96         obj,
     97         default=json_default,

~/PycharmProjects/FAST-OAD_test/.venv3.8/lib/python3.8/site-packages/zmq/utils/jsonapi.py in dumps(o, **kwargs)
     23     Keyword arguments are passed along to :py:func:`json.dumps`.
     24     """
---> 25     return json.dumps(o, **kwargs).encode("utf8")
     26 
     27 

~/.pyenv/versions/3.8.10/lib/python3.8/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    232     if cls is None:
    233         cls = JSONEncoder
--> 234     return cls(
    235         skipkeys=skipkeys, ensure_ascii=ensure_ascii,
    236         check_circular=check_circular, allow_nan=allow_nan, indent=indent,

~/.pyenv/versions/3.8.10/lib/python3.8/json/encoder.py in encode(self, o)
    197         # exceptions aren't as detailed.  The list call should be roughly
    198         # equivalent to the PySequence_Fast that ''.join() would do.
--> 199         chunks = self.iterencode(o, _one_shot=True)
    200         if not isinstance(chunks, (list, tuple)):
    201             chunks = list(chunks)

~/.pyenv/versions/3.8.10/lib/python3.8/json/encoder.py in iterencode(self, o, _one_shot)
    255                 self.key_separator, self.item_separator, self.sort_keys,
    256                 self.skipkeys, _one_shot)
--> 257         return _iterencode(o, 0)
    258 
    259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

ValueError: Out of range float values are not JSON compliant

Environment

christophe-david commented 3 years ago

The problem seems to happen since the version 7.x of jupyter-client. Downgrading it to 6.2 makes the optimization viewer functional again.

christophe-david commented 3 years ago

The problem seems to be about ipysheet, but I cannot see the root of the problem for now.

@ScottDelbecq, could you remind me of the possible alternative to ipysheet you mentioned some times ago ? 😅

ScottDelbecq commented 3 years ago

:( It was ipydatagrid!

christophe-david commented 3 years ago

Thanks. Looks good. Probably worth investigating, as it looks supported by some solid developer team.

For the record, I also bumped into QGrid, that has been very popular, but the project has been inactive for more than a year now, so we can safely discard it.