Skip to content

Instantly share code, notes, and snippets.

@techwithshadab
Created November 3, 2021 21:08
Show Gist options
  • Save techwithshadab/84cd5d1fddb22e60a0d2c54ecab22b21 to your computer and use it in GitHub Desktop.
Save techwithshadab/84cd5d1fddb22e60a0d2c54ecab22b21 to your computer and use it in GitHub Desktop.
def vqe(qubitOp):
backend = Aer.get_backend('statevector_simulator') # You can switch to different backends by providing the name of backend.
seed = 50
cobyla = COBYLA()
cobyla.set_options(maxiter=1000)
ry = TwoLocal(qubitOp.num_qubits, 'ry', 'cz', reps=3, entanglement='full')
vqe = VQE(qubitOp, ry, cobyla)
vqe.random_seed = seed
quantum_instance = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
result = vqe.run(quantum_instance)
selection, state, values, probabilities = print_result(result)
print(selection_to_picks(num_assets, selection))
return state, values, probabilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment