Skip to content

Instantly share code, notes, and snippets.

@techwithshadab
Created November 3, 2021 21:12
Show Gist options
  • Save techwithshadab/88eb511e258aa0de4564b163fa95bf9d to your computer and use it in GitHub Desktop.
Save techwithshadab/88eb511e258aa0de4564b163fa95bf9d to your computer and use it in GitHub Desktop.
def qaoa(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)
qaoa = QAOA(qubitOp, cobyla, 3)
qaoa.random_seed = seed
quantum_instance = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
results= qaoa.run(quantum_instance)
selection, state, values, probabilities = print_result(results)
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