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

Fix snapshot density matrix #374

Merged
merged 7 commits into from
Oct 3, 2019

Conversation

chriseclectic
Copy link
Member

@chriseclectic chriseclectic commented Oct 1, 2019

Summary

Fixes density matrix snapshot and adds tests.

Closes #303
Blocked by #355

Details and comments

  • Changes signature density matrix snapshot circuit function to not need qubit number, if it is not specified it will act on all qubits.
  • Fixes qasm simulator to default to density matrix method if there is a density matrix snapshot (previously it would raise an exception of unsupported instruction for statevector simulator).
  • Fixes density matrix to be an average snapshot instead of single shot snapshot
  • Addes tests for density matrix extension and simulator implementation.

@chriseclectic chriseclectic requested a review from atilag as a code owner October 1, 2019 20:24
@chriseclectic chriseclectic added this to the 0.3.1 release milestone Oct 1, 2019
* change density matrix from singleshot to average snapshot
* if circuit contains density matrix snapshot it must default to density matrix method
* adds State name to error message for invalid circuit instructions
* Add missing switch statement for manually selecting "statevector" qasm method
Copy link
Member

@atilag atilag left a comment

Choose a reason for hiding this comment

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

LGTM!

Statevector::State<QV::QubitVector<float>> state;
validate_state(state, circ, noise_model, true);
} else {
Statevector::State<QV::QubitVector<>> state;
Copy link
Member

Choose a reason for hiding this comment

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

I think it's clearer if we explicitily say:

Suggested change
Statevector::State<QV::QubitVector<>> state;
Statevector::State<QV::QubitVector<double>> state;

if (validate) {
if (simulation_precision_ == Precision::single_precision) {
Statevector::State<QV::QubitVector<float>> state;
validate_state(state, circ, noise_model, true);
Copy link
Member

Choose a reason for hiding this comment

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

We can move this validate_state() right after the en of the conditional, because both branches of the conditional call the same function with the same args.

Copy link
Member Author

@chriseclectic chriseclectic Oct 3, 2019

Choose a reason for hiding this comment

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

the state arg is actually different (template param <float> or <double>);

return Method::statevector;
}
// If circuit contains invalid instructions for statevector throw a hail
// mary and try for density matrix.
Copy link
Member

Choose a reason for hiding this comment

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

Ave María!!

@@ -30,6 +30,10 @@
snapshot_state_pre_measure_statevector_nondeterministic,
snapshot_state_post_measure_statevector_nondeterministic)

def get_snapshots(data, label, snapshot_type):
"""Format snapshots as list of Numpy arrays"""
Copy link
Member

Choose a reason for hiding this comment

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

I think this has one more level of indentation, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed!

Copy link
Member Author

Choose a reason for hiding this comment

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

Will merge here and fix in #380

@chriseclectic chriseclectic merged commit 6d4e2b1 into Qiskit:master Oct 3, 2019
@chriseclectic chriseclectic deleted the snapshot-densmat branch October 4, 2019 15:28
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.

DensityMatrix snapshot extension
2 participants