class_docstr: Test Stable Diffusion text-to-image pipeline for:
  
  - PyTorch to CoreML conversion via coremltools
  - Speed of CoreML runtime across several compute units
  - Integration with `diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.py`
  - Efficacy of the safety_checker
  - Affinity of the generated image with the original prompt via CLIP score
  - The bridge between Python and Swift CLI
  - The signal parity of Swift CLI generated image with that of Python CLI
docstr: Tests:
  - The bridge between Python and Swift CLI
  - The signal parity of Swift CLI generated image with that of Python CLI
docstr_tok: ["Tests",":","-","The","bridge","between","Python","and","Swift","CLI","-","The","signal","parity","of","Swift","CLI","generated","image","with","that","of","Python","CLI"]
code: def test_swift_cli_image_generation(self):
      """Tests:
      - The bridge between Python and Swift CLI
      - The signal parity of Swift CLI generated image with that of Python CLI
      """
      # coremltools to Core ML compute unit mapping
      compute_unit_map = {
          "ALL": "all",
          "CPU_AND_GPU": "cpuAndGPU",
          "CPU_AND_NE": "cpuAndNeuralEngine",
      }
  
      # Prepare resources for Swift CLI
      resources_dir = torch2coreml.bundle_resources_for_swift_cli(
          self.cli_args
      )
      logger.info("Bundled resources for Swift CLI")
  
      # Execute image generation with Swift CLI
      # Note: First time takes ~5 minutes due to project building and so on
      cmd = " ".join(
          [
              f'swift run StableDiffusionSample "{TEST_PROMPT}"',
              f"--resource-path {resources_dir}",
              f"--seed {TEST_SEED}",
              f"--output-path {self.cli_args.o}",
              f"--compute-units {compute_unit_map[TEST_COMPUTE_UNIT[-1]]}",
          ]
      )
      logger.info(f"Executing `{cmd}`")
      os.system(cmd)
      logger.info(f"Image generation with Swift CLI is complete")
  
      # Load Swift CLI generated image
      swift_cli_image = Image.open(
          os.path.join(
              self.cli_args.o,
              "_".join(TEST_PROMPT.rsplit(" "))
              + "."
              + str(TEST_SEED)
              + ".final.png",
          )
      )
  
      # Load Python CLI (pipeline.py) generated image
      python_cli_image = Image.open(
          pipeline.get_image_path(
              self.cli_args,
              prompt=TEST_PROMPT,
              compute_unit=TEST_COMPUTE_UNIT[-1],
          )
      )
  
      # Compute signal parity
      swift2torch_psnr = torch2coreml.report_correctness(
          np.array(swift_cli_image.convert("RGB")),
          np.array(python_cli_image.convert("RGB")),
          "Swift CLI and Python CLI generated images",
      )
      self.assertGreater(
          swift2torch_psnr, torch2coreml.ABSOLUTE_MIN_PSNR
      )
  
imports: import argparse
  import contextlib
  import coremltools
  from diffusers import StableDiffusionPipeline
  import json
  import logging
  import numpy
  import os
  import unittest
  from PIL import Image
  from statistics import median
  import tempfile
  import time
  import torch
  from python_coreml_stable_diffusion import torch2coreml, pipeline, coreml_model
label_desc: Use image node_id 7 for calling the TestStableDiffusionForTextToImage obj's underlying member method code with example usage: obj.test_swift_cli_image_generation() without return types