class_docstr: Tests for the expand_matrix helper function.
class_docstr_tok: ["Tests","for","the","expand_matrix","helper","function","."]
docstr: Test that a broadcasted 2 qubit gate on consecutive wires correctly
  expands to 4 qubits.
docstr_tok: ["Test","that","a","broadcasted","2","qubit","gate","on","consecutive","wires","correctly","expands","to","4","qubits","."]
code: def test_expand_two_consecutive_wires_broadcasted(self, tol):
      """Test that a broadcasted 2 qubit gate on consecutive wires correctly
      expands to 4 qubits."""
      U2 = np.array(
          [[0, 1, 1, 1], [1, 0, 1, -1], [1, -1, 0, 1], [1, 1, -1, 0]]
      ) / np.sqrt(3)
      U2 = np.tensordot([2.31, 1.53, 0.7 - 1.9j], U2, axes=0)
  
      # test applied to wire 0+1
      res = qml.math.expand_matrix(U2, [0, 1], [0, 1, 2, 3])
      expected = np.kron(np.kron(U2, I_broadcasted), I_broadcasted)
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      # test applied to wire 1+2
      res = qml.math.expand_matrix(U2, [1, 2], [0, 1, 2, 3])
      expected = np.kron(np.kron(I_broadcasted, U2), I_broadcasted)
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      # test applied to wire 2+3
      res = qml.math.expand_matrix(U2, [2, 3], [0, 1, 2, 3])
      expected = np.kron(np.kron(I_broadcasted, I_broadcasted), U2)
      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 16 for calling the TestExpandMatrix obj's underlying member method code with example usage: obj.test_expand_two_consecutive_wires_broadcasted(tol) without return types