Skip to content

Commit

Permalink
factorize inplace while removing qubit in density matrix simulation s…
Browse files Browse the repository at this point in the history
…tate
  • Loading branch information
sanuj committed Aug 27, 2023
1 parent 7a6bc5c commit 0764095
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cirq-core/cirq/sim/density_matrix_simulation_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ def remove_qubits(self, qubits: Sequence['cirq.Qid']):
ret = super().remove_qubits(qubits)
if ret is not NotImplemented:
return ret
extracted, remainder = self.factor(qubits)
extracted, remainder = self.factor(qubits, inplace=True)
remainder._state._density_matrix *= extracted._state._density_matrix.reshape(-1)[0]
return remainder

def _act_on_fallback_(
self, action: Any, qubits: Sequence['cirq.Qid'], allow_decompose: bool = True
) -> bool:
Expand Down
17 changes: 2 additions & 15 deletions cirq-core/cirq/sim/simulation_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,7 @@ def test_delegating_gate_unitary(exp):
assert_test_circuit_for_sv_simulator(test_circuit, control_circuit)


@pytest.mark.parametrize('exp', np.linspace(0, 2 * np.pi, 1))
def test_delegating_gate_channel_sv(exp):
q = cirq.LineQubit(0)

test_circuit = cirq.Circuit()
test_circuit.append(cirq.H(q))
test_circuit.append(DelegatingAncillaZ(exp, True).on(q))

control_circuit = cirq.Circuit(cirq.H(q))
control_circuit.append(cirq.ZPowGate(exponent=exp).on(q))

assert_test_circuit_for_sv_simulator(test_circuit, control_circuit)


@pytest.mark.parametrize('exp', np.linspace(0, 2 * np.pi, 1))
@pytest.mark.parametrize('exp', np.linspace(0, 2 * np.pi, 10))
def test_delegating_gate_channel(exp):
q = cirq.LineQubit(0)

Expand All @@ -178,6 +164,7 @@ def test_delegating_gate_channel(exp):
control_circuit = cirq.Circuit(cirq.H(q))
control_circuit.append(cirq.ZPowGate(exponent=exp).on(q))

assert_test_circuit_for_sv_simulator(test_circuit, control_circuit)
assert_test_circuit_for_dm_simulator(test_circuit, control_circuit)


Expand Down

0 comments on commit 0764095

Please sign in to comment.