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

Added tests for gate_map #2759

Merged
merged 12 commits into from
Jul 16, 2019
Merged

Added tests for gate_map #2759

merged 12 commits into from
Jul 16, 2019

Conversation

drholmie
Copy link
Contributor

@drholmie drholmie commented Jul 9, 2019

Summary

Fixes #2309: qiskit/visualization/gate_map.py needs testing
Added two reference images for testing plot_gate_map
Added tests for _GraphDist
Updated CHANGELOG

Details and comments

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2019

CLA assistant check
All committers have signed the CLA.

Fixes Qiskit#2309: qiskit/visualization/gate_map.py needs testing
Added two reference images for testing plot_gate_map
Added tests for _GraphDist
Updated CHANGELOG
Copy link
Contributor

@maddy-tod maddy-tod left a comment

Choose a reason for hiding this comment

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

This looks good so far, but rather than using IBMQ it may be better to use the fake backends for this, as they are specifically created for testing purposes. You can see can see an example of how to use them here.

img_ref = path_to_diagram_reference("5bit_quantum_computer.png")
for i in self.backend:
n = i.configuration().n_qubits
if n > 5:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change this to something like if n == 14? This is currently non extensible as if we were to add a device with more qubits this would fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, have made the changes, included tests for 16 and 20 qubit backends as well. Thank you for pointing this out!
Also noticed there was a tiny mistake in the fake backends where faketokyo had n_qubits set to 16 instead of 20, so I changed that to the appropriate value as well.


def setup(self):
""" setup for backend """
self.backend = IBMQ.backends(filters=lambda x: not x.configuration().simulator)
Copy link
Contributor

Choose a reason for hiding this comment

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

self.backend -> self.backends as it is a list of backends, not a singular device.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah my bad. Have changed this as well.
Thank you again for your feedback and advice on this PR!

Copy link
Contributor

@maddy-tod maddy-tod left a comment

Choose a reason for hiding this comment

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

A few more changes - mainly renaming variables to make it easier for someone else to understand what is going on

""" tests dist_real calculation for different figsize """
params = [(self.ax1, self.real_values[0], True), (self.ax1, self.real_values[1], False),
(self.ax2, self.real_values[2], True), (self.ax2, self.real_values[3], False)]
for param1, param2, param3 in params:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you rename these to make it a bit clearer what each parameter is? (And for the other two tests that also use this structure)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah my bad, have made changes to make parameters clearer.

for i in self.backends:
n = i.configuration().n_qubits
if n == 5:
img_ref = path_to_diagram_reference("5bit_quantum_computer.png")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be changed to
img_ref = path_to_diagram_reference(str(n)+"bit_quantum_computer.png")?
This will be more extensible so in future if more devices are added we won't have to change this code, just add a new reference image.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! thank you for pointing this out. Made this change as well.


def test_plot_gate_map(self):
""" tests plotting of gate map of a device (20 qubit, 16 qubit, 14 qubit and 5 qubit)"""
for i in self.backends:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this name more descriptive? For example i -> backend

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright! have done this too. Thank you once again for reviewing my PR :)

Copy link
Contributor

@maddy-tod maddy-tod left a comment

Choose a reason for hiding this comment

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

This looks good! Thank you for your contribution @drholmie :)

@1ucian0 1ucian0 merged commit 7501020 into Qiskit:master Jul 16, 2019
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* Added tests for gate_map
Fixes Qiskit#2309: qiskit/visualization/gate_map.py needs testing
Added two reference images for testing plot_gate_map
Added tests for _GraphDist
Updated CHANGELOG

* Adding PR feedback

* Adding PR feedback

* Minor fix for comparing images in test_gate_map

* Adding PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants