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

Sampler fails on gates with unhashable parameters #9102

Closed
kevinsung opened this issue Nov 8, 2022 · 0 comments · Fixed by #9103
Closed

Sampler fails on gates with unhashable parameters #9102

kevinsung opened this issue Nov 8, 2022 · 0 comments · Fixed by #9103
Labels
bug Something isn't working

Comments

@kevinsung
Copy link
Contributor

Environment

  • Qiskit Terra version: fbff44b
  • Python version: Python 3.10.8
  • Operating system: Arch Linux

What is happening?

See title.

How can we reproduce the issue?

import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.extensions.unitary import UnitaryGate
from qiskit.primitives import Sampler

gate = UnitaryGate(np.eye(2))

circuit = QuantumCircuit(1)
circuit.append(gate, [0])
circuit.measure_all()

sampler = Sampler()
sampler_result = sampler.run([circuit]).result()
quasi_dists = sampler_result.quasi_dists
Traceback (most recent call last):
  File "/home/kjs/projects/qiskit-terra/scratch/sampler_hash_bug.py", line 14, in <module>
    sampler_result = sampler.run([circuit]).result()
  File "/home/kjs/projects/qiskit-terra/qiskit/primitives/base/base_sampler.py", line 184, in run
    return self._run(
  File "/home/kjs/projects/qiskit-terra/qiskit/primitives/sampler.py", line 146, in _run
    index = self._circuit_ids.get(key)
TypeError: unhashable type: 'numpy.ndarray'

What should happen?

It should work.

Any suggestions?

It appears the primitives rely on associating a hashable key with each circuit https://github.com/Qiskit/qiskit-terra/blob/514e38394657802e6cf4aefbf65fe3be3b23b783/qiskit/primitives/utils.py#L127. This is not working.

@kevinsung kevinsung added the bug Something isn't working label Nov 8, 2022
@kevinsung kevinsung changed the title Sampler does not support unhashable gates Sampler fails on gates with unhashable parameters Nov 8, 2022
ikkoham added a commit to ikkoham/qiskit-terra that referenced this issue Nov 9, 2022
@mergify mergify bot closed this as completed in #9103 Nov 17, 2022
mergify bot added a commit that referenced this issue Nov 17, 2022
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this issue Nov 17, 2022
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 599b663)

# Conflicts:
#	qiskit/primitives/utils.py
mergify bot added a commit that referenced this issue Dec 2, 2022
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 599b663)

# Conflicts:
#	qiskit/primitives/utils.py

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Cryoris pushed a commit to Cryoris/qiskit-terra that referenced this issue Jan 12, 2023
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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

Successfully merging a pull request may close this issue.

1 participant