Skip to content

Commit

Permalink
Fix for Qiskit#2235
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanro committed Sep 18, 2024
1 parent e3a3b29 commit 12d85d7
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,29 @@ uint_t reorder_qubits(const reg_t &qubits, uint_t index) {
return new_index;
}

uint_t reorder_qubits_rev(const reg_t &qubits, uint_t index) {
uint_t new_index = 0;

int_t current_pos = 0, current_val = 0, new_pos = 0, shift = 0;
uint_t num_qubits = qubits.size();
for (uint_t i = 0; i < num_qubits; i++) {
current_pos = qubits[i];
current_val = 1ULL << current_pos;
new_pos = i;
shift = new_pos - current_pos;
if (index & current_val) {
if (shift > 0) {
new_index += current_val << shift;
} else if (shift < 0) {
new_index += current_val >> -shift;
} else {
new_index += current_val;
}
}
}
return new_index;
}

template <class vec_t>
void permute_all_qubits(const vec_t &orig_statevector,
const reg_t &input_qubits, const reg_t &output_qubits,
Expand Down Expand Up @@ -1350,7 +1373,7 @@ Vector<complex_t> MPS::get_amplitude_vector(const reg_t &base_values) {
// Since the qubits may not be ordered, we determine the actual index
// by the internal order of the qubits, to obtain the actual_base_value
uint_t actual_base_value =
reorder_qubits(qubit_ordering_.order_, base_values[i]);
reorder_qubits_rev(qubit_ordering_.order_, base_values[i]);
base_value = AER::Utils::int2string(actual_base_value);
amplitude_vector[i] = get_single_amplitude(base_value);
}
Expand Down

0 comments on commit 12d85d7

Please sign in to comment.