Skip to content

Commit

Permalink
fixed equality check on floating point with bit manipulation
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
Signed-off-by: M-J-Hochreiter <77507116+M-J-Hochreiter@users.noreply.github.com>
  • Loading branch information
M-J-Hochreiter and burgholzer authored Jan 16, 2025
1 parent 9cbec23 commit c41302d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/algorithms/StatePreparation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,13 @@ auto createStatePreparationCircuit(
"Using State Preparation with Amplitudes that are not normalized"};
}

// get number of qubits needed
double const numQubits = std::log2(amplitudes.size());

if (std::abs(numQubits) < EPS || std::floor(numQubits) != numQubits) {
// check if the number of elements in the vector is a power of two
if (amplitudes.size() == 0 || (amplitudes.size() & (amplitudes.size() - 1)) != 0) {
throw std::invalid_argument{
"Using State Preparation with vector size that is not a power of 2"};
}

QuantumComputation toZeroCircuit =
gatesToUncompute(amplitudes, static_cast<size_t>(numQubits));
const auto numQubits = static_cast<size_t>(std::log2(amplitudes.size()));
QuantumComputation toZeroCircuit = gatesToUncompute(amplitudes, numQubits);

// invert circuit
CircuitOptimizer::flattenOperations(toZeroCircuit);
Expand Down

0 comments on commit c41302d

Please sign in to comment.