Commit 11b667fa authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Merge branch 'zach_vqe' into xacc-devel

parents 38cc51c5 9616680b
...@@ -52,3 +52,6 @@ install(TARGETS _pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX}) ...@@ -52,3 +52,6 @@ install(TARGETS _pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES xacc.py DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES xacc.py DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY plugin_generator DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY plugin_generator DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY benchmark DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY benchmark DESTINATION ${CMAKE_INSTALL_PREFIX})
file(GLOB PYDECORATORS ${CMAKE_CURRENT_SOURCE_DIR}/benchmark/vqe/*.py)
install(FILES ${PYDECORATORS} DESTINATION ${CMAKE_INSTALL_PREFIX}/py-plugins)
...@@ -38,7 +38,7 @@ def install_package(install_name): ...@@ -38,7 +38,7 @@ def install_package(install_name):
xacc.info("Retrieving package and checking requirements..") xacc.info("Retrieving package and checking requirements..")
package_path = PLUGIN_INSTALLATIONS[install_name] package_path = PLUGIN_INSTALLATIONS[install_name]
for k,v in MASTER_PACKAGES.items(): for k,v in MASTER_PACKAGES.items():
if install_name in v: if install_name in v and k in REQUIREMENTS:
requirement = REQUIREMENTS[k]['module'] requirement = REQUIREMENTS[k]['module']
mdir = k mdir = k
importlib.import_module(requirement) importlib.import_module(requirement)
...@@ -118,7 +118,6 @@ def get_packages(): ...@@ -118,7 +118,6 @@ def get_packages():
def main(argv=None): def main(argv=None):
opts = parse_args(sys.argv[1:]) opts = parse_args(sys.argv[1:])
get_packages() get_packages()
if opts.path: if opts.path:
set_plugin_path(opts.path) set_plugin_path(opts.path)
......
from abc import abstractmethod, ABC
class AnsatzGenerator(ABC):
"""
Abstract class to be inherited by iPOPO bundles to generate quantum circuit ansatz for quantum computation
Subclasses must inherit and implement the generate() method to return an XACC Intermediate Representation (IR) Function instance which expresses
a composition of instructions to be executed
"""
@abstractmethod
def generate(self, inputParams):
pass
...@@ -2,7 +2,6 @@ from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provide ...@@ -2,7 +2,6 @@ from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provide
Validate, Invalidate, Instantiate Validate, Invalidate, Instantiate
from hamiltonian_generator import HamiltonianGenerator from hamiltonian_generator import HamiltonianGenerator
import ast, xacc import ast, xacc
import xaccvqe as vqe
@ComponentFactory("xaccKernelH2_hamiltonian_generator_factory") @ComponentFactory("xaccKernelH2_hamiltonian_generator_factory")
...@@ -18,36 +17,34 @@ class XACCKernelH2(HamiltonianGenerator): ...@@ -18,36 +17,34 @@ class XACCKernelH2(HamiltonianGenerator):
""" """
def generate(self, inputParams): def generate(self, inputParams):
src = """__qpu__ kernel() { src = """0.7080240949826064
0.7080240949826064 - 1.248846801817026 0^ 0
-1.248846801817026 0 1 0 0 - 1.248846801817026 1^ 1
-1.248846801817026 1 1 1 0 - 0.4796778151607899 2^ 2
-0.4796778151607899 2 1 2 0 - 0.4796778151607899 3^ 3
-0.4796778151607899 3 1 3 0 + 0.33667197218932576 0^ 1^ 1 0
0.33667197218932576 0 1 1 1 1 0 0 0 + 0.0908126658307406 0^ 1^ 3 2
0.0908126658307406 0 1 1 1 3 0 2 0 + 0.09081266583074038 0^ 2^ 0 2
0.09081266583074038 0 1 2 1 0 0 2 0 + 0.331213646878486 0^ 2^ 2 0
0.331213646878486 0 1 2 1 2 0 0 0 + 0.09081266583074038 0^ 3^ 1 2
0.09081266583074038 0 1 3 1 1 0 2 0 + 0.331213646878486 0^ 3^ 3 0
0.331213646878486 0 1 3 1 3 0 0 0 + 0.33667197218932576 1^ 0^ 0 1
0.33667197218932576 1 1 0 1 0 0 1 0 + 0.0908126658307406 1^ 0^ 2 3
0.0908126658307406 1 1 0 1 2 0 3 0 + 0.09081266583074038 1^ 2^ 0 3
0.09081266583074038 1 1 2 1 0 0 3 0 + 0.331213646878486 1^ 2^ 2 1
0.331213646878486 1 1 2 1 2 0 1 0 + 0.09081266583074038 1^ 3^ 1 3
0.09081266583074038 1 1 3 1 1 0 3 0 + 0.331213646878486 1^ 3^ 3 1
0.331213646878486 1 1 3 1 3 0 1 0 + 0.331213646878486 2^ 0^ 0 2
0.331213646878486 2 1 0 1 0 0 2 0 + 0.09081266583074052 2^ 0^ 2 0
0.09081266583074052 2 1 0 1 2 0 0 0 + 0.331213646878486 2^ 1^ 1 2
0.331213646878486 2 1 1 1 1 0 2 0 + 0.09081266583074052 2^ 1^ 3 0
0.09081266583074052 2 1 1 1 3 0 0 0 + 0.09081266583074048 2^ 3^ 1 0
0.09081266583074048 2 1 3 1 1 0 0 0 + 0.34814578469185886 2^ 3^ 3 2
0.34814578469185886 2 1 3 1 3 0 2 0 + 0.331213646878486 3^ 0^ 0 3
0.331213646878486 3 1 0 1 0 0 3 0 + 0.09081266583074052 3^ 0^ 2 1
0.09081266583074052 3 1 0 1 2 0 1 0 + 0.331213646878486 3^ 1^ 1 3
0.331213646878486 3 1 1 1 1 0 3 0 + 0.09081266583074052 3^ 1^ 3 1
0.09081266583074052 3 1 1 1 3 0 1 0 + 0.09081266583074048 3^ 2^ 0 1
0.09081266583074048 3 1 2 1 0 0 1 0 + 0.34814578469185886 3^ 2^ 2 3"""
0.34814578469185886 3 1 2 1 2 0 3 0
}"""
inputParams['rdm-source'] = src inputParams['rdm-source'] = src
return vqe.compile(src) return xacc.getObservable('fermion', src)
...@@ -2,9 +2,6 @@ from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provide ...@@ -2,9 +2,6 @@ from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provide
Validate, Invalidate, Instantiate Validate, Invalidate, Instantiate
from hamiltonian_generator import HamiltonianGenerator from hamiltonian_generator import HamiltonianGenerator
import ast, xacc import ast, xacc
import xaccvqe as vqe
from xaccvqe import PauliOperator
@ComponentFactory("rbh_4q_sto3g_hamiltonian_generator_factory") @ComponentFactory("rbh_4q_sto3g_hamiltonian_generator_factory")
@Provides("hamiltonian_generator") @Provides("hamiltonian_generator")
......
...@@ -3,7 +3,7 @@ from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provide ...@@ -3,7 +3,7 @@ from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provide
from frozencore import FrozenCoreHamiltonian from frozencore import FrozenCoreHamiltonian
import xacc import xacc
from xaccvqe import PauliOperator from xacc import PauliOperator
@ComponentFactory("taperedfrozencore_hamiltonian_generator_factory") @ComponentFactory("taperedfrozencore_hamiltonian_generator_factory")
@Provides("hamiltonian_generator") @Provides("hamiltonian_generator")
......
from abc import abstractmethod, ABC
class HamiltonianGenerator(ABC):
"""
Abstract class to be inherited by iPOPO bundles to generate a Hamiltonian for quantum computation
Subclasses must inherit and implement the generate() method to return an XACC-VQE PauliOperator
"""
@abstractmethod
def generate(self, data):
pass
...@@ -7,10 +7,3 @@ chemistry: /chemistry ...@@ -7,10 +7,3 @@ chemistry: /chemistry
chem-hams: /chemistry/hamiltonian_generators chem-hams: /chemistry/hamiltonian_generators
chem-ansatze: /chemistry/ansatz_generators chem-ansatze: /chemistry/ansatz_generators
[Requirements]
# Put the master dir name (VQE) and any requirement info for
# the Python module required to use the plugins
vqe: {"module": "xaccvqe",
"repo": "https://github.com/ornl-qci/xacc-vqe.git",
"dir": "xacc-vqe"}
\ No newline at end of file
from pelix.ipopo.decorators import (ComponentFactory, Property, Instantiate)
import ast
import xacc
from xacc import BenchmarkAlgorithm
from vqe_base import VQEBase
@ComponentFactory("vqe_benchmark_factory")
@Property("_name", "name", "vqe")
@Instantiate("vqe_benchmark")
class VQE(VQEBase):
"""
Algorithm class inherited from VQEBase to execute the VQE algorithm
"""
def __init__(self):
super().__init__()
def execute(self, inputParams):
"""
Inherited method with algorithm-specific implementation
Parameters:
inputParams - a dictionary of input parameters obtained from .ini file
"""
super().execute(inputParams)
# self.vqe_options_dict['task'] = 'vqe'
# if self.optimizer is not None:
# self.optimizer.optimize(self.op, self.buffer, self.optimizer_options, self.vqe_options_dict)
# else:
execParams = {'accelerator': self.qpu, 'ansatz': self.ansatz, 'observable': self.op, 'optimizer':self.optimizer}
vqe = xacc.getAlgorithm('vqe', execParams)
vqe.execute(self.buffer)
return self.buffer
def analyze(self, buffer, inputParams):
super().analyze(buffer, inputParams)
from xacc import BenchmarkAlgorithm
import xacc
import ast
import time
import os
from pelix.ipopo.decorators import (Provides, Requires, BindField, UnbindField)
#
# VQEBase is an abstract class that implements the VQE algorithm using XACC.
# VQE and VQEEnergy are iPOPO bundles that inherit from this class to execute the algorithm and analyze results.
#
# Methods:
# bind_dicts - Required for using iPOPO service registry
# unbind_dicts - Required for using iPOPO service registry
# execute - executes the VQE algorithm according to input configurations
# analyze - analyzes the AcceleratorBuffer produced from execute()
@Provides("benchmark_algorithm")
@Requires("_ansatz_generators", "ansatz_generator", aggregate=True)
@Requires("_hamiltonian_generators", "hamiltonian_generator", aggregate=True)
@Requires("_vqe_optimizers", "vqe_optimization", aggregate=True, optional=True)
class VQEBase(BenchmarkAlgorithm):
def __init__(self):
self.hamiltonian_generators = {}
self.ansatz_generators = {}
self.vqe_optimizers = {}
self.vqe_options_dict = {}
self.n_qubits = 0
self.buffer = None
self.ansatz = None
self.op = None
self.qpu = None
@BindField('_vqe_optimizers')
@BindField('_ansatz_generators')
@BindField('_hamiltonian_generators')
def bind_dicts(self, field, service, svc_ref):
"""
This method is intended to be inherited by iPOPO bundle subclasses.
Binds the service references of the available molecule and ansatz generators.
"""
if svc_ref.get_property('hamiltonian_generator'):
generator = svc_ref.get_property('hamiltonian_generator')
self.hamiltonian_generators[generator] = service
if svc_ref.get_property('ansatz_generator'):
generator = svc_ref.get_property('ansatz_generator')
self.ansatz_generators[generator] = service
if svc_ref.get_property('vqe_optimizer'):
optimizer = svc_ref.get_property('vqe_optimizer')
self.vqe_optimizers[optimizer] = service
@UnbindField("_vqe_optimizers")
@UnbindField('_ansatz_generators')
@UnbindField('_hamiltonian_generators')
def unbind_dicts(self, field, service, svc_ref):
"""
This method is intended to be inherited by iPOPO bundle subclasses.
Unbinds the service references of the available molecule and ansatz generators when the instance is killed
"""
if svc_ref.get_property('hamiltonian_generator'):
generator = svc_ref.get_property('hamiltonian_generator')
del self.hamiltonian_generators[generator]
if svc_ref.get_property('ansatz_generator'):
generator = svc_ref.get_property('ansatz_generator')
del self.ansatz_generators[generator]
if svc_ref.get_property('vqe_optimizer'):
optimizer = svc_ref.get_property('vqe_optimizer')
del self.vqe_optimizers[optimizer]
def execute(self, inputParams):
"""
This method is intended to be inherited by vqe and vqe_energy subclasses to allow algorithm-specific implementation.
This superclass method adds extra information to the buffer and allows XACC settings options to be set before executing VQE.
Parameters:
inputParams : dictionary
a dictionary of input parameters obtained from .ini file
return QPU Accelerator buffer
Options used (obtained from inputParams):
'qubit-map': map of logical qubits to physical qubits
'n-execs': number of sampler executions of measurements
'initial-parameters': list of initial parameters for the VQE algorithm
'restart-from-file': AcceleratorDecorator option to allow restart of VQE algorithm
'readout-error': AcceleratorDecorator option for readout-error mitigation
"""
self.qpu = xacc.getAccelerator(inputParams['accelerator'])
xaccOp = self.hamiltonian_generators[inputParams['hamiltonian-generator']].generate(
inputParams)
self.ansatz = self.ansatz_generators[inputParams['name']].generate(
inputParams, xaccOp.nBits())
if 'qubit-map' in inputParams:
qubit_map = ast.literal_eval(inputParams['qubit-map'])
xaccOp, self.ansatz, n_qubits = xaccvqe.mapToPhysicalQubits(
xaccOp, self.ansatz, qubit_map)
else:
n_qubits = xaccOp.nBits()
self.op = xaccOp
self.n_qubits = n_qubits
self.buffer = self.qpu.createBuffer('q', n_qubits)
self.buffer.addExtraInfo('hamiltonian', str(xaccOp))
self.buffer.addExtraInfo('ansatz-qasm', self.ansatz.toString('q').replace('\\n', '\\\\n'))
pycompiler = xacc.getCompiler('xacc-py')
self.buffer.addExtraInfo('ansatz-qasm-py', '\n'.join(pycompiler.translate('q',self.ansatz).split('\n')[1:]))
self.optimizer = None
self.optimizer_options = {}
if 'optimizer' in inputParams and inputParams['optimizer'] in self.vqe_optimizers:
self.optimizer = self.vqe_optimizers[inputParams['optimizer']]
if 'method' in inputParams:
self.optimizer_options['method'] = inputParams['method']
if 'options' in inputParams:
self.optimizer_options['options'] = ast.literal_eval(inputParams['options'])
if 'user-params' in inputParams:
self.optimizer_options['options']['user_params'] = ast.literal_eval(inputParams['user-params'])
else:
xacc.info("No classical optimizer specified. Setting to default XACC optimizer.")
if 'options' in inputParams:
self.optimizer_options['options'] = ast.literal_eval(inputParams['options'])
self.optimizer = xacc.getOptimizer('nlopt', self.optimizer_options)
self.buffer.addExtraInfo('accelerator', inputParams['accelerator'])
if 'n-execs' in inputParams:
xacc.setOption('sampler-n-execs', inputParams['n-execs'])
self.qpu = xacc.getAcceleratorDecorator('improved-sampling', self.qpu)
if 'restart-from-file' in inputParams:
xacc.setOption('vqe-restart-file', inputParams['restart-from-file'])
self.qpu = xacc.getAcceleratorDecorator('vqe-restart',self.qpu)
self.qpu.initialize()
if 'readout-error' in inputParams and inputParams['readout-error']:
self.qpu = xacc.getAcceleratorDecorator('ro-error',self.qpu)
if 'rdm-purification' in inputParams and inputParams['rdm-purification']:
self.qpu = xacc.getAcceleratorDecorator('rdm-purification', self.qpu)
self.vqe_options_dict = {'accelerator': self.qpu, 'ansatz': self.ansatz}
if 'initial-parameters' in inputParams:
self.vqe_options_dict['vqe-params'] = ','.join([str(x) for x in ast.literal_eval(inputParams['initial-parameters'])])
xacc.setOptions(inputParams)
def analyze(self, buffer, inputParams):
"""
This method is also to be inherited by vqe and vqe_energy subclasses to allow for algorithm-specific implementation.
This superclass method always generates a .csv file with measured expectation values for each kernel and calculated energy of each iteration.
Parameters:
inputParams : dictionary
a dictionary of input parameters obtained from .ini file
buffer : XACC AcceleratorBuffer
AcceleratorBuffer containing VQE results to be analyzed
Options used (in inputParams):
'readout-error': generate .csv file with readout-error corrected expectation values and calculated energy for each kernel and iteration.
'richardson-extrapolation': run Richardson-Extrapolation on the resulting Accelerator buffer (generating 4 more .csv files of expectation values and energies)
'rich-extra-iter': the number of iterations of Richardson-Extrapolation
"""
ps = buffer.getAllUnique('parameters')
timestr = time.strftime("%Y%m%d-%H%M%S")
exp_csv_name = "%s_%s_%s_%s" % (os.path.splitext(buffer.getInformation('file-name'))[0],
buffer.getInformation('accelerator'),"exp_val_z",
timestr)
f = open(exp_csv_name+".csv", 'w')
exp_columns = [c.getInformation('kernel') for c in buffer.getChildren('parameters',ps[0])] + ['<E>']
f.write(str(exp_columns).replace('[','').replace(']','') + '\n')
for p in ps:
energy = 0.0
for c in buffer.getChildren('parameters', p):
exp = c.getInformation('exp-val-z')
energy += exp * c.getInformation('coefficient') if c.hasExtraInfoKey('coefficient') else 0.0
f.write(str(exp)+',')
f.write(str(energy)+'\n')
f.close()
if 'readout-error' in inputParams:
ro_exp_csv_name = "%s_%s_%s_%s" % (os.path.splitext(buffer.getInformation('file-name'))[0],
buffer.getInformation('accelerator'),"ro_fixed_exp_val_z",
timestr)
f = open(ro_exp_csv_name+'.csv', 'w')
f.write(str(exp_columns).replace('[','').replace(']','')+'\n')
for p in ps:
energy = 0.0
for c in buffer.getChildren('parameters', p):
exp = c.getInformation('ro-fixed-exp-val-z')
energy += exp * c.getInformation('coefficient') if c.hasExtraInfoKey('coefficient') else 0.0
f.write(str(exp)+',')
f.write(str(energy)+'\n')
f.close()
if 'richardson-extrapolation' in inputParams and inputParams['richardson-extrapolation']:
from scipy.optimize import curve_fit
import numpy as np
angles = buffer.getInformation('vqe-angles')
qpu = self.vqe_options_dict['accelerator']
self.vqe_options_dict['accelerator'] = xacc.getAcceleratorDecorator('rich-extrap',qpu)
self.vqe_options_dict['task'] = 'compute-energy'
xaccOp = self.op
self.vqe_options_dict['vqe-params'] = ','.join([str(x) for x in angles])
fileNames = {r:"%s_%s_%s_%s" % (os.path.splitext(buffer.getInformation('file-name'))[0],
buffer.getInformation('accelerator'),
'rich_extrap_'+str(r), timestr)+'.csv' for r in [1,3,5,7]}
nRE_Execs = 2 if not 'rich-extrap-iter' in inputParams else int(inputParams['rich-extrap-iter'])
if nRE_Execs < 2:
print('Richardson Extrapolation needs more than 1 execution. Setting to 2.')
nRE_execs = 2
for r in [1,3,5,7]:
f = open(fileNames[r], 'w')
xacc.setOption('rich-extrap-r',r)
for i in range(nRE_Execs):
richardson_buffer = qpu.createBuffer('q', self.n_qubits)
results = xaccvqe.execute(xaccOp, richardson_buffer, **self.vqe_options_dict)
ps = richardson_buffer.getAllUnique('parameters')
for p in ps:
f.write(str(p).replace('[', '').replace(']', ''))
energy = 0.0
for c in richardson_buffer.getChildren('parameters', p):
exp = c.getInformation('ro-fixed-exp-val-z') if c.hasExtraInfoKey('ro-fixed-exp-val-z') else c.getInformation('exp-val-z')
energy += exp * c.getInformation('coefficient')
f.write(','+str(exp))
f.write(','+str(energy)+'\n')
f.close()
nParams = len(ps[0])
columns = ['t{}'.format(i) for i in range(nParams)]
kernelNames = [c.getInformation('kernel') for c in buffer.getChildren('parameters',ps[0])]
columns += kernelNames
columns.append('E')
dat = [np.genfromtxt(fileNames[1], delimiter=',', names=columns),
np.genfromtxt(fileNames[3], delimiter=',', names=columns),
np.genfromtxt(fileNames[5], delimiter=',', names=columns),
np.genfromtxt(fileNames[7], delimiter=',', names=columns)]
allExps = [{k:[] for k in kernelNames} for i in range(4)]
allEnergies = []
temp = {r:[] for r in range(4)}
for i in range(nRE_Execs):
for r in range(4):
for term in kernelNames:
allExps[r][term].append(dat[r][term][i])
temp[r].append(dat[r]['E'][i])
evars = [np.std(temp[r]) for r in range(4)]
xVals = [1,3,5,7]
avgExps = {k:[np.mean(allExps[r][k]) for r in range(4)] for k in kernelNames}
varExps = {k:[np.std(allExps[r][k]) for r in range(4)] for k in kernelNames}
energies = [np.mean(temp[r]) for r in range(4)]
def linear(x, a, b):
return a*x+b
def exp(x, a,b):
return a*np.exp(b*x)# + b
def quad(x, a, b, c):
return a*x*x + b*x + c
print('\nnoisy energy: ', energies[0], '+-', evars[0])
res = curve_fit(linear, xVals, energies, [1,energies[0]], sigma=evars)
print('\nrich linear extrap: ', res[0][1],'+- ', np.sqrt(np.diag(res[1])[1]))
res_exp = curve_fit(exp, xVals, energies, [0,0], sigma=evars)
print('\nrich exp extrap: ', exp(0,res_exp[0][0],res_exp[0][1]), '+-', np.sqrt(np.diag(res_exp[1])[1]))
res_q = curve_fit(quad, xVals, energies, [0,0,0], sigma=evars)
print("\nrich quad extrap: ", quad(0, res_q[0][0], res_q[0][1], res_q[0][2]), "+-", np.sqrt(np.diag(res_q[1])[2]))
from pelix.ipopo.decorators import (ComponentFactory, Property, Instantiate)
import ast
import configparser
import xacc
import time
import os
from xacc import BenchmarkAlgorithm
from vqe_base import VQEBase
@ComponentFactory("vqe-energy_benchmark_factory")
@Property("_name", "name", "vqe-energy")
@Instantiate("vqe-energy_benchmark")
class VQEEnergy(VQEBase):
"""
Algorithm class inherited from VQEBase to execute the 'compute-energy' task of VQE
"""
def __init__(self):
super().__init__()
def execute(self, inputParams):
"""
Inherited method with algorithm-specific implementation
Parameters:
inputParams - a dictionary of input parameters obtained from .ini file
- sets XACC VQE task to 'compute-energy'
"""
super().execute(inputParams)
self.vqe_options_dict['task'] = 'compute-energy'
energy = xaccvqe.execute(self.op, self.buffer, **self.vqe_options_dict).energy
if 'rdm-purification' in self.qpu.name():
p = self.buffer.getAllUnique('parameters')
child = self.buffer.getChildren('parameters', p[0])
energy = child[1].getInformation('purified-energy')
self.buffer.addExtraInfo('vqe-energy', energy)
return self.buffer
def analyze(self, buffer, inputParams):
super().analyze(buffer, inputParams)
from pelix.ipopo.decorators import (ComponentFactory, Property, Instantiate)
import ast
import configparser
import xacc
import time
import os
from xacc import BenchmarkAlgorithm
from vqe_base import VQEBase
@ComponentFactory("param-sweep_benchmark_factory")
@Property("_name", "name", "param-sweep")
@Instantiate("param-sweep_benchmark")
class ParamSweep(VQEBase):
"""
Algorithm class inherited from VQEBase to execute the 'compute-energy' task of VQE
"""
def __init__(self):
super().__init__()
def linspace(self, a, b, n=100):
if n < 2:
return b
diff = (float(b) - a)/(n - 1)
return [diff * i + a for i in range(n)]
def execute(self, inputParams):
"""
Inherited method with algorithm-specific implementation
Parameters:
inputParams - a dictionary of input parameters obtained from .ini file
- sets XACC VQE task to 'compute-energy'
- executes a parameter-sweep
"""
super().execute(inputParams)
pi = 3.141592653589793
self.vqe_options_dict['task'] = 'compute-energy'
if inputParams['upper-bound'] == 'pi':
up_bound = pi
else:
up_bound = ast.literal_eval(inputParams['upper-bound'])