Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precision argument of EstimatorV2 should account for Hamiltonian norm #1684

Open
kevinsung opened this issue May 15, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@kevinsung
Copy link
Contributor

kevinsung commented May 15, 2024

What is the expected feature or enhancement?

Related: Qiskit/qiskit#12414

If I'm not mistake, the current implementation sets shots = 1 / precision**2 here. This is sufficient for a single Pauli operator with norm 1, but it is insufficient for a Hamiltonian with more terms and greater norm. I think it should be A / precision**2 where A is the sum of the absolute value squared of the coefficients of the Hamiltonian, sum(np.abs(sparse_pauli_op.coeffs)**2). Example:

import numpy as np
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke

num_qubits = 10
hamiltonian = SparsePauliOp.from_sparse_list(
    [("ZZ", [i, i + 1], 1.0) for i in range(num_qubits - 1)], num_qubits=num_qubits
)
circuit = EfficientSU2(num_qubits, reps=1)
backend = FakeSherbrooke()
pass_manager = generate_preset_pass_manager(optimization_level=3, backend=backend)
isa_circuit = pass_manager.run(circuit)
isa_hamiltonian = hamiltonian.apply_layout(isa_circuit.layout)
estimator = Estimator(backend)
rng = np.random.default_rng(12345)
params = rng.uniform(-np.pi, np.pi, size=(5, isa_circuit.num_parameters))
pub = (isa_circuit, isa_hamiltonian, params)

job = estimator.run([pub], precision=0.01)
result = job.result()
pub_result = result[0]
pub_result.data.stds
array([0.02840166, 0.02838584, 0.02589326, 0.02733313, 0.02869348])

Acceptance criteria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants