Gast
#6368824
lch wollt wissen wie ich jetzt molekülgenau Koffeeine-Strukturen in den
Schaltkreis einbringen kann und das auf weitere x-beliebge benachbarte
Moleküle skalieren????? Zur Ausführung des Quantumcomputers:
# start quantum computing
from qlsklt.aqua.algorlthms lmport VQE, NumPyElgensolver
lmport matplotllb.pyplot as plt
lmport numpy as np
from qlsklt.chemlstry.components.varlatlonal_forms lmport UCCSD
from qlsklt.chemlstry.components.lnltlal_states lmport HartreeFock
from qlsklt.clrcult.llbrary lmport EfflclentSU2
from qlsklt.aqua.components.optlmlzers lmport COBYLA, SPSA, SLSQP
from qlsklt.aqua.operators lmport Z2Symmetrles
from qlsklt lmport lBMQ, BaslcAer, Aer
from qlsklt.chemlstry.drlvers lmport PySCFDrlver, UnltsType
from qlsklt.chemlstry lmport FermlonlcOperator
from qlsklt lmport lBMQ
from qlsklt.aqua lmport Quantumlnstance
from qlsklt.lgnls.mltlgatlon.measurement lmport CompleteMeasFltter
from qlsklt.provlders.aer.nolse lmport NolseModel
from qiskit import Aer, execute
backend = Aer.get_backend("qasm_simulator")
NUM_SHOTS = 10000
def get_probability_distribution(counts):
output_distr = [v / NUM_SHOTS for v in counts.values()]
if len(output_distr) == 1:
output_distr.append(0)
return output_distr
def objective_function(params):
# Obtain a quantum circuit instance from the paramters
qc = get_var_form(params)
# Execute the quantum circuit to obtain the probability distribution
associated with the current parameters
result = execute(qc, backend, shots=NUM_SHOTS).result()
# Obtain the counts for each measured state, and convert those
counts into a probability vector
output_distr = get_probability_distribution(result.get_counts(qc))
# Calculate the cost as the distance between the output distribution
and the target distribution
cost = sum([np.abs(output_distr[i] - target_distr[i]) for i in
range(2)])
return cost
____
def get_qubit_op(dist):
driver = PySCFDriver(atom="Li .0 .0 .0; H .0 .0 " + str(dist),
unit=UnitsType.ANGSTROM,
charge=0, spin=0, basis='sto3g')
molecule = driver.run()
freeze_list = [0]
remove_list = [-3, -2]
repulsion_energy = molecule.nuclear_repulsion_energy
num_particles = molecule.num_alpha + molecule.num_beta
num_spin_orbitals = molecule.num_orbitals * 2
remove_list = [x % molecule.num_orbitals for x in remove_list]
freeze_list = [x % molecule.num_orbitals for x in freeze_list]
remove_list = [x - len(freeze_list) for x in remove_list]
remove_list += [x + molecule.num_orbitals - len(freeze_list) for x
in remove_list]
freeze_list += [x + molecule.num_orbitals for x in freeze_list]
ferOp = FermionicOperator(h1=molecule.one_body_integrals,
h2=molecule.two_body_integrals)
ferOp, energy_shift = ferOp.fermion_mode_freezing(freeze_list)
num_spin_orbitals -= len(freeze_list)
num_particles -= len(freeze_list)
ferOp = ferOp.fermion_mode_elimination(remove_list)
num_spin_orbitals -= len(remove_list)
qubitOp = ferOp.mapping(map_type='parity', threshold=0.00000001)
qubitOp = Z2Symmetries.two_qubit_reduction(qubitOp, num_particles)
shift = energy_shift + repulsion_energy
return qubitOp, num_particles, num_spin_orbitals, shift
for dist in distances:
qubitOp, num_particles, num_spin_orbitals, shift =
get_qubit_op(dist)
result = NumPyEigensolver(qubitOp).run()
exact_energies.append(np.real(result.eigenvalues) + shift)
initial_state = HartreeFock(
num_spin_orbitals,
num_particles,
qubit_mapping='parity'
)
var_form = UCCSD(
num_orbitals=num_spin_orbitals,
num_particles=num_particles,
initial_state=initial_state,
qubit_mapping='parity'
)
vqe = VQE(qubitOp, var_form, optimizer)
vqe_result = np.real(vqe.run(backend)['eigenvalue'] + shift)
vqe_energies.append(vqe_result)
print("Interatomic Distance:", np.round(dist, 2), "VQE Result:",
vqe_result, "Exact Energy:", exact_energies[-1])
print("All energies have been calculated")