Commit bf32390f authored by Nguyen, Thien's avatar Nguyen, Thien

Used std::vector in Heterogeneous map in gate merge procedure

There is some potential compatibility issues with external linkage.
Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 4ea24ac6
......@@ -1296,6 +1296,22 @@ bool ZYZ::expand(const xacc::HeterogeneousMap& runtimeOptions)
{
unitary = runtimeOptions.get<Eigen::Matrix2cd>("unitary");
}
else if (runtimeOptions.keyExists<std::vector<std::complex<double>>>("unitary"))
{
auto matAsVec = runtimeOptions.get<std::vector<std::complex<double>>>("unitary");
// Correct size: 2 x 2
if (matAsVec.size() == 4)
{
for (int row = 0; row < 2; ++row)
{
for (int col = 0; col < 2; ++col)
{
// Expect row-by-row layout
unitary(row, col) = matAsVec[2*row + col];
}
}
}
}
else
{
xacc::error("unitary matrix is required.");
......
......@@ -72,10 +72,16 @@ void MergeSingleQubitGatesOptimizer::apply(std::shared_ptr<CompositeInstruction>
auto fuser = xacc::getService<xacc::quantum::GateFuser>("default");
fuser->initialize(tmpKernel);
const Eigen::Matrix2cd uMat = fuser->calcFusedGate(1);
Eigen::Matrix2cd uMat = fuser->calcFusedGate(1);
uMat.transposeInPlace();
Eigen::Vector4cd matAsVec(Eigen::Map<Eigen::Vector4cd>(uMat.data(), uMat.cols()*uMat.rows()));
std::vector<std::complex<double>> flattenedUnitary;
flattenedUnitary.resize(matAsVec.size());
Eigen::Vector4cd::Map(&flattenedUnitary[0], flattenedUnitary.size()) = matAsVec;
auto zyz = std::dynamic_pointer_cast<quantum::Circuit>(xacc::getService<Instruction>("z-y-z"));
const bool expandOk = zyz->expand({
std::make_pair("unitary", uMat)
std::make_pair("unitary", flattenedUnitary)
});
assert(expandOk);
// Optimized decomposed sequence:
......@@ -235,10 +241,15 @@ void MergeTwoQubitBlockOptimizer::apply(std::shared_ptr<CompositeInstruction> pr
}
auto fuser = xacc::getService<xacc::quantum::GateFuser>("default");
fuser->initialize(tmpKernel);
const Eigen::Matrix4cd uMat = fuser->calcFusedGate(2);
Eigen::Matrix4cd uMat = fuser->calcFusedGate(2);
uMat.transposeInPlace();
Eigen::VectorXcd matAsVec(Eigen::Map<Eigen::VectorXcd>(uMat.data(), uMat.cols()*uMat.rows()));
std::vector<std::complex<double>> flattenedUnitary;
flattenedUnitary.resize(matAsVec.size());
Eigen::VectorXcd::Map(&flattenedUnitary[0], flattenedUnitary.size()) = matAsVec;
auto kak = std::dynamic_pointer_cast<quantum::Circuit>(xacc::getService<Instruction>("kak"));
const bool expandOk = kak->expand({
std::make_pair("unitary", uMat)
std::make_pair("unitary", flattenedUnitary)
});
assert(expandOk);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment