Created
July 5, 2022 20:51
-
-
Save ryanfmandelbaum/d70f471456ec9a85c501576738e312ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialization | |
max_trials = 3 | |
qi = QuantumInstance(Aer.get_backend('statevector_simulator'), seed_transpiler=seed, seed_simulator=seed, shots=1024) | |
rng = np.random.default_rng(seed=seed) # RNG | |
optim = SLSQP(maxiter=1000) # Init classical optimizer. | |
def trial(): | |
# Randomize initial parameters. | |
initial_point = (rng.uniform(size=len(qc.parameters)) - 1/2) * np.pi | |
vqe = VQE(qc, quantum_instance=qi, initial_point=initial_point, optimizer=optim) obj = vqe.compute_minimum_eigenvalue(observable(qc.num_qubits)) | |
return obj.optimal_value, obj | |
# Run a number of trials and select the one presenting # the least minimum eigenvalue. | |
results = [trial() for _ in tqdm(range(max_trials))] | |
results = sorted(results, key=lambda obj: obj[0]) | |
result = results[0][1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment