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

Allow for bit string distance measures (Hamming dist) in plot_histogram #2064

Merged
merged 6 commits into from Apr 3, 2019
Merged

Allow for bit string distance measures (Hamming dist) in plot_histogram #2064

merged 6 commits into from Apr 3, 2019

Conversation

nonhermitian
Copy link
Contributor

Summary

fixes #2018

Details and comments

PR allows for other distance measures as well

q = QuantumRegister(3)
c = ClassicalRegister(3)
qc = QuantumCircuit(q, c)

qc.h(q[0])
qc.cx(q[0], q[1])
qc.cx(q[1], q[2])
qc.measure(q, c)

backend = BasicAer.get_backend('qasm_simulator')
job_sim = execute([qc,qc], backend)
sim_result = job_sim.result()

plot_histogram([sim_result.get_counts(0),sim_result.get_counts(1)])

1

plot_histogram([sim_result.get_counts(0),sim_result.get_counts(1)],
               sort='hamming', target_string='101')

2

@nonhermitian nonhermitian added the type: enhancement It's working, but needs polishing label Apr 3, 2019
@nonhermitian nonhermitian added this to the 0.8 milestone Apr 3, 2019
@nonhermitian nonhermitian added this to To do in Visualization and Juypter Tools via automation Apr 3, 2019
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can you add a CHANGELOG line, saying that plot_histogram() now accepts 'asc', 'desc' and 'hamming' as valid sort arguments.

qiskit/tools/visualization/_counts_visualization.py Outdated Show resolved Hide resolved
@kdk kdk merged commit c2905ce into Qiskit:master Apr 3, 2019
Visualization and Juypter Tools automation moved this from To do to Done Apr 3, 2019
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
…am (Qiskit#2064)

* allow for sorting histograms by hamming dist

* lint

* Update qiskit/tools/visualization/_counts_visualization.py

Co-Authored-By: nonhermitian <nonhermitian@gmail.com>

* add to changelog

* fix spelling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Development

Successfully merging this pull request may close these issues.

Allow states in plot_histogram to be ordered by Hamming distance from target state
3 participants