diff --git a/src/smappy/calibrate/psf_window.py b/src/smappy/calibrate/psf_window.py index a1421b05..85bfcbc7 100644 --- a/src/smappy/calibrate/psf_window.py +++ b/src/smappy/calibrate/psf_window.py @@ -66,6 +66,27 @@ def torch_missing(): f"into this Python; or, in a terminal:\n{shell_line(torch_install.command())}") +def torch_slow(): + """What the window says when torch works but leaves the NVIDIA card unused (`torch_install.replacement`), + with the command that brings the card's build; None otherwise.""" + from .. import torch_install + reason = torch_install.replacement() + if reason is None: + return None + return (f"{reason}. Install PyTorch replaces it with the build for the card; or, in a terminal:\n" + f"{shell_line(torch_install.command(replace=True))}") + + +def learning_device() -> str: + """"on the graphics card (…)", "on Apple's GPU" or "on the CPU" (`uipsf.device.describe`); empty where torch + cannot be loaded, which the notice says already.""" + try: + from uipsf.device import describe + return describe() + except Exception: + return "" + + def shell_line(parts, windows: Optional[bool] = None) -> str: """``parts`` as a line to paste into a terminal. @@ -351,6 +372,7 @@ def choice(label, items, slot): self.install_button.clicked.connect(self.install_torch) layout.addWidget(self.install_button) self._installer = None + self._device = None # where the pupil model learns, found once (`learning_device`) self.detect_button = QPushButton("Detect beads") self.detect_button.setToolTip("find the beads, ring them on the Stacks page and say how long " @@ -443,10 +465,12 @@ def _show_method(self) -> None: form.set_shown({name: reads["averaging"] for name in AVERAGE_ONLY if name in shared}) pupil = self.method.key in ("pupil", "insitu", "molecules") or getattr(self.method, "needs_torch", False) missing = torch_missing() - self.notice.setText(missing or "") - self.notice.setVisible(pupil and missing is not None) - # shown only while torch is missing or too old: nothing to press once it is right - self.install_button.setVisible(pupil and (missing is not None or self._installer is not None)) + # a CPU build on a machine with an NVIDIA card works, slowly: said and offered, never blocking + note = missing or torch_slow() + self.notice.setText(note or "") + self.notice.setVisible(pupil and note is not None) + # shown only while torch is missing, too old or the CPU's beside a card: nothing to press once it is right + self.install_button.setVisible(pupil and (note is not None or self._installer is not None)) self.stop_button.setVisible(pupil) self.browse_button.setVisible(self.method.has_stack) self.toggle_button.setVisible(getattr(self.method, "marks", True)) @@ -1073,7 +1097,13 @@ def _show_detected_text(self) -> None: """The detection's line, with the time calibrating the beads as marked takes where the method knows it (`detected_text`): excluding beads shortens it.""" text_of = getattr(self.method, "detected_text", None) - self.found_label.setText(text_of(self.detected, self.marks) if text_of else self.detected.text) + text = text_of(self.detected, self.marks) if text_of else self.detected.text + if self.method.key in ("pupil", "insitu", "molecules") or getattr(self.method, "needs_torch", False): + if self._device is None: + self._device = learning_device() + if self._device: + text += f"; learnt {self._device}" + self.found_label.setText(text) def detect(self) -> None: """Find the beads and say how many and how long calibrating them will take; nothing is learnt.""" @@ -1456,7 +1486,8 @@ def install_torch(self) -> None: self._installer.kill() return from .. import torch_install - program, *arguments = torch_install.command() + self._replacing = torch_install.cpu_build_on_nvidia() + program, *arguments = torch_install.command(replace=self._replacing) process = QProcess(self) process.setProcessChannelMode(QProcess.MergedChannels) process.readyReadStandardOutput.connect(self._installer_output) @@ -1478,8 +1509,13 @@ def _installer_finished(self, code, _status=None) -> None: self._installer = None self.install_button.setText("Install PyTorch") missing = torch_missing() - self.status_bar.showMessage("PyTorch is installed: the pupil model is ready" if missing is None - else f"the install stopped (exit code {code}); {missing.splitlines()[0]}") + if missing is not None: + self.status_bar.showMessage(f"the install stopped (exit code {code}); {missing.splitlines()[0]}") + elif getattr(self, "_replacing", False) and "torch" in sys.modules: + # the CPU build is loaded in this process already: the card's is used from the next start + self.status_bar.showMessage("PyTorch for the card is installed: restart SMAPpy to learn on it") + else: + self.status_bar.showMessage("PyTorch is installed: the pupil model is ready") self._show_method() # ------------------------------------------------------------- saving diff --git a/src/smappy/docs/panels/PSF calibration.md b/src/smappy/docs/panels/PSF calibration.md index 7b40b44c..9f5de39d 100644 --- a/src/smappy/docs/panels/PSF calibration.md +++ b/src/smappy/docs/panels/PSF calibration.md @@ -2,7 +2,7 @@ title: PSF calibration summary: Makes the PSF calibration the Spline 3D fitters read, from beads in a z stack, from single molecules on the coverslip in a z stack, or in situ from the blinking molecules of a measurement -- the bead average or a physical model of the microscope's pupil learnt with uiPSF v2 -- or, as a fourth, the curves of an elliptical Gaussian's widths in z that Astigmatic z reads, or, in the 4Pi mode, a 4Pi model for Spline 4Pi from 4Pi bead scans, and shows what each found and how well it fits. widget: smappy.calibrate.psf_window.PSFCalibrationWindow -covers: [smappy.calibrate.pupil.half_split_uncertainty, smappy.calibrate.pupil.fit_quality, smappy.calibrate.plots.draw_pupil_fit_quality, smappy.torch_install.command, smappy.calibrate.psf_methods.BeadAverage, smappy.calibrate.psf_methods.PupilModel, smappy.calibrate.pupil.run_calibration, smappy.calibrate.pupil.bead_rois, smappy.calibrate.pupil.single_rois, smappy.calibrate.pupil.dual_rois, smappy.calibrate.pupil.spline_calibration, smappy.calibrate.pupil.dual_calibration, smappy.calibrate.pupil.save, smappy.calibrate.pupil.OpticsSettings, smappy.calibrate.pupil.BeadSettings, smappy.calibrate.pupil.learns_tilt, uipsf.diagnostics.figures.coverslip_tilt, smappy.calibrate.core.find_stack_beads, smappy.calibrate.psf_window.PSFCalibrationWindow, smappy.calibrate.pupil.estimate_seconds, smappy.calibrate.psf_methods.LearningProgress, smappy.calibrate.model_views.average_views, smappy.calibrate.model_views.pupil_views, smappy.calibrate.model_views.draw_model_vs_data, smappy.calibrate.model_views.planes, smappy.calibrate.stack_browser.StackBrowser, smappy.calibrate.stack_view.StackViewer, smappy.calibrate.pupil.covered_z_nm, smappy.calibrate.psf_methods.InSitu, smappy.calibrate.psf_methods.EllipticalGaussian, smappy.calibrate.elliptical.bead_widths, smappy.calibrate.elliptical.align_beads, smappy.calibrate.elliptical.calibrate_widths, smappy.calibrate.elliptical.save_path, smappy.calibrate.elliptical.EllipticalCalibrationSettings, smappy.calibrate.insitu_run.run_insitu, smappy.calibrate.insitu_run.movie_rois, smappy.calibrate.insitu_run.block_order, smappy.calibrate.insitu_run.enough, smappy.calibrate.insitu_run.start_astigmatism, smappy.calibrate.insitu_run.held_pupil, smappy.microscope_db.gamma_of, smappy.calibrate.insitu.quotas, smappy.calibrate.insitu_run.insitu_spline, smappy.calibrate.insitu_run.InSituModelSettings, smappy.calibrate.insitu.InSituSettings, smappy.calibrate.insitu.select, smappy.calibrate.insitu_views.draw_z_bins, smappy.calibrate.insitu_views.draw_rounds, smappy.calibrate.insitu_views.model_vs_data, uipsf.workflows.insitu_rounds.calibrate_insitu, uipsf.workflows.insitu_rounds.coverslip_edge, uipsf.workflows.insitu_rounds.focus_from_data, uipsf.workflows.insitu.twin, smappy.calibrate.psf_methods.FourPiPupil, smappy.calibrate.psf_methods.FourPiAverage, smappy.calibrate.psf_methods.for_mode, smappy.calibrate.fourpi_beads.average_model, smappy.fourpi.iab_from_beads, smappy.calibrate.fourpi_beads.scan_beads, smappy.calibrate.fourpi_beads.read_scan, smappy.calibrate.fourpi_beads.scan_layout, smappy.calibrate.fourpi_beads.scan_step_nm, smappy.calibrate.fourpi_beads.bead_fits, smappy.calibrate.fourpi_beads.FourPiBeadSettings, smappy.calibrate.psf_methods.MoleculeStack, smappy.calibrate.psf_methods.MoleculeElliptical, smappy.calibrate.psf_methods.methods_of, smappy.calibrate.molecule_stack.molecule_rois, smappy.calibrate.molecule_stack.read_file, smappy.calibrate.molecule_stack.stage_z_um, smappy.calibrate.molecule_stack.split_sweeps, smappy.calibrate.molecule_stack.width_curve, smappy.calibrate.molecule_stack.focus_of, smappy.calibrate.molecule_stack.detect, smappy.calibrate.molecule_stack.select, smappy.calibrate.molecule_stack.draw, smappy.calibrate.molecule_stack.illumination_radius, smappy.calibrate.molecule_stack.molecule_widths, smappy.calibrate.molecule_stack.MoleculeStackSettings, smappy.calibrate.molecule_dual.dual_molecule_rois, smappy.calibrate.molecule_dual.registration_from_molecules, smappy.calibrate.molecule_stack_run.run_molecule_stack, smappy.calibrate.molecule_stack_run.spline_range, smappy.calibrate.molecule_stack_run.estimate_seconds, smappy.calibrate.molecule_views.draw_selection, smappy.calibrate.molecule_views.draw_z_check, smappy.calibrate.molecule_views.draw_foci, smappy.calibrate.molecule_views.model_vs_data, uipsf.workflows.molecule_stack.learn_molecule_stack, uipsf.workflows.molecule_stack.z_check, uipsf.workflows.molecule_stack.molecule_chunk, uipsf.model.geometry.CoverslipStackGeometry] +covers: [smappy.calibrate.pupil.half_split_uncertainty, smappy.calibrate.pupil.fit_quality, smappy.calibrate.plots.draw_pupil_fit_quality, smappy.torch_install.command, smappy.torch_install.cpu_build_on_nvidia, uipsf.device.describe, smappy.calibrate.psf_methods.BeadAverage, smappy.calibrate.psf_methods.PupilModel, smappy.calibrate.pupil.run_calibration, smappy.calibrate.pupil.bead_rois, smappy.calibrate.pupil.single_rois, smappy.calibrate.pupil.dual_rois, smappy.calibrate.pupil.spline_calibration, smappy.calibrate.pupil.dual_calibration, smappy.calibrate.pupil.save, smappy.calibrate.pupil.OpticsSettings, smappy.calibrate.pupil.BeadSettings, smappy.calibrate.pupil.learns_tilt, uipsf.diagnostics.figures.coverslip_tilt, smappy.calibrate.core.find_stack_beads, smappy.calibrate.psf_window.PSFCalibrationWindow, smappy.calibrate.pupil.estimate_seconds, smappy.calibrate.psf_methods.LearningProgress, smappy.calibrate.model_views.average_views, smappy.calibrate.model_views.pupil_views, smappy.calibrate.model_views.draw_model_vs_data, smappy.calibrate.model_views.planes, smappy.calibrate.stack_browser.StackBrowser, smappy.calibrate.stack_view.StackViewer, smappy.calibrate.pupil.covered_z_nm, smappy.calibrate.psf_methods.InSitu, smappy.calibrate.psf_methods.EllipticalGaussian, smappy.calibrate.elliptical.bead_widths, smappy.calibrate.elliptical.align_beads, smappy.calibrate.elliptical.calibrate_widths, smappy.calibrate.elliptical.save_path, smappy.calibrate.elliptical.EllipticalCalibrationSettings, smappy.calibrate.insitu_run.run_insitu, smappy.calibrate.insitu_run.movie_rois, smappy.calibrate.insitu_run.block_order, smappy.calibrate.insitu_run.enough, smappy.calibrate.insitu_run.start_astigmatism, smappy.calibrate.insitu_run.held_pupil, smappy.microscope_db.gamma_of, smappy.calibrate.insitu.quotas, smappy.calibrate.insitu_run.insitu_spline, smappy.calibrate.insitu_run.InSituModelSettings, smappy.calibrate.insitu.InSituSettings, smappy.calibrate.insitu.select, smappy.calibrate.insitu_views.draw_z_bins, smappy.calibrate.insitu_views.draw_rounds, smappy.calibrate.insitu_views.model_vs_data, uipsf.workflows.insitu_rounds.calibrate_insitu, uipsf.workflows.insitu_rounds.coverslip_edge, uipsf.workflows.insitu_rounds.focus_from_data, uipsf.workflows.insitu.twin, smappy.calibrate.psf_methods.FourPiPupil, smappy.calibrate.psf_methods.FourPiAverage, smappy.calibrate.psf_methods.for_mode, smappy.calibrate.fourpi_beads.average_model, smappy.fourpi.iab_from_beads, smappy.calibrate.fourpi_beads.scan_beads, smappy.calibrate.fourpi_beads.read_scan, smappy.calibrate.fourpi_beads.scan_layout, smappy.calibrate.fourpi_beads.scan_step_nm, smappy.calibrate.fourpi_beads.bead_fits, smappy.calibrate.fourpi_beads.FourPiBeadSettings, smappy.calibrate.psf_methods.MoleculeStack, smappy.calibrate.psf_methods.MoleculeElliptical, smappy.calibrate.psf_methods.methods_of, smappy.calibrate.molecule_stack.molecule_rois, smappy.calibrate.molecule_stack.read_file, smappy.calibrate.molecule_stack.stage_z_um, smappy.calibrate.molecule_stack.split_sweeps, smappy.calibrate.molecule_stack.width_curve, smappy.calibrate.molecule_stack.focus_of, smappy.calibrate.molecule_stack.detect, smappy.calibrate.molecule_stack.select, smappy.calibrate.molecule_stack.draw, smappy.calibrate.molecule_stack.illumination_radius, smappy.calibrate.molecule_stack.molecule_widths, smappy.calibrate.molecule_stack.MoleculeStackSettings, smappy.calibrate.molecule_dual.dual_molecule_rois, smappy.calibrate.molecule_dual.registration_from_molecules, smappy.calibrate.molecule_stack_run.run_molecule_stack, smappy.calibrate.molecule_stack_run.spline_range, smappy.calibrate.molecule_stack_run.estimate_seconds, smappy.calibrate.molecule_views.draw_selection, smappy.calibrate.molecule_views.draw_z_check, smappy.calibrate.molecule_views.draw_foci, smappy.calibrate.molecule_views.model_vs_data, uipsf.workflows.molecule_stack.learn_molecule_stack, uipsf.workflows.molecule_stack.z_check, uipsf.workflows.molecule_stack.molecule_chunk, uipsf.model.geometry.CoverslipStackGeometry] --- ## What it does @@ -83,7 +83,12 @@ with one too old, *Install PyTorch* installs the right build for the computer (for Apple's GPU, an NVIDIA card or the CPU) into the Python running SMAPpy; the window also shows the command to type instead. The bead average works without it. It uses the -GPU where PyTorch finds one (NVIDIA, or Apple's). +GPU where PyTorch finds one (NVIDIA, or Apple's), and the line *Detect* writes +says where: *learnt on the graphics card*, *on Apple's GPU* or *on the CPU*. +A PyTorch built for the CPU only on a computer with an NVIDIA card -- a plain +`pip install torch` on Windows brings that one -- works, several times +slower; the window says so and offers *Install PyTorch* to replace it with +the card's build. ## How it works @@ -1266,9 +1271,11 @@ beads can be minutes away. Nothing is saved, and the beads are neither scored nor drawn against the model. ### Install PyTorch -Shown with the pupil model while PyTorch is missing or too old: installs it -into the Python running SMAPpy, with pip's progress in the status line; -pressed again, it stops. The pupil model can be used as soon as it is done. +Shown with the pupil model while PyTorch is missing or too old, or built for +the CPU only beside an NVIDIA card: installs it into the Python running +SMAPpy, with pip's progress in the status line; pressed again, it stops. The +pupil model can be used as soon as it is done -- after replacing a CPU build +once SMAPpy is started again, if a calibration had already loaded the old one. ### Save as... Saves the calibration under another name, or one made with *save model* off. diff --git a/src/smappy/torch_install.py b/src/smappy/torch_install.py index 0f5933ec..a55b808b 100644 --- a/src/smappy/torch_install.py +++ b/src/smappy/torch_install.py @@ -20,6 +20,12 @@ Nothing here imports torch: what is installed is read from its package metadata, so asking costs nothing and an old torch is not loaded into the process before it is replaced. + +**A build for the CPU on a machine with an NVIDIA card** (`cpu_build_on_nvidia`) works, and learns several +times slower without saying so: uipsf takes the card only when torch was built for it (`uipsf.device`). It +happens when torch came from elsewhere than the window -- a plain ``pip install torch`` on Windows, whose PyPI +wheel is CPU only. The window then warns and offers the button again (`replacement`); its command replaces +the build rather than finding the installed version good enough. """ from __future__ import annotations @@ -56,6 +62,38 @@ def problem() -> Optional[str]: return None +def _installed() -> Optional[str]: + from importlib import metadata + try: + return metadata.version("torch") + except metadata.PackageNotFoundError: + return None + + +def cpu_build_on_nvidia(version: Optional[str] = None, system: Optional[str] = None, + nvidia: Optional[bool] = None) -> bool: + """Whether the installed torch is built for the CPU only on a machine with an NVIDIA card (module docstring), + read from its version's local label: PyTorch's CPU index marks its wheels ``+cpu``; on Windows a CUDA build + is always ``+cu…`` (PyPI's wheel, without a label, is CPU only), on Linux PyPI's unlabelled wheel is CUDA's.""" + version = _installed() if version is None else version + system = system or platform.system() + nvidia = has_nvidia() if nvidia is None else nvidia + if not version or not nvidia or system == "Darwin": + return False + label = version.partition("+")[2].lower() + if label == "cpu": + return True + return system == "Windows" and not label.startswith("cu") + + +def replacement() -> Optional[str]: + """What the window says when torch works but leaves the NVIDIA card unused; None when it does not.""" + if problem() is not None or not cpu_build_on_nvidia(): + return None + return (f"PyTorch {_installed()} is built for the CPU only, though this computer has an NVIDIA card: the pupil " + f"model learns on the CPU, several times slower") + + def has_nvidia() -> bool: return shutil.which("nvidia-smi") is not None @@ -84,11 +122,20 @@ def installer(has_pip: Optional[bool] = None, uv: Optional[str] = None) -> List[ def command(system: Optional[str] = None, nvidia: Optional[bool] = None, - start: Optional[List[str]] = None) -> List[str]: - """The install command, as a list for a process, that installs the right torch here.""" + start: Optional[List[str]] = None, replace: bool = False) -> List[str]: + """The install command, as a list for a process, that installs the right torch here. + + ``replace``: a CPU build is there and the card's is wanted (`cpu_build_on_nvidia`). ``--upgrade`` alone + can keep it -- PyPI's unlabelled 2.x sorts below a 2.x+cpu, and an installed version newer than the CUDA + index's is "satisfied" -- so the build is reinstalled from the CUDA index. On Windows without its + dependencies, which a CUDA wheel there shares with the CPU one (it carries CUDA inside); on Linux the CUDA + wheel needs NVIDIA's packages, so only the higher local label (+cu126 above +cpu) moves it.""" system = system or platform.system() nvidia = has_nvidia() if nvidia is None else nvidia pip = (start or installer()) + ["--upgrade", f"torch>={'.'.join(map(str, MINIMUM))}"] + if replace and nvidia and system in ("Windows", "Linux"): + extra = ["--force-reinstall", "--no-deps"] if system == "Windows" else [] + return pip + extra + ["--index-url", CUDA_INDEX] if system == "Linux" and not nvidia: return pip + ["--index-url", CPU_INDEX] if system == "Windows" and nvidia: diff --git a/src/uipsf/device.py b/src/uipsf/device.py index 6a545638..16627696 100644 --- a/src/uipsf/device.py +++ b/src/uipsf/device.py @@ -32,6 +32,21 @@ def default_device() -> torch.device: return torch.device("cpu") +def describe(device=None) -> str: + """Where the learning runs, for a person: "on the graphics card (NVIDIA GeForce RTX 3070 Ti)", "on Apple's + GPU" or "on the CPU". The PSF calibration window says it after *Detect*: a CPU build of torch on a + machine with a card learnt on the CPU, several times slower, and nothing said so.""" + d = default_device() if device is None else torch.device(device) + if d.type == "cuda": + try: + return f"on the graphics card ({torch.cuda.get_device_name(d)})" + except Exception: # a name is a courtesy, never a reason to fail + return "on the graphics card" + if d.type == "mps": + return "on Apple's GPU" + return "on the CPU" + + def resolve(device=None, dtype: torch.dtype = torch.float32) -> tuple[torch.device, torch.dtype]: """The device to use, refusing float64 where the hardware has none (MPS).""" device = default_device() if device is None else torch.device(device) diff --git a/tests/test_torch_install.py b/tests/test_torch_install.py index 5d4c3c57..357274b3 100644 --- a/tests/test_torch_install.py +++ b/tests/test_torch_install.py @@ -52,3 +52,68 @@ def test_the_window_offers_the_install_only_for_the_pupil_model_and_only_while_t window._show_method() assert not window.install_button.isVisibleTo(window) and window.run_button.isEnabled() window.close() + + +def test_a_cpu_build_on_a_machine_with_an_nvidia_card_is_found_from_its_version(): + found = torch_install.cpu_build_on_nvidia + assert found("2.14.1", "Windows", nvidia=True) # PyPI's Windows wheel is the CPU's + assert not found("2.14.1+cu126", "Windows", nvidia=True) + assert found("2.14.1+cpu", "Linux", nvidia=True) + assert not found("2.14.1", "Linux", nvidia=True) # PyPI's Linux wheel is CUDA's + assert not found("2.14.1", "Windows", nvidia=False) # no card: the CPU is all there is + assert not found("2.14.1", "Darwin", nvidia=False) + + +def test_replacing_a_cpu_build_reinstalls_from_the_cuda_index(): + windows = torch_install.command("Windows", nvidia=True, replace=True) + assert windows[-4:] == ["--force-reinstall", "--no-deps", "--index-url", torch_install.CUDA_INDEX] + linux = torch_install.command("Linux", nvidia=True, replace=True) + assert linux[-2:] == ["--index-url", torch_install.CUDA_INDEX] and "--no-deps" not in linux + assert torch_install.command("Darwin", nvidia=False, replace=True) == torch_install.command("Darwin", nvidia=False) + + +def test_the_window_warns_of_a_cpu_build_beside_a_card_offers_the_install_and_still_runs(monkeypatch): + import pytest + pytest.importorskip("PySide6") + from PySide6.QtWidgets import QApplication + + from smappy.calibrate.psf_window import PSFCalibrationWindow + QApplication.instance() or QApplication([]) + monkeypatch.setattr(torch_install, "problem", lambda: None) + monkeypatch.setattr(torch_install, "_installed", lambda: "2.14.1") + monkeypatch.setattr(torch_install, "has_nvidia", lambda: True) + monkeypatch.setattr(torch_install.platform, "system", lambda: "Windows") + window = PSFCalibrationWindow() + window.method_box.setCurrentText("pupil model (uiPSF)") + assert window.install_button.isVisibleTo(window) and window.run_button.isEnabled() + assert "built for the CPU only" in window.notice.text() and torch_install.CUDA_INDEX in window.notice.text() + monkeypatch.setattr(torch_install, "has_nvidia", lambda: False) + window._show_method() + assert not window.install_button.isVisibleTo(window) and not window.notice.isVisibleTo(window) + window.close() + + +def test_after_detect_the_window_says_where_the_pupil_model_learns(monkeypatch): + import pytest + pytest.importorskip("PySide6") + from PySide6.QtWidgets import QApplication + + from smappy.calibrate import psf_window + from smappy.calibrate.psf_methods import Detected + QApplication.instance() or QApplication([]) + monkeypatch.setattr(torch_install, "problem", lambda: None) + monkeypatch.setattr(psf_window, "learning_device", lambda: "on the graphics card (a test card)") + window = psf_window.PSFCalibrationWindow() + window.method_box.setCurrentText("pupil model (uiPSF)") + window.method = type("M", (), {"key": "pupil"})() # its own text, not a method's detected_text + window.detected = Detected(None, "12 beads to learn from") + window._show_detected_text() + assert window.found_label.text() == "12 beads to learn from; learnt on the graphics card (a test card)" + window.close() + + +def test_the_device_is_described_for_a_person(): + import pytest + pytest.importorskip("torch") + from uipsf.device import describe + assert describe("cpu") == "on the CPU" and describe("mps") == "on Apple's GPU"