LibKet - Kwantum Expression Template Library
The open-source expression template library LibKet makes it possible to develop quantum-accelerated scientific applications and test them on different gate-based quantum computing platforms like Quantum Inspire, IBM's Quantum Experience and Rigetti's Quantum Cloud Services without the need to reimplement quantum algorithms in vendor-specific SDKs like Qiskit and PyQuil. LibKet is designed as C++14 expression template library that allows to formulate quantum algorithms as generic expressions, which are synthesized to backend-optimized quantum kernels that can be executed in quantum simulators and cloud-based quantum computers. Next to the basic quantum gates, LibKet comes with a growing collection of customizable quantum algorithms and building blocks like the Quantum Fourier transformation that simplify the development of quantum-accelerated applications.
The following code snippet shows how to generate the quantum kernel for an n-qubit QFT and execute it first on the Quantum Inspire simulator platform using 6-qubits and then on IBM's Quantum Experience cloud service using one of the 5-qubit quantum processors. Beneath it the generated cQASM code and circuit is shown.
#include <LibKet.hpp>
using namespace LibKet;
using namespace LibKet::circuits;
using namespace LibKet::filters;
using namespace LibKet::gates;
// Create generic quantum expression
auto expr = qft(init());
// Execute QFT<6> on Quantum-Inspire platform
try {
QDevice<QDeviceType::qi_26_simulator, 6> qi; qi(expr);
utils::json result = qi.execute();
QInfo << result << std::endl;
QInfo << "job ID : " << qi.get<QResultType::id>(result) << std::endl;
QInfo << "time stamp : " << qi.get<QResultType::timestamp>(result) << std::endl;
QInfo << "duration : " << qi.get<QResultType::duration>(result).count() << std::endl;
QInfo << "best : " << qi.get<QResultType::best>(result) << std::endl;
QInfo << "histogram : " << qi.get<QResultType::histogram>(result) << std::endl;
} catch(const std::exception &e) {
QWarn << e.what() << std::endl;
}
// Execute QFT<5> on IBM Quantum Experience platform
try {
QDevice<QDeviceType::ibmq_5_london, 5> ibmq; ibmq(expr);
utils::json result = ibmq.execute();
QInfo << result << std::endl;
QInfo << "job ID : " << qi.get<QResultType::id>(result) << std::endl;
QInfo << "time stamp : " << qi.get<QResultType::timestamp>(result) << std::endl;
QInfo << "duration : " << qi.get<QResultType::duration>(result).count() << std::endl;
QInfo << "best : " << qi.get<QResultType::best>(result) << std::endl;
QInfo << "histogram : " << qi.get<QResultType::histogram>(result) << std::endl;
} catch(const std::exception &e) {
QWarn << e.what() << std::endl;
}
version 1.0
qubits 6
h q[0]
cr q[1], q[0], 1.570796326794896558
cr q[2], q[0], 0.785398163397448279
cr q[3], q[0], 0.392699081698724139
cr q[4], q[0], 0.196349540849362070
cr q[5], q[0], 0.098174770424681035
h q[1]
cr q[2], q[1], 1.570796326794896558
cr q[3], q[1], 0.785398163397448279
cr q[4], q[1], 0.392699081698724139
cr q[5], q[1], 0.196349540849362070
h q[2]
cr q[3], q[2], 1.570796326794896558
cr q[4], q[2], 0.785398163397448279
cr q[5], q[2], 0.392699081698724139
h q[3]
cr q[4], q[3], 1.570796326794896558
cr q[5], q[3], 0.785398163397448279
h q[4]
cr q[5], q[4], 1.570796326794896558
h q[5]
swap q[0], q[5]
swap q[1], q[4]
swap q[2], q[3]
measure q[0,1,2,3,4,5]
q[0] | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
q[1] | ||||||||||||||||||||||||||
q[2] | ||||||||||||||||||||||||||
q[3] | ||||||||||||||||||||||||||
q[4] | ||||||||||||||||||||||||||
q[5] |