Xopt icon indicating copy to clipboard operation
Xopt copied to clipboard

fixed AsynchronousXopt.to_json() and dump

Open ndwang opened this issue 5 months ago • 5 comments

I put in a fix for #234 and #235

The error is caused by duplicate indices in AsynchronousXopt.data.

When adding new data, Xopt.add_data() checks if self.data exists. If this is the first batch of data, keep the indices. If there are already data, reindex the new data and concatenate. https://github.com/xopt-org/Xopt/blob/7dc1b5c003dded6cde87bd61f965c3185be8ceeb/xopt/base.py#L379-L388

new_data.index starts from 0 in Xopt, however, in AsynchronousXopt it start from 1! This causes AsynchronousXopt.data to have two entries with index 1.

This index shift traces down to AsynchronousXopt.prepare_input_data() https://github.com/xopt-org/Xopt/blob/7dc1b5c003dded6cde87bd61f965c3185be8ceeb/xopt/asynchronous.py#L77-L80

It's not clear to me if this shift is required to manage futures. So my proposal is simply forcing Xopt.add_data() to always reindex the first batch to start from 0.

ndwang avatar Jul 23 '25 17:07 ndwang