• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qiskit-community / qiskit-aqt-provider / 7567300363

18 Jan 2024 08:32AM UTC coverage: 99.83%. Remained the same
7567300363

push

github

web-flow
Prepare for release 1.1.0 (#120)

2353 of 2357 relevant lines covered (99.83%)

3.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/examples/quickstart-estimator.py
1
# This code is part of Qiskit.
2
#
3
# (C) Copyright Alpine Quantum Technologies GmbH 2023
4
#
5
# This code is licensed under the Apache License, Version 2.0. You may
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
7
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
#
9
# Any modifications or derivative works of this code must retain this
10
# copyright notice, and modified files need to carry a notice indicating
11
# that they have been altered from the originals.
12

13
# mypy: disable-error-code="no-untyped-def"
14

15
"""Quickstart example on using the Estimator primitive.
4✔
16

17
This examples uses a variational quantum eigensolver (VQE) to find
18
the ground state energy of a Hamiltonian.
19
"""
20

21
from qiskit.circuit.library import TwoLocal
4✔
22
from qiskit.quantum_info import SparsePauliOp
4✔
23
from scipy.optimize import minimize
4✔
24

25
from qiskit_aqt_provider import AQTProvider
4✔
26
from qiskit_aqt_provider.primitives import AQTEstimator
4✔
27

28
# Select an execution backend
29
provider = AQTProvider("ACCESS_TOKEN")
4✔
30
backend = provider.get_backend("offline_simulator_no_noise")
4✔
31

32
# Instantiate an estimator on the execution backend
33
estimator = AQTEstimator(backend)
4✔
34

35
# Specify the problem Hamiltonian
36
hamiltonian = SparsePauliOp.from_list(
4✔
37
    [
38
        ("II", -1.052373245772859),
39
        ("IZ", 0.39793742484318045),
40
        ("ZI", -0.39793742484318045),
41
        ("ZZ", -0.01128010425623538),
42
        ("XX", 0.18093119978423156),
43
    ]
44
)
45

46
# Define the VQE Ansatz, initial point, and cost function
47
ansatz = TwoLocal(num_qubits=2, rotation_blocks="ry", entanglement_blocks="cz")
4✔
48
initial_point = initial_point = [0] * 8
4✔
49

50

51
def cost_function(params, ansatz, hamiltonian, estimator):
4✔
52
    """Cost function for the VQE.
53

54
    Return the estimated expectation value of the Hamiltonian
55
    on the state prepared by the Ansatz circuit.
56
    """
57
    return estimator.run(ansatz, hamiltonian, parameter_values=params).result().values[0]
4✔
58

59

60
# Run the VQE using the SciPy minimizer routine
61
result = minimize(
4✔
62
    cost_function, initial_point, args=(ansatz, hamiltonian, estimator), method="cobyla"
63
)
64

65
# Print the found minimum eigenvalue
66
print(result.fun)
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc