From b0f987ad3ede80da22bc955054a2fdbb37b6afde Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 5 Nov 2021 10:01:57 -0400 Subject: [PATCH] small fixes to allow initial density matrix for faster noisy sampling with cirq --- qsdk/backendbuddy/simulator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qsdk/backendbuddy/simulator.py b/qsdk/backendbuddy/simulator.py index 8b6b8e3ab..2428c9432 100644 --- a/qsdk/backendbuddy/simulator.py +++ b/qsdk/backendbuddy/simulator.py @@ -108,8 +108,9 @@ def simulate(self, source_circuit, return_statevector=False, initial_statevector if source_circuit.width == 0: raise ValueError("Cannot simulate an empty circuit (e.g identity unitary) with unknown number of qubits.") - # If the unitary is the identity (no gates), no need for simulation: return all-zero state - if source_circuit.size == 0: + # If the unitary is the identity (no gates) and no noise model, no need for simulation: + # return all-zero state or sample from statevector + if source_circuit.size == 0 and not self._noise_model: if initial_statevector is not None: statevector = initial_statevector frequencies = self._statevector_to_frequencies(initial_statevector) @@ -392,7 +393,7 @@ def _get_expectation_value_from_frequencies(self, qubit_operator, state_prep_cir n_qubits = state_prep_circuit.width if not self.statevector_available or state_prep_circuit.is_mixed_state or self._noise_model: initial_circuit = state_prep_circuit - if initial_statevector is not None: + if initial_statevector is not None and not self.statevector_available: raise ValueError(f'Backend {self._target} does not support statevectors') else: updated_statevector = initial_statevector