Unverified Commit 2e602b89 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #203 from danclaudino/indexing

Changed qubit indexing in UCCSD ansatz
parents dc18c50c 0c1b782d
import xacc
xacc.set_verbose(True)
opstr = '''(0.174073,0) Z2 Z3 +
(0.1202,0) Z1 Z3 +
opstr = '''(0.174073,0) Z1 Z3 +
(0.1202,0) Z2 Z3 +
(0.165607,0) Z1 Z2 +
(0.165607,0) Z0 Z3 +
(0.1202,0) Z0 Z2 +
(-0.0454063,0) Y0 Y1 X2 X3 +
(0.1202,0) Z0 Z1 +
(-0.0454063,0) Y0 Y2 X1 X3 +
(-0.220041,0) Z3 +
(-0.106477,0) +
(0.17028,0) Z0 +
(-0.220041,0) Z2 +
(0.17028,0) Z1 +
(-0.0454063,0) X0 X1 Y2 Y3 +
(0.0454063,0) X0 Y1 Y2 X3 +
(0.168336,0) Z0 Z1 +
(0.0454063,0) Y0 X1 X2 Y3'''
(-0.220041,0) Z1 +
(0.17028,0) Z2 +
(-0.0454063,0) X0 X2 Y1 Y3 +
(0.0454063,0) X0 Y2 Y1 X3 +
(0.168336,0) Z0 Z2 +
(0.0454063,0) Y0 X2 X1 Y3'''
op = xacc.getObservable('pauli',opstr)
......
......@@ -44,6 +44,7 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
// Compute the number of parameters
auto _nOccupied = (int)std::ceil(nElectrons / 2.0);
auto _nVirtual = nQubits / 2 - _nOccupied;
auto _nOrbitals = _nOccupied + _nVirtual;
auto nSingle = _nOccupied * _nVirtual;
auto nDouble = nSingle * (nSingle + 1) / 2;
auto _nParameters = nSingle + nDouble;
......@@ -80,8 +81,8 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto singleParams = slice(params, 0, nSingle);
auto doubleParams1 = slice(params, nSingle, 2 * nSingle);
auto doubleParams2 = slice(params, 2 * nSingle);
std::vector<std::function<int(int)>> fs{[](int i) { return 2 * i; },
[](int i) { return 2 * i + 1; }};
std::vector<std::function<int(int, int)>> fs{[](int i, int n) { return i; },
[](int i, int n) { return i + n; }};
using OpType = std::vector<std::pair<int, bool>>;
int count = 0;
......@@ -94,10 +95,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
for (int s = 0; s < 2; s++) {
auto ti = fs[s];
auto oi = fs[1 - s];
auto vt = ti(vs);
auto vo = oi(vs);
auto ot = ti(os);
auto oo = oi(os);
auto vt = ti(vs, _nOrbitals);
auto vo = oi(vs, _nOrbitals);
auto ot = ti(os, _nOrbitals);
auto oo = oi(os, _nOrbitals);
OpType op1{{vt, 1}, {ot, 0}}, op2{{ot, 1}, {vt, 0}};
FermionOperator op(op1, 1.0, singleParams[count]);
......@@ -152,10 +153,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto ia = fs[sa];
auto ib = fs[sb];
auto v1a = ia(vs1);
auto o1a = ia(os1);
auto v2b = ib(vs2);
auto o2b = ib(os2);
auto v1a = ia(vs1, _nOrbitals);
auto o1a = ia(os1, _nOrbitals);
auto v2b = ib(vs2, _nOrbitals);
auto o2b = ib(os2, _nOrbitals);
OpType op5{{v1a, 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) {
}
}
for (int i = nElectrons - 1; i >= 0; i--) {
std::size_t j = (std::size_t)i;
for (int i = (nElectrons / 2) - 1; i >= 0; i--) {
std::size_t alpha = (std::size_t)i;
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);
}
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