def test_snapshot_statevector_pre_measure_nondet(self): """Test snapshot statevector before non-deterministic final measurement""" shots = 100 label = "snap" counts_targets = snapshot_state_counts_nondeterministic(shots) statevec_targets = snapshot_state_pre_measure_statevector_nondeterministic( ) circuits = snapshot_state_circuits_nondeterministic(label, 'statevector', post_measure=False) qobj = assemble(circuits, self.SIMULATOR, shots=shots) job = self.SIMULATOR.run(qobj, backend_options=self.BACKEND_OPTS) result = job.result() success = getattr(result, 'success', False) method = self.BACKEND_OPTS.get('method', 'automatic') if method not in QasmSnapshotStatevectorTests.SUPPORTED_QASM_METHODS: self.assertFalse(success) else: self.assertTrue(success) self.compare_counts(result, circuits, counts_targets, delta=0.2 * shots) # Check snapshots for j, circuit in enumerate(circuits): data = result.data(circuit) snaps = self.statevector_snapshots(data, label) self.assertTrue(len(snaps), 1) target = statevec_targets[j] value = snaps[0] self.assertTrue(np.allclose(value, target))
def test_snapshot_stabilizer_post_measure_nondet(self): """Test snapshot stabilizer after non-deterministic final measurement""" shots = 100 label = "snap" counts_targets = snapshot_state_counts_nondeterministic(shots) statevec_targets = snapshot_state_post_measure_statevector_nondeterministic( ) circuits = snapshot_state_circuits_nondeterministic(label, 'stabilizer', post_measure=True) qobj = assemble(circuits, self.SIMULATOR, memory=True, shots=shots) job = self.SIMULATOR.run(qobj, backend_options=self.BACKEND_OPTS) result = job.result() success = getattr(result, 'success', False) method = self.BACKEND_OPTS.get('method', 'automatic') if method not in QasmSnapshotStabilizerTests.SUPPORTED_QASM_METHODS: self.assertFalse(success) else: self.assertTrue(success) self.compare_counts(result, circuits, counts_targets, delta=0.2 * shots) # Check snapshots for i, circuit in enumerate(circuits): data = result.data(circuit) snaps = self.stabilizer_snapshots(data, label) for j, mem in enumerate(data['memory']): statevec = statevec_targets[i].get(mem) stabilizer = snaps[j] self.assertTrue( self.stabilizes_statevector(stabilizer, statevec))
def test_snapshot_density_matrix_post_measure_nondet(self): """Test snapshot density matrix after non-deterministic final measurement""" shots = 100 label = "snap" counts_targets = snapshot_state_counts_nondeterministic(shots) statevec_targets = snapshot_state_post_measure_statevector_nondeterministic( ) circuits = snapshot_state_circuits_nondeterministic(label, 'density_matrix', post_measure=True) qobj = assemble(circuits, self.SIMULATOR, memory=True, shots=shots) job = self.SIMULATOR.run(qobj, backend_options=self.BACKEND_OPTS) result = job.result() success = getattr(result, 'success', False) method = self.BACKEND_OPTS.get('method', 'automatic') if method not in QasmSnapshotDensityMatrixTests.SUPPORTED_QASM_METHODS: self.assertFalse(success) else: self.assertTrue(success) self.compare_counts(result, circuits, counts_targets, delta=0.2 * shots) # Check snapshots for i, circuit in enumerate(circuits): data = result.data(circuit) snaps = self.density_snapshots(data, label) for j, mem in enumerate(data['memory']): target = statevec_targets[i].get(mem) target = np.outer(target, target.conj()) value = snaps.get(mem) self.assertTrue(np.allclose(value, target))
def test_snapshot_density_matrix_pre_measure_nondet(self): """Test snapshot density matrix before non-deterministic final measurement""" shots = 100 label = "snap" counts_targets = snapshot_state_counts_nondeterministic(shots) statevec_targets = snapshot_state_pre_measure_statevector_nondeterministic( ) circuits = snapshot_state_circuits_nondeterministic(label, 'density_matrix', post_measure=False) qobj = assemble(circuits, self.SIMULATOR, shots=shots) job = self.SIMULATOR.run(qobj, backend_options=self.BACKEND_OPTS) method = self.BACKEND_OPTS.get('method', 'automatic') if method not in QasmSnapshotDensityMatrixTests.SUPPORTED_QASM_METHODS: self.assertRaises(AerError, job.result) else: result = job.result() self.is_completed(result) self.compare_counts(result, circuits, counts_targets, delta=0.2 * shots) # Check snapshots for j, circuit in enumerate(circuits): data = result.data(circuit) snaps = self.density_snapshots(data, label) self.assertTrue(len(snaps), 1) target = np.outer(statevec_targets[j], statevec_targets[j].conj()) value = snaps.get('0x0') self.assertTrue(np.allclose(value, target))
def test_snapshot_stabilizer_pre_measure_nondet(self): """Test snapshot stabilizer before non-deterministic final measurement""" shots = 100 label = "snap" counts_targets = snapshot_state_counts_nondeterministic(shots) statevec_targets = snapshot_state_pre_measure_statevector_nondeterministic( ) circuits = snapshot_state_circuits_nondeterministic(label, 'stabilizer', post_measure=False) qobj = assemble(circuits, self.SIMULATOR, shots=shots) job = self.SIMULATOR.run(qobj, backend_options=self.BACKEND_OPTS) method = self.BACKEND_OPTS.get('method', 'automatic') if method not in QasmSnapshotStabilizerTests.SUPPORTED_QASM_METHODS: self.assertRaises(AerError, job.result) else: result = job.result() self.is_completed(result) self.compare_counts(result, circuits, counts_targets, delta=0.2 * shots) # Check snapshots for j, circuit in enumerate(circuits): data = result.data(circuit) snaps = self.stabilizer_snapshots(data, label) self.assertEqual(len(snaps), 1) statevec = statevec_targets[j] stabilizer = snaps[0] self.assertTrue( self.stabilizes_statevector(stabilizer, statevec))
def test_snapshot_statevector_post_measure_nondet(self): """Test snapshot statevector after non-deterministic final measurement""" shots = 100 label = "snap" counts_targets = snapshot_state_counts_nondeterministic(shots) statevec_targets = snapshot_state_post_measure_statevector_nondeterministic( ) circuits = snapshot_state_circuits_nondeterministic(label, 'statevector', post_measure=True) qobj = assemble(circuits, self.SIMULATOR, memory=True, shots=shots) job = self.SIMULATOR.run(qobj, backend_options=self.BACKEND_OPTS) method = self.BACKEND_OPTS.get('method', 'automatic') if method not in QasmSnapshotStatevectorTests.SUPPORTED_QASM_METHODS: self.assertRaises(AerError, job.result) else: result = job.result() self.is_completed(result) self.compare_counts(result, circuits, counts_targets, delta=0.2 * shots) # Check snapshots for i, circuit in enumerate(circuits): data = result.data(circuit) snaps = self.statevector_snapshots(data, label) for j, mem in enumerate(data['memory']): target = statevec_targets[i].get(mem) self.assertTrue(np.allclose(snaps[j], target))