class_docstr: Tests for the expand_matrix helper function.
class_docstr_tok: ["Tests","for","the","expand_matrix","helper","function","."]
docstr: Test that a broadcasted 3 qubit gate on non-consecutive but ascending
  wires correctly expands to 4 qubits.
docstr_tok: ["Test","that","a","broadcasted","3","qubit","gate","on","non-consecutive","but","ascending","wires","correctly","expands","to","4","qubits","."]
code: def test_expand_three_nonconsecutive_ascending_wires_broadcasted(
      self, tol
  ):
      """Test that a broadcasted 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_broadcasted[:1], [0, 2, 3], [0, 1, 2, 3]
      )
      expected = np.tensordot(
          np.tensordot(
              np.kron(SWAP, II),
              np.kron(I_broadcasted, Toffoli_broadcasted[:1]),
              axes=[[1], [1]],
          ),
          np.kron(SWAP, II),
          axes=[[2], [0]],
      )
      expected = np.moveaxis(expected, 0, -2)
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      # test applied to wire 0,1,3
      res = qml.math.expand_matrix(
          Toffoli_broadcasted, [0, 1, 3], [0, 1, 2, 3]
      )
      expected = np.tensordot(
          np.tensordot(
              np.kron(II, SWAP),
              np.kron(Toffoli_broadcasted, I_broadcasted),
              axes=[[1], [1]],
          ),
          np.kron(II, SWAP),
          axes=[[2], [0]],
      )
      expected = np.moveaxis(expected, 0, -2)
      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 22 for calling the TestExpandMatrix obj's underlying member method code with example usage: obj.test_expand_three_nonconsecutive_ascending_wires_broadcasted(tol) without return types