Skip to content

Commit 84a32fa

Browse files
first few signature changes, docstring adapted
1 parent 1e4aba1 commit 84a32fa

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

include/mqt-core/algorithms/StatePreparation.hpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,19 @@
1616

1717
namespace qc {
1818
/**
19-
* Prepares a generic Quantum State from a list of normalized complex
20-
amplitudes
21-
* Adapted implementation of Qiskit State Preparation:
19+
* @brief Prepares a generic quantum state from a list of normalized
20+
* complex amplitudes
2221
*
23-
https://github.com/Qiskit/qiskit/blob/main/qiskit/circuit/library/data_preparation/state_preparation.py#
24-
* based on paper:
25-
* Shende, Bullock, Markov. Synthesis of Quantum Logic Circuits (2004)
26-
[`https://ieeexplore.ieee.org/document/1629135`]
27-
* */
28-
29-
/**
30-
* @throws invalid_argument when amplitudes are not normalized or length not
31-
* power of 2
32-
* @param list of complex amplitudes to initialize to
33-
* @return MQT Circuit that initializes a state
34-
* */
22+
* Adapted implementation of IBM Qiskit's State Preparation:
23+
* https://github.com/Qiskit/qiskit/blob/e9ccd3f374fd5424214361d47febacfa5919e1e3/qiskit/circuit/library/data_preparation/state_preparation.py
24+
* based on the following paper:
25+
* V. V. Shende, S. S. Bullock and I. L. Markov, "Synthesis of quantum-logic circuits," in IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems, vol. 25, no. 6, pp. 1000-1010, June 2006, doi: 10.1109/TCAD.2005.855930.
26+
*
27+
* @param amplitudes state (vector) to prepare. Must be normalized and have a size that is a power of two
28+
* @return quantum computation that prepares the state
29+
* @throws invalid_argument @p amplitudes is not normalized or its length is not a
30+
* power of two
31+
**/
3532
[[nodiscard]] auto
3633
createStatePreparationCircuit(std::vector<std::complex<double>>& amplitudes)
3734
-> QuantumComputation;

src/algorithms/StatePreparation.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static const double EPS = 1e-10;
3131
namespace qc {
3232
using Matrix = std::vector<std::vector<double>>;
3333

34-
template <typename T> [[nodiscard]] auto twoNorm(std::vector<T> vec) -> double {
34+
template <typename T>
35+
[[nodiscard]] auto twoNorm(const std::vector<T>& vec) -> double {
3536
double norm = 0;
3637
for (auto elem : vec) {
3738
norm += std::norm(elem);
@@ -40,11 +41,12 @@ template <typename T> [[nodiscard]] auto twoNorm(std::vector<T> vec) -> double {
4041
}
4142

4243
template <typename T>
43-
[[nodiscard]] auto isNormalized(std::vector<T> vec) -> bool {
44+
[[nodiscard]] auto isNormalized(const std::vector<T>& vec) -> bool {
4445
return std::abs(1 - twoNorm(vec)) < EPS;
4546
}
4647

47-
[[nodiscard]] auto kroneckerProduct(Matrix matrixA, Matrix matrixB) -> Matrix {
48+
[[nodiscard]] auto kroneckerProduct(const Matrix& matrixA,
49+
const Matrix& matrixB) -> Matrix {
4850
size_t const rowA = matrixA.size();
4951
size_t const rowB = matrixB.size();
5052
size_t const colA = matrixA[0].size();
@@ -79,9 +81,9 @@ template <typename T>
7981
return identity;
8082
}
8183

82-
[[nodiscard]] auto matrixVectorProd(const Matrix& matrix,
83-
std::vector<double> vector)
84-
-> std::vector<double> {
84+
[[nodiscard]] auto
85+
matrixVectorProd(const Matrix& matrix,
86+
const std::vector<double>& vector) -> std::vector<double> {
8587
std::vector<double> result;
8688
for (const auto& matrixVec : matrix) {
8789
double sum{0};
@@ -150,7 +152,7 @@ template <typename T>
150152
multiplexer.cx(0, static_cast<Qubit>(localNumQubits - 1));
151153
}
152154

153-
CircuitOptimizer::flattenOperations(multiplexer, false);
155+
CircuitOptimizer::flattenOperations(multiplexer);
154156
return multiplexer;
155157
}
156158

@@ -195,8 +197,8 @@ rotationsToDisentangle(std::vector<std::complex<double>> amplitudes)
195197

196198
// creates circuit that takes desired vector to zero
197199
[[nodiscard]] auto
198-
gatesToUncompute(std::vector<std::complex<double>> amplitudes, size_t numQubits)
199-
-> QuantumComputation {
200+
gatesToUncompute(std::vector<std::complex<double>>& amplitudes,
201+
size_t numQubits) -> QuantumComputation {
200202
QuantumComputation disentangler{numQubits};
201203
for (size_t i = 0; i < numQubits; ++i) {
202204
// rotations to disentangle LSB
@@ -277,7 +279,7 @@ auto createStatePreparationCircuit(
277279
QuantumComputation toZeroCircuit = gatesToUncompute(amplitudes, numQubits);
278280

279281
// invert circuit
280-
CircuitOptimizer::flattenOperations(toZeroCircuit, false);
282+
CircuitOptimizer::flattenOperations(toZeroCircuit);
281283
toZeroCircuit.invert();
282284

283285
return toZeroCircuit;

0 commit comments

Comments
 (0)