Skip to content

Commit

Permalink
Added QEOM entry to manual
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Claudino <[email protected]>
  • Loading branch information
danclaudino committed Dec 11, 2020
1 parent 649966d commit 91e97b5
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 1 deletion.
161 changes: 161 additions & 0 deletions docs/source/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,167 @@ In Python:
qcmx.execute(buffer)
QEOM
++++
The Quantum Equation of Motion (QEOM) Algorithm requires the following input information:
(`Ollitrault et al (2020) <https://arxiv.org/abs/1910.12890>`_)

+------------------------+------------------------------------------------------+------------------------------------------+
| Algorithm Parameter | Parameter Description | type |
+========================+======================================================+==========================================+
| observable | The hermitian operator represents the Hamiltonian | std::shared_ptr<Observable> |
+------------------------+------------------------------------------------------+------------------------------------------+
| accelerator | The Accelerator backend to target | std::shared_ptr<Accelerator> |
+------------------------+------------------------------------------------------+------------------------------------------+
| ansatz | State preparation circuit | std::shared_ptr<CompositeInstruction> |
+------------------------+------------------------------------------------------+------------------------------------------+
| n-occupied | The number of occupied orbitals | int |
+------------------------+------------------------------------------------------+------------------------------------------+
| n-virtual | The number of virtual orbitals | int |
+------------------------+------------------------------------------------------+------------------------------------------+
| operators | Excitation operators | std::vector<std::shared_ptr<Observable>> |
+------------------------+------------------------------------------------------+------------------------------------------+

Please note that the algorithm requires either both ``n-occupied`` and ``n-virtual`` or ``operators``. In the former case, it will default to single and double excitation operators.

.. code:: cpp
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "Algorithm.hpp"
#include "xacc_observable.hpp"
#include "OperatorPool.hpp"
int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
// Get reference to the Accelerator
// specified by --accelerator argument
auto accelerator = xacc::getAccelerator("qpp");
// Allocate 4 qubits in the buffer
auto buffer = xacc::qalloc(4);
// Get reference to the Hamiltonian
// specified by the --observable argument
auto str = std::string(
"(-0.165606823582,-0) 1^ 2^ 1 2 + (0.120200490713,0) 1^ 0^ 0 1 + "
"(-0.0454063328691,-0) 0^ 3^ 1 2 + (0.168335986252,0) 2^ 0^ 0 2 + "
"(0.0454063328691,0) 1^ 2^ 3 0 + (0.168335986252,0) 0^ 2^ 2 0 + "
"(0.165606823582,0) 0^ 3^ 3 0 + (-0.0454063328691,-0) 3^ 0^ 2 1 + "
"(-0.0454063328691,-0) 1^ 3^ 0 2 + (-0.0454063328691,-0) 3^ 1^ 2 0 + "
"(0.165606823582,0) 1^ 2^ 2 1 + (-0.165606823582,-0) 0^ 3^ 0 3 + "
"(-0.479677813134,-0) 3^ 3 + (-0.0454063328691,-0) 1^ 2^ 0 3 + "
"(-0.174072892497,-0) 1^ 3^ 1 3 + (-0.0454063328691,-0) 0^ 2^ 1 3 + "
"(0.120200490713,0) 0^ 1^ 1 0 + (0.0454063328691,0) 0^ 2^ 3 1 + "
"(0.174072892497,0) 1^ 3^ 3 1 + (0.165606823582,0) 2^ 1^ 1 2 + "
"(-0.0454063328691,-0) 2^ 1^ 3 0 + (-0.120200490713,-0) 2^ 3^ 2 3 + "
"(0.120200490713,0) 2^ 3^ 3 2 + (-0.168335986252,-0) 0^ 2^ 0 2 + "
"(0.120200490713,0) 3^ 2^ 2 3 + (-0.120200490713,-0) 3^ 2^ 3 2 + "
"(0.0454063328691,0) 1^ 3^ 2 0 + (-1.2488468038,-0) 0^ 0 + "
"(0.0454063328691,0) 3^ 1^ 0 2 + (-0.168335986252,-0) 2^ 0^ 2 0 + "
"(0.165606823582,0) 3^ 0^ 0 3 + (-0.0454063328691,-0) 2^ 0^ 3 1 + "
"(0.0454063328691,0) 2^ 0^ 1 3 + (-1.2488468038,-0) 2^ 2 + "
"(0.0454063328691,0) 2^ 1^ 0 3 + (0.174072892497,0) 3^ 1^ 1 3 + "
"(-0.479677813134,-0) 1^ 1 + (-0.174072892497,-0) 3^ 1^ 3 1 + "
"(0.0454063328691,0) 3^ 0^ 1 2 + (-0.165606823582,-0) 3^ 0^ 3 0 + "
"(0.0454063328691,0) 0^ 3^ 2 1 + (-0.165606823582,-0) 2^ 1^ 2 1 + "
"(-0.120200490713,-0) 0^ 1^ 0 1 + (-0.120200490713,-0) 1^ 0^ 1 0 + "
"(0.7080240981,0)");
auto H = xacc::quantum::getObservable("fermion", str);
// Create reference to the initial state
// specified by the --ansatz argument
auto pool = xacc::getService<OperatorPool>("singlet-adapted-uccsd");
pool->optionalParameters({{"n-electrons", 2}});
pool->generate(buffer->size());
auto ansatz = xacc::getIRProvider("quantum")->createComposite("ansatz");
ansatz->addInstruction(
xacc::getIRProvider("quantum")->createInstruction("X", {0}));
ansatz->addInstruction(
xacc::getIRProvider("quantum")->createInstruction("X", {2}));
ansatz->addVariable("x0");
for (auto &inst : pool->getOperatorInstructions(2, 0)->getInstructions()) {
ansatz->addInstruction(inst);
}
auto kernel = ansatz->operator()({0.0808});
// Instantiate the QEOM algorithm
auto qeom = xacc::getAlgorithm("qeom");
// Pass parameters to QEOM algorithm
qeom->initialize({{"accelerator",accelerator},
{"observable", H},
{"ansatz", kernel},
{"n-occupied", 1},
{"n-virtual", 1}});
// Execute QEOM
qeom->execute(buffer);
xacc::Finalize();
return 0;
}
In Python:

.. code:: python
import xacc
accelerator = xacc.getAccelerator("qpp")
buffer = xacc.qalloc(4)
opstr = '''
(-0.165606823582,-0) 1^ 2^ 1 2 + (0.120200490713,0) 1^ 0^ 0 1 +
(-0.0454063328691,-0) 0^ 3^ 1 2 + (0.168335986252,0) 2^ 0^ 0 2 +
(0.0454063328691,0) 1^ 2^ 3 0 + (0.168335986252,0) 0^ 2^ 2 0 +
(0.165606823582,0) 0^ 3^ 3 0 + (-0.0454063328691,-0) 3^ 0^ 2 1 +
(-0.0454063328691,-0) 1^ 3^ 0 2 + (-0.0454063328691,-0) 3^ 1^ 2 0 +
(0.165606823582,0) 1^ 2^ 2 1 + (-0.165606823582,-0) 0^ 3^ 0 3 +
(-0.479677813134,-0) 3^ 3 + (-0.0454063328691,-0) 1^ 2^ 0 3 +
(-0.174072892497,-0) 1^ 3^ 1 3 + (-0.0454063328691,-0) 0^ 2^ 1 3 +
(0.120200490713,0) 0^ 1^ 1 0 + (0.0454063328691,0) 0^ 2^ 3 1 +
(0.174072892497,0) 1^ 3^ 3 1 + (0.165606823582,0) 2^ 1^ 1 2 +
(-0.0454063328691,-0) 2^ 1^ 3 0 + (-0.120200490713,-0) 2^ 3^ 2 3 +
(0.120200490713,0) 2^ 3^ 3 2 + (-0.168335986252,-0) 0^ 2^ 0 2 +
(0.120200490713,0) 3^ 2^ 2 3 + (-0.120200490713,-0) 3^ 2^ 3 2 +
(0.0454063328691,0) 1^ 3^ 2 0 + (-1.2488468038,-0) 0^ 0 +
(0.0454063328691,0) 3^ 1^ 0 2 + (-0.168335986252,-0) 2^ 0^ 2 0 +
(0.165606823582,0) 3^ 0^ 0 3 + (-0.0454063328691,-0) 2^ 0^ 3 1 +
(0.0454063328691,0) 2^ 0^ 1 3 + (-1.2488468038,-0) 2^ 2 +
(0.0454063328691,0) 2^ 1^ 0 3 + (0.174072892497,0) 3^ 1^ 1 3 +
(-0.479677813134,-0) 1^ 1 + (-0.174072892497,-0) 3^ 1^ 3 1 +
(0.0454063328691,0) 3^ 0^ 1 2 + (-0.165606823582,-0) 3^ 0^ 3 0 +
(0.0454063328691,0) 0^ 3^ 2 1 + (-0.165606823582,-0) 2^ 1^ 2 1 +
(-0.120200490713,-0) 0^ 1^ 0 1 + (-0.120200490713,-0) 1^ 0^ 1 0 + (0.7080240981,0)
'''
H = xacc.getObservable('fermion', opstr)
pool = xacc.quantum.getOperatorPool("singlet-adapted-uccsd")
pool.optionalParameters({"n-electrons": 2})
pool.generate(buffer.size())
provider = xacc.getIRProvider('quantum')
ansatz = provider.createComposite('initial-state')
ansatz.addInstruction(provider.createInstruction('X', [0]))
ansatz.addInstruction(provider.createInstruction('X', [2]))
ansatz.addVariable("x0")
for inst in pool.getOperatorInstructions(2, 0).getInstructions():
ansatz.addInstruction(inst)
kernel = ansatz.eval([0.0808])
qeom = xacc.getAlgorithm('qeom', {
'accelerator': accelerator,
'observable': H,
'ansatz': kernel,
'n-occupied': 1,
'n-virtual': 1
})
qeom.execute(buffer)
Accelerator Decorators
----------------------
ROErrorDecorator
Expand Down
2 changes: 1 addition & 1 deletion quantum/plugins/algorithms/qeom/tests/qEOMTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(qEOMTester, checkqEOM) {

auto pool = xacc::getService<OperatorPool>("singlet-adapted-uccsd");
pool->optionalParameters({{"n-electrons", 2}});
auto xd = pool->generate(buffer->size());
pool->generate(buffer->size());
auto ansatz = xacc::getIRProvider("quantum")->createComposite("ansatz");
ansatz->addInstruction(
xacc::getIRProvider("quantum")->createInstruction("X", {0}));
Expand Down

0 comments on commit 91e97b5

Please sign in to comment.