class_docstr: Test that the sample_state function works as expected
class_docstr_tok: ["Test","that","the","sample_state","function","works","as","expected"]
docstr: Tests that sample_state works as expected with many wires, and with re-ordering.
docstr_tok: ["Tests","that","sample_state","works","as","expected","with","many","wires",",","and","with","re-ordering","."]
code: def test_sample_state_many_wires(self, num_wires):
      """Tests that sample_state works as expected with many wires, and with re-ordering."""
      shots = 10000
      shape = (2,) * num_wires
      flat_state = np.arange(1, 2**num_wires + 1, dtype=np.float64)
      original_norm = np.linalg.norm(flat_state)
      flat_state /= original_norm
      state = flat_state.reshape(shape)
      expected_probs = (
          np.real(flat_state) ** 2 + np.imag(flat_state) ** 2
      )
  
      ordered_samples = sample_state(state, shots)
      ordered_probs = samples_to_probs(ordered_samples, num_wires)
      assert np.allclose(
          ordered_probs, expected_probs, atol=APPROX_ATOL
      )
  
      random_wires = list(range(num_wires))
      shuffle(random_wires)
      random_samples = sample_state(state, shots, wires=random_wires)
      random_probs = samples_to_probs(random_samples, num_wires)
  
      reordered_probs = (
          ordered_probs.reshape(shape).transpose(random_wires).flatten()
      )
      assert np.allclose(
          reordered_probs, random_probs, atol=APPROX_ATOL
      )
  
imports: from random import shuffle
  import pytest
  import numpy
  import pennylane
  from pennylane.devices.qubit import simulate
  from pennylane.devices.qubit.simulate import _FlexShots
  from pennylane.devices.qubit import sample_state, measure_with_samples
  from pennylane.devices.qubit.sampling import _sample_state_jax
  from pennylane.measurements import Shots
label_desc: Use image node_id 9 for calling the TestSampleState obj's underlying member method code with example usage: obj.test_sample_state_many_wires(num_wires) without return types