genQC logo genQC
  • Overview
  • Get Started
  • Tutorials
  • API Reference
  • Research
  • Code Repository
  1. Utils
  2. Miscellaneous util

API Reference

  • Modules Overview
  • Release notes

  • Benchmark
    • Compilation benchmark
  • Dataset
    • Dataset balancing
    • Cached dataset
    • Quantum circuit dataset
    • Config dataset
    • Dataset helper functions
    • Mixed cached dataset
  • Inference
    • Evaluation metrics
    • Evaluation helper
    • Sampling functions
  • Models
    • Config model
    • Frozen OpenCLIP
    • Layers
    • Position encodings
    • Conditional qc-UNet
    • Encoder for unitaries
    • Clip
      • Frozen OpenCLIP
      • Unitary CLIP
    • Embedding
      • Base embedder
      • Rotational preset embedder
    • Transformers
      • Transformers and attention
      • CirDiT - Circuit Diffusion Transformer
      • Transformers
  • Pipeline
    • Callbacks
    • Compilation Diffusion Pipeline
    • Diffusion Pipeline
    • Diffusion Pipeline Special
    • Metrics
    • Multimodal Diffusion Pipeline
    • Pipeline
    • Unitary CLIP Pipeline
  • Platform
    • Circuits dataset generation functions
    • Circuits instructions
    • Simulation backend
    • Backends
      • Base backend
      • CUDA-Q circuits backend
      • Pennylane circuits backend
      • Qiskit circuits backend
    • Tokenizer
      • Base tokenizer
      • Circuits tokenizer
      • Tensor tokenizer
  • Scheduler
    • Scheduler
    • DDIM Scheduler
    • DDPM Scheduler
    • DPM Scheduler
  • Utils
    • Async functions
    • Config loader
    • Math and algorithms
    • Miscellaneous util

On this page

  • Memory utils
    • MemoryCleaner
  • Python utils
    • virtual
    • cache_data
  • Torch utils
    • DataLoaders
    • infer_torch_device
    • number_of_paramters
    • scale_tensor
    • normalize_tensor
  • Plot utils
    • saveSvg
    • savePng
    • savePdf
    • plot_image_grid
    • latents_to_pil
  • Inference utils
    • set_seed
    • get_element_matching_indices
    • get_entanglement_bins
  • Report an issue
  • View source
  1. Utils
  2. Miscellaneous util

Miscellaneous util

Miscellaneous util code

Memory utils


source

MemoryCleaner

 MemoryCleaner ()

CLass with static methods to clean (gpu) memory.

Python utils


source

virtual

 virtual (f:<built-infunctioncallable>)

Decorator to enfore subclass method implementations and raises error at method calls.

class A():
    def p1(self, x): print("A p1", x)
    
    @virtual
    def p2(self, x): pass
 
class B(A):
    def p3(self, x): print("B p2", x)
    
b = B()
b.p1(1)
try:
    b.p2(1)
except BaseException as e:
    print("Exception that would be raised: ", e)
A p1 1
Exception that would be raised:  Virtual method p2 needs to be implemented by subclass B.

source

cache_data

 cache_data (file_name, force_recompute)

*A decorator that memorizes the result of a function and stores it. Note, if the function or its arguments change we ignore it, we only check if the file exists!

Parameters: - file_name (str): The name of the file to store the memoized results. - force_recompute (bool): If True, existing cache is ignored.*

Torch utils


source

DataLoaders

 DataLoaders (*dls:list[torch.utils.data.dataloader.DataLoader])

Combines train and valid DataLoader objects.


source

infer_torch_device

 infer_torch_device ()
infer_torch_device()
[INFO]: Cuda device has a capability of 8.6 (>= 8), allowing tf32 matmul.
device(type='cuda')

source

number_of_paramters

 number_of_paramters (model:torch.nn.modules.module.Module)

source

scale_tensor

 scale_tensor (t:torch.Tensor)

[-1,1] to [0,1]


source

normalize_tensor

 normalize_tensor (t:torch.Tensor)

[0,1] to [-1,1]

Plot utils


source

saveSvg

 saveSvg (filename)

source

savePng

 savePng (filename)

source

savePdf

 savePdf (filename)

source

plot_image_grid

 plot_image_grid (imgs:Union[list,<built-infunctionarray>,torch.Tensor],
                  labels:list=None, labels_fs='medium', figsize=(16, 4),
                  cols=8, cmap='Greys', show_colorbar=False,
                  **imshow_kwargs)
n = 6
plot_image_grid(torch.randn((n,28,28,1)), [f"label {i}" for i in range(n)])


source

latents_to_pil

 latents_to_pil (latents:torch.Tensor, channels=None)

Inference utils


source

set_seed

 set_seed (seed:int)

Sets a seed to pytorch, numpy and python. Additionally sets cuda flags.


source

get_element_matching_indices

 get_element_matching_indices (a:torch.Tensor, b:torch.Tensor)

Compares (2d) a with b. Returns the indices of b, where a element of a matches with b.


source

get_entanglement_bins

 get_entanglement_bins (num_of_qubits:int)

Returns all SRV sorted in entangle bins, corresponding to a number of entangled qubits.

Print the Schmidt-rank-vector bins for 5 qubits:

for srvs,label in zip(*get_entanglement_bins(5)):
    print(label, ":", srvs)
0 qubit entangled : [[1, 1, 1, 1, 1]]
2 qubit entangled : [[1, 1, 1, 2, 2], [1, 1, 2, 1, 2], [1, 1, 2, 2, 1], [1, 2, 1, 1, 2], [1, 2, 1, 2, 1], [1, 2, 2, 1, 1], [2, 1, 1, 1, 2], [2, 1, 1, 2, 1], [2, 1, 2, 1, 1], [2, 2, 1, 1, 1]]
3 qubit entangled : [[1, 1, 2, 2, 2], [1, 2, 1, 2, 2], [1, 2, 2, 1, 2], [1, 2, 2, 2, 1], [2, 1, 1, 2, 2], [2, 1, 2, 1, 2], [2, 1, 2, 2, 1], [2, 2, 1, 1, 2], [2, 2, 1, 2, 1], [2, 2, 2, 1, 1]]
4 qubit entangled : [[1, 2, 2, 2, 2], [2, 1, 2, 2, 2], [2, 2, 1, 2, 2], [2, 2, 2, 1, 2], [2, 2, 2, 2, 1]]
5 qubit entangled : [[2, 2, 2, 2, 2]]
Back to top
Math and algorithms
 

Copyright 2025, Florian Fürrutter

  • Report an issue
  • View source