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 non-ascending
  wires correctly expands to 4 qubits
docstr_tok: ["Test","that","a","broadcasted","3","qubit","gate","on","non-consecutive","non-ascending","wires","correctly","expands","to","4","qubits"]
code: def test_expand_three_nonconsecutive_nonascending_wires_broadcasted(
      self, tol
  ):
      """Test that a broadcasted 3 qubit gate on non-consecutive non-ascending
      wires correctly expands to 4 qubits"""
      # test applied to wire 3, 1, 2
      res = qml.math.expand_matrix(
          Toffoli_broadcasted, [3, 1, 2], [0, 1, 2, 3]
      )
      # change the control qubit on the Toffoli gate
      rows = [0, 4, 1, 5, 2, 6, 3, 7]
      Toffoli_broadcasted_perm = Toffoli_broadcasted[:, :, rows][
          :, rows
      ]
      expected = np.kron(I_broadcasted, Toffoli_broadcasted_perm)
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      # test applied to wire 3, 0, 2
      res = qml.math.expand_matrix(
          Toffoli_broadcasted, [3, 0, 2], [0, 1, 2, 3]
      )
      # change the control qubit on the Toffoli gate
      expected = np.tensordot(
          np.tensordot(
              np.kron(SWAP, II),
              np.kron(I_broadcasted, Toffoli_broadcasted_perm),
              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)
  
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 24 for calling the TestExpandMatrix obj's underlying member method code with example usage: obj.test_expand_three_nonconsecutive_nonascending_wires_broadcasted(tol) without return types