class_docstr: Tests for the expand_matrix helper function.
class_docstr_tok: ["Tests","for","the","expand_matrix","helper","function","."]
docstr: Test that a 3 qubit gate on non-consecutive but ascending
  wires correctly expands to 4 qubits.
docstr_tok: ["Test","that","a","3","qubit","gate","on","non-consecutive","but","ascending","wires","correctly","expands","to","4","qubits","."]
code: def test_expand_three_nonconsecutive_ascending_wires(self, tol):
      """Test that a 3 qubit gate on non-consecutive but ascending
      wires correctly expands to 4 qubits."""
      # test applied to wire 0,2,3
      res = qml.math.expand_matrix(Toffoli, [0, 2, 3], [0, 1, 2, 3])
      expected = (
          np.kron(SWAP, II) @ np.kron(I, Toffoli) @ np.kron(SWAP, II)
      )
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      # test applied to wire 0,1,3
      res = qml.math.expand_matrix(Toffoli, [0, 1, 3], [0, 1, 2, 3])
      expected = (
          np.kron(II, SWAP) @ np.kron(Toffoli, I) @ np.kron(II, SWAP)
      )
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
imports: from functools import reduce
  import numpy
  import pytest
  from gate_data import CNOT, II, SWAP, I, Toffoli
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 21 for calling the TestExpandMatrix obj's underlying member method code with example usage: obj.test_expand_three_nonconsecutive_ascending_wires(tol) without return types