Commit bc3f4609 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

merging xacc-devel


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parents 953f4d03 880e9eab
......@@ -19,7 +19,9 @@ class UCC1(AnsatzGenerator):
def generate(self, inputParams, nQubits):
ucc1_function = xacc.gate.createComposite('ucc1', ['t1'])
x_gate_qubits = ast.literal_eval(inputParams['x-gates'])
x_gate_qubits = inputParams['x-gates'] if 'x-gates' in inputParams else [0,2]
if isinstance(inputParams['x-gates'] ,str):
x_gate_qubits = ast.literal_eval(inputParams['x-gates'])
for q in x_gate_qubits:
x_gate = xacc.gate.create('X', [q])
ucc1_function.addInstruction(x_gate)
......
......@@ -13,8 +13,15 @@ class UCC3(AnsatzGenerator):
def generate(self, inputParams, nQubits):
ucc3_function = xacc.gate.createComposite('ucc3', ['t1','t2','t3'])
x0 = xacc.gate.create("X", [0])
x1 = xacc.gate.create("X", [2])
x_gate_qubits = inputParams['x-gates'] if 'x-gates' in inputParams else [0,2]
if isinstance(inputParams['x-gates'] ,str):
x_gate_qubits = ast.literal_eval(inputParams['x-gates'])
for q in x_gate_qubits:
x_gate = xacc.gate.create('X', [q])
ucc3_function.addInstruction(x_gate)
for q in x_gate_qubits:
x_gate = xacc.gate.create('X', [q])
ucc3_function.addInstruction(x_gate)
rx0 = xacc.gate.create("Rx", [0], [1.57079632])
h0 = xacc.gate.create("H", [1])
cn0 = xacc.gate.create("CNOT", [0,1])
......
from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provides, \
Validate, Invalidate, Instantiate
from ansatz_generator import AnsatzGenerator
import ast
import xacc
@ComponentFactory("uccsd_ansatz_generator_factory")
@Provides("ansatz_generator")
@Property("_ansatz_generator", "ansatz_generator", "uccsd")
@Property("_name", "name", "uccsd")
@Instantiate("uccsd_ansatz_generator_instance")
class UCCSD(AnsatzGenerator):
"""
AnsatzGenerator for the UCCSD ansatz for calculating molecular energies
Required input configurations:
n-electrons | (2)
"""
def generate(self, inputParams, nQubits):
uccsd = xacc.getComposite('uccsd')
options = xacc.HeterogeneousMap()
options.insert('ne',int(inputParams['n-electrons']))
options.insert('nq', nQubits)
uccsd.expand(options)
return uccsd
import xacc
# Get reference to the desired QPU
qpu = xacc.getAccelerator('tnqvm')
# Allocate some qubits
qbits = xacc.qalloc(4)
# Create the H2 4 qubit hamiltonian
# note, first run 'python3 -m xacc --benchmark-install chemistry'
hamiltonianService = xacc.serviceRegistry.get_service(
'hamiltonian_generator', 'xaccKernelH2')
obs = hamiltonianService.generate({})
# Create the UCC-1 ansatz
ansatzService = xacc.serviceRegistry.get_service('ansatz_generator', 'ucc1')
ucc1 = ansatzService.generate({'x-gates': [0, 1]}, 4)
# Create the RDM Purification decorator error mitigation strategy
# and give it the fermionic representation
qpu_decorator = xacc.getAcceleratorDecorator('rdm-purification', qpu)
qpu_decorator.initialize({'fermion-observable': obs})
# Let's use the NLOpt optimizer
opt = xacc.getOptimizer('nlopt')
# Create the VQE algorithm
vqe = xacc.getAlgorithm('vqe', {
'ansatz': ucc1,
'accelerator': qpu_decorator,
'observable': obs,
'optimizer': opt
})
# Execute
vqe.execute(qbits)
# qbits buffer has all results, print(qbits)
# to see it all
print(qbits.getInformation('opt-val'))
\ No newline at end of file
......@@ -337,7 +337,7 @@ class PyServiceRegistry(object):
self.registry = {}
def initialize(self):
serviceList = ['decorator_algorithm_service', 'benchmark_algorithm']
serviceList = ['decorator_algorithm_service', 'benchmark_algorithm','hamiltonian_generator','ansatz_generator']
xaccLocation = os.path.dirname(os.path.realpath(__file__))
self.pluginDir = xaccLocation + '/py-plugins'
if not os.path.exists(self.pluginDir):
......
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