dimod
dimod copied to clipboard
Add a method for reordering the variables in a sample set
It would be good to have something like
reordered_sampleset = sampleset.reorder_variables(order)
Additional Context This can currently be done "manually"
# Get the samples as an unlabelled array, but with the columns ordered by variable_order
samples_array = sampleset.samples(sorted_by=None)[:, variable_order]
# Construct a new sampleset with that array and variable order, keeping everything else the
# same
reordered_sampleset = dimod.SampleSet.from_samples(
(samples_array, variable_order), # the samples array, with the new order
vartype=sampleset.vartype, # vartype is the same
sort_labels=False, # don't sort the labels
**sampleset.data_vectors, # energy, num_occurances, etc are all the same
)
but it might be nice to have it all bundled into a method
I second this, it would be great to have this so that pedagogical notebooks intended for youngsters such as this one (see the confusing reordering in cell Out [7]) do not have too complicated code.