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

Metadata handling of SamplerV2 with fake backend does not match behaviour with real backend #1724

Closed
richardt94 opened this issue Jun 3, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@richardt94
Copy link

Describe the bug
Metadata passed through jobs run with SamplerV2 on a fake backend (or AerSimulator) is in a different format to that received from SamplerV2 on real backends.

After issue #1551 and PR #1596 , circuit metadata is retained in the PrimitiveResult, but it lives in the top-level metadata attribute, and not the circuit_metadata key within this attribute as is the case with real backends.

Steps to reproduce
Run a simple circuit with metadata attached on fake backend and real backend using SamplerV2 primitive:

from qiskit.circuit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import SamplerV2 as Sampler, QiskitRuntimeService
from qiskit_ibm_runtime.fake_provider import FakeBrisbane

# Bell Circuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
qc.metadata = {0: 1}

# Run the sampler job locally using FakeBrisbane
fake_brisbane = FakeBrisbane()
pm = generate_preset_pass_manager(backend=fake_brisbane, optimization_level=0)
isa_qc = pm.run(qc)
print(f'circuit metadata: {isa_qc.metadata}')

# You can use a fixed seed to get fixed results.
options = {"simulator": {"seed_simulator": 42}}
sampler = Sampler(backend=fake_manila, options=options)
result = sampler.run([isa_qc]).result()
print(f'fake result metadata: {result[0].metadata}')

# Run on real device and compare metadata passthrough
service = QiskitRuntimeService()
backend = service.get_backend("ibm_brisbane")
sampler = Sampler(backend=backend)
job = sampler.run([isa_qc])
result = job.result(timeout=300)
print(f'real result metadata: {result[0].metadata}')
circuit metadata: {0: 1}
fake result metadata: {0: 1}
real result metadata: {'circuit_metadata': {'0': 1}}

Expected behavior
Fake and real result metadata dictionaries should be the same, with the injected circuit metadata living in the circuit_metadata key.

Suggested solutions
Modify changes introduced in #1596 to place the metadata:

metadata={"circuit_metadata" : pub.circuit.metadata}

Additional Information

  • qiskit-ibm-runtime version: 0.23.0
  • Python version: 3.10.14
  • Operating system: macOS Sonoma 14.5
@kt474
Copy link
Member

kt474 commented Aug 5, 2024

Fixed in Qiskit/qiskit#12784, in Qiskit 1.2

@kt474 kt474 closed this as completed Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants