Commit 0c1b782d authored by Daniel Claudino's avatar Daniel Claudino
Browse files

Changed qubit indexing in UCCSD ansatz


Signed-off-by: default avatarDaniel Claudino <6d3@ornl.gov>
parent 6703c3ea
import xacc import xacc
xacc.set_verbose(True) xacc.set_verbose(True)
opstr = '''(0.174073,0) Z2 Z3 + opstr = '''(0.174073,0) Z1 Z3 +
(0.1202,0) Z1 Z3 + (0.1202,0) Z2 Z3 +
(0.165607,0) Z1 Z2 + (0.165607,0) Z1 Z2 +
(0.165607,0) Z0 Z3 + (0.165607,0) Z0 Z3 +
(0.1202,0) Z0 Z2 + (0.1202,0) Z0 Z1 +
(-0.0454063,0) Y0 Y1 X2 X3 + (-0.0454063,0) Y0 Y2 X1 X3 +
(-0.220041,0) Z3 + (-0.220041,0) Z3 +
(-0.106477,0) + (-0.106477,0) +
(0.17028,0) Z0 + (0.17028,0) Z0 +
(-0.220041,0) Z2 + (-0.220041,0) Z1 +
(0.17028,0) Z1 + (0.17028,0) Z2 +
(-0.0454063,0) X0 X1 Y2 Y3 + (-0.0454063,0) X0 X2 Y1 Y3 +
(0.0454063,0) X0 Y1 Y2 X3 + (0.0454063,0) X0 Y2 Y1 X3 +
(0.168336,0) Z0 Z1 + (0.168336,0) Z0 Z2 +
(0.0454063,0) Y0 X1 X2 Y3''' (0.0454063,0) Y0 X2 X1 Y3'''
op = xacc.getObservable('pauli',opstr) op = xacc.getObservable('pauli',opstr)
...@@ -26,4 +26,4 @@ def ansatz_vqe(q, t0, t1): ...@@ -26,4 +26,4 @@ def ansatz_vqe(q, t0, t1):
print(ansatz_vqe.getCompositeInstruction().toString()) print(ansatz_vqe.getCompositeInstruction().toString())
buffer = xacc.qalloc(4) buffer = xacc.qalloc(4)
ansatz_vqe(buffer, 0.,0.) ansatz_vqe(buffer, 0.,0.)
\ No newline at end of file
...@@ -44,6 +44,7 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -44,6 +44,7 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
// Compute the number of parameters // Compute the number of parameters
auto _nOccupied = (int)std::ceil(nElectrons / 2.0); auto _nOccupied = (int)std::ceil(nElectrons / 2.0);
auto _nVirtual = nQubits / 2 - _nOccupied; auto _nVirtual = nQubits / 2 - _nOccupied;
auto _nOrbitals = _nOccupied + _nVirtual;
auto nSingle = _nOccupied * _nVirtual; auto nSingle = _nOccupied * _nVirtual;
auto nDouble = nSingle * (nSingle + 1) / 2; auto nDouble = nSingle * (nSingle + 1) / 2;
auto _nParameters = nSingle + nDouble; auto _nParameters = nSingle + nDouble;
...@@ -80,8 +81,8 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -80,8 +81,8 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto singleParams = slice(params, 0, nSingle); auto singleParams = slice(params, 0, nSingle);
auto doubleParams1 = slice(params, nSingle, 2 * nSingle); auto doubleParams1 = slice(params, nSingle, 2 * nSingle);
auto doubleParams2 = slice(params, 2 * nSingle); auto doubleParams2 = slice(params, 2 * nSingle);
std::vector<std::function<int(int)>> fs{[](int i) { return 2 * i; }, std::vector<std::function<int(int, int)>> fs{[](int i, int n) { return i; },
[](int i) { return 2 * i + 1; }}; [](int i, int n) { return i + n; }};
using OpType = std::vector<std::pair<int, bool>>; using OpType = std::vector<std::pair<int, bool>>;
int count = 0; int count = 0;
...@@ -94,10 +95,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -94,10 +95,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
for (int s = 0; s < 2; s++) { for (int s = 0; s < 2; s++) {
auto ti = fs[s]; auto ti = fs[s];
auto oi = fs[1 - s]; auto oi = fs[1 - s];
auto vt = ti(vs); auto vt = ti(vs, _nOrbitals);
auto vo = oi(vs); auto vo = oi(vs, _nOrbitals);
auto ot = ti(os); auto ot = ti(os, _nOrbitals);
auto oo = oi(os); auto oo = oi(os, _nOrbitals);
OpType op1{{vt, 1}, {ot, 0}}, op2{{ot, 1}, {vt, 0}}; OpType op1{{vt, 1}, {ot, 0}}, op2{{ot, 1}, {vt, 0}};
FermionOperator op(op1, 1.0, singleParams[count]); FermionOperator op(op1, 1.0, singleParams[count]);
...@@ -152,10 +153,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -152,10 +153,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto ia = fs[sa]; auto ia = fs[sa];
auto ib = fs[sb]; auto ib = fs[sb];
auto v1a = ia(vs1); auto v1a = ia(vs1, _nOrbitals);
auto o1a = ia(os1); auto o1a = ia(os1, _nOrbitals);
auto v2b = ib(vs2); auto v2b = ib(vs2, _nOrbitals);
auto o2b = ib(os2); auto o2b = ib(os2, _nOrbitals);
OpType op5{{v1a, 1}, {o1a, 0}, {v2b, 1}, {o2b, 0}}, OpType op5{{v1a, 1}, {o1a, 0}, {v2b, 1}, {o2b, 0}},
op6{{o2b, 1}, {o1a, 0}, {v2b, 1}, {o2b, 0}}; op6{{o2b, 1}, {o1a, 0}, {v2b, 1}, {o2b, 0}};
...@@ -268,10 +269,14 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -268,10 +269,14 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
} }
} }
for (int i = nElectrons - 1; i >= 0; i--) { for (int i = (nElectrons / 2) - 1; i >= 0; i--) {
std::size_t j = (std::size_t)i; std::size_t alpha = (std::size_t)i;
auto xGate = auto xGate =
gateRegistry->createInstruction("X", std::vector<std::size_t>{j}); gateRegistry->createInstruction("X", std::vector<std::size_t>{alpha});
insertInstruction(0, xGate);
std::size_t beta = (std::size_t)(i + _nOrbitals);
xGate =
gateRegistry->createInstruction("X", std::vector<std::size_t>{beta});
insertInstruction(0, xGate); insertInstruction(0, xGate);
} }
return true; return true;
......
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