code: def test_io_forward(tmp_path):
      """Test IO for forward solutions."""
      # do extensive tests with MEEG + grad
      n_channels, n_src = 366, 108
      fwd = read_forward_solution(fname_meeg_grad)
      assert isinstance(fwd, Forward)
      fwd = read_forward_solution(fname_meeg_grad)
      fwd = convert_forward_solution(fwd, surf_ori=True)
      leadfield = fwd["sol"]["data"]
      assert_equal(leadfield.shape, (n_channels, n_src))
      assert_equal(len(fwd["sol"]["row_names"]), n_channels)
      fname_temp = tmp_path / "test-fwd.fif"
      with pytest.warns(RuntimeWarning, match="stored on disk"):
          write_forward_solution(fname_temp, fwd, overwrite=True)
  
      fwd = read_forward_solution(fname_meeg_grad)
      fwd = convert_forward_solution(fwd, surf_ori=True)
      fwd_read = read_forward_solution(fname_temp)
      fwd_read = convert_forward_solution(fwd_read, surf_ori=True)
      leadfield = fwd_read["sol"]["data"]
      assert_equal(leadfield.shape, (n_channels, n_src))
      assert_equal(len(fwd_read["sol"]["row_names"]), n_channels)
      assert_equal(len(fwd_read["info"]["chs"]), n_channels)
      assert "dev_head_t" in fwd_read["info"]
      assert "mri_head_t" in fwd_read
      assert_array_almost_equal(
          fwd["sol"]["data"], fwd_read["sol"]["data"]
      )
  
      fwd = read_forward_solution(fname_meeg)
      fwd = convert_forward_solution(
          fwd, surf_ori=True, force_fixed=True, use_cps=False
      )
      with pytest.warns(RuntimeWarning, match="stored on disk"):
          write_forward_solution(fname_temp, fwd, overwrite=True)
      fwd_read = read_forward_solution(fname_temp)
      fwd_read = convert_forward_solution(
          fwd_read, surf_ori=True, force_fixed=True, use_cps=False
      )
      assert repr(fwd_read)
      assert isinstance(fwd_read, Forward)
      assert is_fixed_orient(fwd_read)
      assert_forward_allclose(fwd, fwd_read)
  
      fwd = convert_forward_solution(
          fwd, surf_ori=True, force_fixed=True, use_cps=True
      )
      leadfield = fwd["sol"]["data"]
      assert_equal(leadfield.shape, (n_channels, 1494 / 3))
      assert_equal(len(fwd["sol"]["row_names"]), n_channels)
      assert_equal(len(fwd["info"]["chs"]), n_channels)
      assert "dev_head_t" in fwd["info"]
      assert "mri_head_t" in fwd
      assert fwd["surf_ori"]
      with pytest.warns(RuntimeWarning, match="stored on disk"):
          write_forward_solution(fname_temp, fwd, overwrite=True)
      fwd_read = read_forward_solution(fname_temp)
      fwd_read = convert_forward_solution(
          fwd_read, surf_ori=True, force_fixed=True, use_cps=True
      )
      assert repr(fwd_read)
      assert isinstance(fwd_read, Forward)
      assert is_fixed_orient(fwd_read)
      assert_forward_allclose(fwd, fwd_read)
  
      fwd = read_forward_solution(fname_meeg_grad)
      fwd = convert_forward_solution(
          fwd, surf_ori=True, force_fixed=True, use_cps=True
      )
      leadfield = fwd["sol"]["data"]
      assert_equal(leadfield.shape, (n_channels, n_src / 3))
      assert_equal(len(fwd["sol"]["row_names"]), n_channels)
      assert_equal(len(fwd["info"]["chs"]), n_channels)
      assert "dev_head_t" in fwd["info"]
      assert "mri_head_t" in fwd
      assert fwd["surf_ori"]
      with pytest.warns(RuntimeWarning, match="stored on disk"):
          write_forward_solution(fname_temp, fwd, overwrite=True)
      fwd_read = read_forward_solution(fname_temp)
      fwd_read = convert_forward_solution(
          fwd_read, surf_ori=True, force_fixed=True, use_cps=True
      )
      assert repr(fwd_read)
      assert isinstance(fwd_read, Forward)
      assert is_fixed_orient(fwd_read)
      assert_forward_allclose(fwd, fwd_read)
  
      # test warnings on bad filenames
      fwd = read_forward_solution(fname_meeg_grad)
      fwd_badname = tmp_path / "test-bad-name.fif.gz"
      with pytest.warns(RuntimeWarning, match="end with"):
          write_forward_solution(fwd_badname, fwd)
      with pytest.warns(RuntimeWarning, match="end with"):
          read_forward_solution(fwd_badname)
  
      fwd = read_forward_solution(fname_meeg)
      write_forward_solution(fname_temp, fwd, overwrite=True)
      fwd_read = read_forward_solution(fname_temp)
      assert_forward_allclose(fwd, fwd_read)
  
      h5py = pytest.importorskip("h5py")
      pytest.importorskip("h5io")
      fname_h5 = fname_temp.with_suffix(".h5")
      fwd.save(fname_h5)
      with h5py.File(fname_h5, "r"):
          pass  # just checks for hdf5-ness
      fwd_read = read_forward_solution(fname_h5)
      assert_forward_allclose(fwd, fwd_read)
  
imports: import gc
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import SourceEstimate, VectorSourceEstimate, apply_forward, apply_forward_raw, average_forward_solutions, convert_forward_solution, pick_types_forward, read_evokeds, read_forward_solution, write_forward_solution
  from mne._fiff.pick import pick_channels_forward
  from mne.channels import equalize_channels
  from mne.datasets import testing
  from mne.forward import Forward, compute_depth_prior, compute_orient_prior, is_fixed_orient, restrict_forward_to_label, restrict_forward_to_stc
  from mne.io import read_info
  from mne.label import read_label
  from mne.utils import requires_mne, run_subprocess
label_desc: Use image node_id 3 for calling a global function with example usage: test_io_forward(tmp_path) without return types