text: """
  Copyright (c) Facebook, Inc. and its affiliates.
  
  This source code is licensed under the MIT license found in the
  LICENSE file in the root directory of this source tree.
  """
  import h5py
  import torch
  import matplotlib.plt as plt
  
  def save_reconstructions(reconstructions, out_dir):
      """
      Saves the reconstructions from a model into h5 files that is appropriate for submission
      to the leaderboard.
  
      Args:
          reconstructions (dict[str, np.array]): A dictionary mapping input filenames to
              corresponding reconstructions (of shape num_slices x height x width).
          out_dir (pathlib.Path): Path to the output directory where the reconstructions
              should be saved.
      """
      out_dir.mkdir(exist_ok=True)
      for fname, recons in reconstructions.items():
          with h5py.File(out_dir / fname, 'w') as f:
              f.create_dataset('reconstruction', data=recons)
  
  
  def tensor_to_complex_np(data):
      """
      Converts a complex torch tensor to numpy array.
      Args:
          data (torch.Tensor): Input data to be converted to numpy.
  
      Returns:
          np.array: Complex numpy version of data
      """
      data = data.numpy()
      return data[..., 0] + 1j * data[..., 1]
  
  
  def print_complex_kspace_tensor(k_space):
      return torch.log(torch.sqrt(k_space[:, :, 0] ** 2 + k_space[:, :, 1] ** 2) + 1e-9)
  
  
  def print_complex_image_tensor(image):
      return torch.sqrt(image[:, :, 0] ** 2 + image[:, :, 1] ** 2)
  
  def print_trajectory(model):
      plt.imshow(model.return_trajectory_matrix(), cmap='gray')
      plt.title('the trajectory found')
      plt.show()