Skip to content

Commit 4735d0f

Browse files
migrate to pyproject.toml
1 parent 39806da commit 4735d0f

54 files changed

Lines changed: 365 additions & 394 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

genQC/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.4"
1+
__version__ = "0.2.5"

genQC/benchmark/bench_compilation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/benchmark/bench_compilation.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['sigma_x', 'sigma_y', 'sigma_z', 'SpecialUnitaries', 'qubit_tensor_product', 'BaseHamiltonian', 'IsingHamiltonian',
77
'XXZHamiltonian']
88

9-
# %% ../../src/benchmark/bench_compilation.ipynb 2
9+
# %% ../../src/benchmark/bench_compilation.ipynb #a593dee3-594e-4760-a02d-db5559f5f25f
1010
from ..imports import *
1111

12-
# %% ../../src/benchmark/bench_compilation.ipynb 5
12+
# %% ../../src/benchmark/bench_compilation.ipynb #e9337291-4d9e-4524-8fe8-9d198a2abb24
1313
class SpecialUnitaries:
1414
"""Special unitary matrices to benchmark compilation."""
1515

@@ -27,7 +27,7 @@ def QFT(num_qubits: int) -> torch.Tensor:
2727
U *= 1.0/np.sqrt(N)
2828
return U
2929

30-
# %% ../../src/benchmark/bench_compilation.ipynb 9
30+
# %% ../../src/benchmark/bench_compilation.ipynb #86c32afa-32ad-4a52-9aa6-144d8f76f1f2
3131
sigma_x = torch.tensor([[0, 1],
3232
[1, 0]],
3333
dtype=torch.complex128)
@@ -40,7 +40,7 @@ def QFT(num_qubits: int) -> torch.Tensor:
4040
[0, -1]],
4141
dtype=torch.complex128)
4242

43-
# %% ../../src/benchmark/bench_compilation.ipynb 11
43+
# %% ../../src/benchmark/bench_compilation.ipynb #485317ad-e46c-4652-bd2b-89c0c03afea2
4444
def qubit_tensor_product(num_qubits: int, *ops: torch.Tensor, pos: int | Sequence[int]) -> torch.Tensor:
4545
"""
4646
Make tensor product with identities, assumes `ops` placed at `pos` in the tensor product ordering.
@@ -64,7 +64,7 @@ def qubit_tensor_product(num_qubits: int, *ops: torch.Tensor, pos: int | Sequenc
6464

6565
return mat
6666

67-
# %% ../../src/benchmark/bench_compilation.ipynb 19
67+
# %% ../../src/benchmark/bench_compilation.ipynb #ecb265cc-521a-44fd-bf8d-c97b46938932
6868
class BaseHamiltonian(abc.ABC):
6969
"""Base implementation of a Hamiltonian."""
7070

@@ -94,7 +94,7 @@ def get_evolution(self, t: float | torch.Tensor, split_complex_channel: bool = F
9494

9595
return U
9696

97-
# %% ../../src/benchmark/bench_compilation.ipynb 21
97+
# %% ../../src/benchmark/bench_compilation.ipynb #8e1da512-6e2f-4eb4-aade-5cb822b6e6f9
9898
class IsingHamiltonian(BaseHamiltonian):
9999
"""Implementation of the Ising Hamiltonian on a qubit chain."""
100100

@@ -140,7 +140,7 @@ def _generate_matrix(self) -> torch.Tensor:
140140

141141
self.data = ham.to(self.device)
142142

143-
# %% ../../src/benchmark/bench_compilation.ipynb 29
143+
# %% ../../src/benchmark/bench_compilation.ipynb #bcff4597-de9d-436e-908a-ff683e868478
144144
class XXZHamiltonian(BaseHamiltonian):
145145
"""Implementation of the XXZ Hamiltonian on a qubit chain."""
146146

genQC/dataset/balancing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/dataset/balancing.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['get_tensor_gate_length', 'add_balance_fn_quantile_qc_length']
77

8-
# %% ../../src/dataset/balancing.ipynb 2
8+
# %% ../../src/dataset/balancing.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
99
from ..imports import *
1010
import genQC.dataset.dataset_helper as dahe
1111

12-
# %% ../../src/dataset/balancing.ipynb 4
12+
# %% ../../src/dataset/balancing.ipynb #e57ce23e-30fc-434f-9443-3cf97f507b89
1313
def get_tensor_gate_length(clr_tensor: torch.Tensor, padding_token: int = 0) -> torch.Tensor:
1414
"""
1515
Returns the gate count of a tokenized circuit.
@@ -21,7 +21,7 @@ def get_tensor_gate_length(clr_tensor: torch.Tensor, padding_token: int = 0) ->
2121
red_clr_tensor = (clr_tensor != padding_token).any(dim=1) # [b, t]
2222
return torch.count_nonzero(red_clr_tensor, dim=1) # [b]
2323

24-
# %% ../../src/dataset/balancing.ipynb 5
24+
# %% ../../src/dataset/balancing.ipynb #36032308-bd0e-4409-9db0-9d89fc258e5a
2525
def add_balance_fn_quantile_qc_length(indices: Union[np.ndarray, torch.Tensor],
2626
x: Union[np.ndarray, torch.Tensor],
2727
y: Union[np.ndarray, torch.Tensor],

genQC/dataset/cached_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/dataset/cached_dataset.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['CachedOpenCLIPDatasetConfig', 'CachedOpenCLIPDataset']
77

8-
# %% ../../src/dataset/cached_dataset.ipynb 2
8+
# %% ../../src/dataset/cached_dataset.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
99
from ..imports import *
1010
from .config_dataset import ConfigDataset, ConfigDatasetConfig
1111
from ..utils.config_loader import *
1212

13-
# %% ../../src/dataset/cached_dataset.ipynb 3
13+
# %% ../../src/dataset/cached_dataset.ipynb #ac8e640e-c614-4d52-b772-c173b2682ad9
1414
@dataclass
1515
class CachedOpenCLIPDatasetConfig(ConfigDatasetConfig):
1616
pass
1717

18-
# %% ../../src/dataset/cached_dataset.ipynb 4
18+
# %% ../../src/dataset/cached_dataset.ipynb #119077c9-999b-44f7-8099-79037503d7e7
1919
class CachedOpenCLIPDataset(ConfigDataset):
2020
"""
2121
Adds `.caching` to the `ConfigDataset` class.

genQC/dataset/circuits_dataset.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/dataset/circuits_dataset.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['CircuitsConfigDatasetConfig', 'CircuitsConfigDataset', 'MixedCircuitsConfigDatasetConfig',
77
'MixedCircuitsConfigDataset']
88

9-
# %% ../../src/dataset/circuits_dataset.ipynb 2
9+
# %% ../../src/dataset/circuits_dataset.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
1010
from ..imports import *
1111
from .cached_dataset import CachedOpenCLIPDataset, CachedOpenCLIPDatasetConfig
1212
from .mixed_cached_dataset import MixedCachedOpenCLIPDataset, MixedCachedOpenCLIPDatasetConfig
@@ -15,7 +15,7 @@
1515
from .dataset_helper import shuffle_tensor_dataset
1616
from ..utils.misc_utils import MemoryCleaner
1717

18-
# %% ../../src/dataset/circuits_dataset.ipynb 4
18+
# %% ../../src/dataset/circuits_dataset.ipynb #016fc327-f986-4d69-b5f0-1b39466fb528
1919
@dataclass
2020
class CircuitsConfigDatasetConfig(CachedOpenCLIPDatasetConfig):
2121
optimized: bool
@@ -26,7 +26,7 @@ class CircuitsConfigDatasetConfig(CachedOpenCLIPDatasetConfig):
2626
max_params: int
2727
gate_pool: list[str]
2828

29-
# %% ../../src/dataset/circuits_dataset.ipynb 5
29+
# %% ../../src/dataset/circuits_dataset.ipynb #36032308-bd0e-4409-9db0-9d89fc258e5a
3030
class CircuitsConfigDataset(CachedOpenCLIPDataset):
3131
"""Dataset for quantum circuits, access `gate_pool` directly and all other paras with `.params_config`"""
3232

@@ -56,12 +56,12 @@ def params_config(self):
5656
params_config = CircuitsConfigDatasetConfig(**params_config)
5757
return params_config
5858

59-
# %% ../../src/dataset/circuits_dataset.ipynb 8
59+
# %% ../../src/dataset/circuits_dataset.ipynb #75c9a200-f9eb-42f9-b3c3-e074e377737a
6060
@dataclass
6161
class MixedCircuitsConfigDatasetConfig(CircuitsConfigDatasetConfig, MixedCachedOpenCLIPDatasetConfig):
6262
pass
6363

64-
# %% ../../src/dataset/circuits_dataset.ipynb 9
64+
# %% ../../src/dataset/circuits_dataset.ipynb #e804a8d7-dcf3-40e4-83a5-cd98207c8dea
6565
class MixedCircuitsConfigDataset(CircuitsConfigDataset, MixedCachedOpenCLIPDataset):
6666
"""
6767
Dataset that uses multiple cached dataset and combines them with padding, either i) Bucket or ii) Max.

genQC/dataset/config_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/dataset/config_dataset.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['ConfigDatasetConfig', 'ConfigDataset']
77

8-
# %% ../../src/dataset/config_dataset.ipynb 2
8+
# %% ../../src/dataset/config_dataset.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
99
from ..imports import *
1010
from ..utils.config_loader import *
1111
from .dataset_helper import *
1212

1313
from huggingface_hub import snapshot_download
1414

15-
# %% ../../src/dataset/config_dataset.ipynb 3
15+
# %% ../../src/dataset/config_dataset.ipynb #a2688c32-b901-4ac1-9ed6-de0dbd12108b
1616
@dataclass
1717
class ConfigDatasetConfig:
1818
"""Config `dataclass` used for storage."""
1919
store_dict: dict
2020
dataset_to_gpu: bool
2121

22-
# %% ../../src/dataset/config_dataset.ipynb 4
22+
# %% ../../src/dataset/config_dataset.ipynb #36032308-bd0e-4409-9db0-9d89fc258e5a
2323
class ConfigDataset():
2424
"""Base class for datasets, manages loading and saving."""
2525

genQC/dataset/dataset_helper.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/dataset/dataset_helper.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['check_duplicate_in_dataset', 'check_duplicates_in_dataset', 'shuffle_tensor_dataset', 'get_unique_elements_indices',
77
'uniquify_tensor_dataset', 'balance_tensor_dataset']
88

9-
# %% ../../src/dataset/dataset_helper.ipynb 2
9+
# %% ../../src/dataset/dataset_helper.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
1010
from ..imports import *
1111
from ..utils.config_loader import *
1212
from ..utils.async_fn import run_parallel_jobs
1313

14-
# %% ../../src/dataset/dataset_helper.ipynb 4
14+
# %% ../../src/dataset/dataset_helper.ipynb #36032308-bd0e-4409-9db0-9d89fc258e5a
1515
def check_duplicate_in_dataset(x, dataset):
1616
"""Check if 'x' is in 'dataset'"""
1717
# x ... [ *]
@@ -22,7 +22,7 @@ def check_duplicate_in_dataset(x, dataset):
2222
comp = torch.all(comp, dim=1)
2323
return comp.any().item()
2424

25-
# %% ../../src/dataset/dataset_helper.ipynb 5
25+
# %% ../../src/dataset/dataset_helper.ipynb #2a8886b0-2b43-4c06-9992-b859d11e698e
2626
def check_duplicates_in_dataset(xs, dataset, return_ind=False, invert=False):
2727
'''
2828
Checks if `xs` is are `dataset`. Boolean `invert` changes if we count duplicates (False) or ones that are not in dataset (True).
@@ -53,7 +53,7 @@ def get_comp(x, dataset):
5353
if return_ind: return num, comp.squeeze() #comp is [i_xs, i_dataset] pairs
5454
return num
5555

56-
# %% ../../src/dataset/dataset_helper.ipynb 9
56+
# %% ../../src/dataset/dataset_helper.ipynb #9ea47154-d7c2-435b-8d08-0999c744af1a
5757
def shuffle_tensor_dataset(x, y=None, *z, cpu_copy=True):
5858
'''Assumes numpy or tensor objects with same length.'''
5959
rand_indx = torch.randperm(x.shape[0])
@@ -86,7 +86,7 @@ def _cpu_array_index(var):
8686

8787
return x[rand_indx]
8888

89-
# %% ../../src/dataset/dataset_helper.ipynb 10
89+
# %% ../../src/dataset/dataset_helper.ipynb #c8005564-1f96-41da-94f5-16d2f9f48b2a
9090
def get_unique_elements_indices(tensor):
9191
'''Returns indices of unique_elements in `tensor`.'''
9292
tensor_unique, ptrs, cnt = torch.unique(tensor, dim=0, return_inverse=True, return_counts=True)
@@ -99,7 +99,7 @@ def get_unique_elements_indices(tensor):
9999

100100
return tensor[idx], idx
101101

102-
# %% ../../src/dataset/dataset_helper.ipynb 11
102+
# %% ../../src/dataset/dataset_helper.ipynb #a9295de7-54e1-435b-aeea-26746019dd95
103103
def uniquify_tensor_dataset(x, y=None, *z):
104104
'''`x` has to be tensor, assumes numpy or tensor obj for `y` and `z`'''
105105
x, x_idx = get_unique_elements_indices(x)
@@ -112,7 +112,7 @@ def uniquify_tensor_dataset(x, y=None, *z):
112112

113113
return x
114114

115-
# %% ../../src/dataset/dataset_helper.ipynb 12
115+
# %% ../../src/dataset/dataset_helper.ipynb #e63e9933-a2ce-47b3-a957-58705e060fc7
116116
def balance_tensor_dataset(x, y, *z, samples: int=None, make_unique: bool=True, y_uniques=None, shuffle_lables: bool=True, add_balance_fn: callable=None, njobs=1):
117117
'''Assumes `x` is tensor and `y` is tensor or numpy.'''
118118

genQC/dataset/mixed_cached_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/dataset/mixed_cached_dataset.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['MixedCachedOpenCLIPDatasetConfig', 'MixedCachedOpenCLIPDataset']
77

8-
# %% ../../src/dataset/mixed_cached_dataset.ipynb 3
8+
# %% ../../src/dataset/mixed_cached_dataset.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
99
from ..imports import *
1010
from .cached_dataset import CachedOpenCLIPDataset, CachedOpenCLIPDatasetConfig, ConfigDataset
1111
from .dataset_helper import *
1212
from ..utils.misc_utils import DataLoaders, MemoryCleaner
1313
from tensordict import TensorDict
1414

15-
# %% ../../src/dataset/mixed_cached_dataset.ipynb 4
15+
# %% ../../src/dataset/mixed_cached_dataset.ipynb #119077c9-999b-44f7-8099-79037503d7e7
1616
@dataclass
1717
class MixedCachedOpenCLIPDatasetConfig(CachedOpenCLIPDatasetConfig):
1818
pad_constant: int
1919
collate_fn: str
2020
bucket_batch_size: int
2121
model_scale_factor: int
2222

23-
# %% ../../src/dataset/mixed_cached_dataset.ipynb 5
23+
# %% ../../src/dataset/mixed_cached_dataset.ipynb #0037efb5-d3a9-46e4-94d1-3dd80297e934
2424
class MixedCachedOpenCLIPDataset(CachedOpenCLIPDataset):
2525
"""Dataset that uses multiple cached dataset and combines them with padding, either i) Bucket or ii) Max."""
2626

genQC/inference/eval_metrics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/inference/eval_metrics.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['BaseNorm', 'UnitaryFrobeniusNorm', 'UnitaryInfidelityNorm']
77

8-
# %% ../../src/inference/eval_metrics.ipynb 2
8+
# %% ../../src/inference/eval_metrics.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
99
from ..imports import *
1010
from scipy.stats import unitary_group
1111

12-
# %% ../../src/inference/eval_metrics.ipynb 4
12+
# %% ../../src/inference/eval_metrics.ipynb #ccbc4adc-098b-415a-98c8-8b80a0697d34
1313
class BaseNorm(abc.ABC):
1414
"""Base class for norms."""
1515

@@ -21,7 +21,7 @@ def distance(approx_U: torch.Tensor, target_U: torch.Tensor) -> torch.Tensor: ra
2121
@abc.abstractmethod
2222
def name() -> str: raise NotImplementedError()
2323

24-
# %% ../../src/inference/eval_metrics.ipynb 6
24+
# %% ../../src/inference/eval_metrics.ipynb #1b178cbc-d116-49c9-862d-16f646daa39b
2525
class UnitaryFrobeniusNorm(BaseNorm):
2626
"""
2727
The Frobenius-Norm for unitaries: defined in https://arxiv.org/pdf/2106.05649.pdf.
@@ -38,7 +38,7 @@ def distance(approx_U: torch.Tensor, target_U: torch.Tensor) -> torch.Tensor:
3838
@staticmethod
3939
def name() -> str: return "Frobenius-Norm"
4040

41-
# %% ../../src/inference/eval_metrics.ipynb 7
41+
# %% ../../src/inference/eval_metrics.ipynb #90080d81-c872-4da3-9f81-31c8908c1056
4242
class UnitaryInfidelityNorm(BaseNorm):
4343
"""
4444
The Infidelity-Norm for unitaries: defined in https://link.aps.org/accepted/10.1103/PhysRevA.95.042318, TABLE I: 1.

genQC/inference/evaluation_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/inference/evaluation_helper.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['get_srvs', 'get_unitaries']
77

8-
# %% ../../src/inference/evaluation_helper.ipynb 2
8+
# %% ../../src/inference/evaluation_helper.ipynb #68f0714b-e45a-46d8-aa05-d6735d4d0e33
99
from ..imports import *
1010
from ..utils.async_fn import run_parallel_jobs
1111
from ..platform.simulation import Simulator
1212

13-
# %% ../../src/inference/evaluation_helper.ipynb 4
13+
# %% ../../src/inference/evaluation_helper.ipynb #f265206e-7f08-4d74-955b-25eb644adc22
1414
def get_srvs(simulator: Simulator, backend_obj_list: Sequence, n_jobs: int = 1, **kwargs):
1515
"""Returns SRVs of a given list of backen objects `backend_obj_list`."""
1616
def _f(backend_obj):
1717
return simulator.backend.schmidt_rank_vector(backend_obj, **kwargs)
1818

1919
return run_parallel_jobs(_f, backend_obj_list, n_jobs)
2020

21-
# %% ../../src/inference/evaluation_helper.ipynb 6
21+
# %% ../../src/inference/evaluation_helper.ipynb #4cf36492-a8c9-437c-850d-09148fe39eeb
2222
def get_unitaries(simulator: Simulator, backend_obj_list: Sequence, n_jobs: int = 1, **kwargs):
2323
"""Returns unitaries of a given list of backen objects `backend_obj_list`."""
2424
def _f(backend_obj):

0 commit comments

Comments
 (0)