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

small fixes to allow initial density matrix for faster noisy sampling with cirq #84

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions qsdk/backendbuddy/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down