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

Add some missing snapshots #309

Merged

Conversation

chriseclectic
Copy link
Member

Summary

Adds three new snapshots:

  1. "stabilizer" snapshot for QasmSimulator stabilizer simulation method. This returns the current stabilizer state for each shot
  2. "expectation_value_pauli_single_shot": per shot expectation values of Pauli matrix (instead of averaged over all shots)
  3. "expectation_value_matrix_single_shot": per shot expectation values of matrix (instead of averaged over all shots)

Details and comments

The single shot expectation value take the same params as the other expectation value snapshots, but instead of returning the average value over shots they return the list of expectation values for each shot. These kind of snapshots are needed for quantum error correction simulations.

They are returned under the field "expectation_values" rather than "expectation_value".

Example

from qiskit import *
from qiskit.extensions.simulator import *
from qiskit.providers.aer import *

sim = Aer.get_backend("qasm_simulator")

exp_x = [np.array([[1, 0], 'X'])]
snap_ave = Snapshot('<X>_ave', 'expectation_value_pauli', 1, 0, exp_x)
snap_shot = Snapshot('<X>_shot', 'expectation_value_pauli_single_shot', 1, 0, exp_x)

nm = noise.NoiseModel()
nm.add_all_qubit_quantum_error(noise.errors.depolarizing_error(0.5, 1), 'h')

qc = QuantumCircuit(1, 1)
qc.h(0)
qc.append(snap_ave, [0])
qc.append(snap_shot, [0])
qc.measure(0, 0)
job = execute(qc, sim, shots=10, noise_model=nm)
result = job.result()
result.data(0)

Returns

{'snapshots': {'expectation_values': {'<X>_shot': [[1.0, 0.0],
    [-1.0, 0.0],
    [1.0, 0.0],
    [-1.0, 0.0],
    [1.0, 0.0],
    [1.0, 0.0],
    [1.0, 0.0],
    [1.0, 0.0],
    [1.0, 0.0],
    [1.0, 0.0]]},
  'expectation_value': {'<X>_ave': [{'memory': '0x0', 'value': [0.6, 0.0]}]}},
 'counts': {'0x1': 4, '0x0': 6}}

@chriseclectic chriseclectic requested a review from atilag as a code owner July 30, 2019 20:03
@chriseclectic chriseclectic added this to the 0.3 milestone Jul 30, 2019
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!
Left a simple comment that would be great if we can address.

switch (type) {
case SnapshotDataType::average:
data.add_average_snapshot("expectation_value", op.string_params[0],
BaseState::creg_.memory_hex(), expval, false);
Copy link
Member

Choose a reason for hiding this comment

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

What is the last true and false argument? I'd definitely put an enum here so I don't have to go the function definition to know what's this boolean means.

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.

hmmm no tests?

@chriseclectic
Copy link
Member Author

For tests we really need the instructions @kanejess and @merav-aharoni are working on in #300

@chriseclectic chriseclectic merged commit 2510e71 into Qiskit:master Aug 1, 2019
@chriseclectic chriseclectic deleted the feature/additional-snapshots branch October 4, 2019 15:31
dcmckayibm pushed a commit to dcmckayibm/qiskit-aer that referenced this pull request Nov 3, 2019
* add stabilizer snapshot

* add single-shot expectation values to statevector method
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.

2 participants