Skip to content

Commit fe1b254

Browse files
Merge branch 'main' into qaoa
2 parents 3fd1432 + 791d111 commit fe1b254

File tree

172 files changed

+49508
-2785
lines changed

Some content is hidden

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

172 files changed

+49508
-2785
lines changed

.github/scripts/join_qmod_metadata.py

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
#!/usr/bin/env python3
1+
#! /usr/bin/env python3
22
import json
3+
import logging
34
import re
45
import sys
56
from pathlib import Path
67
from typing import List
78

9+
# Order matters: higher-priority suffixes first
10+
QMOD_DICT = {".qmod": "native", ".ipynb": "python"}
811

9-
def _get_qmod_path_for_metadata(metadata_path: Path) -> Path:
10-
# Each metadata file has the same name as the qmod file, but with a .json extension,
11-
# so we replace the extension with qmod
12-
qmod_path = metadata_path.parent / (Path(metadata_path.stem).stem + ".qmod")
13-
if not qmod_path.exists():
14-
raise RuntimeError(
15-
f"Could not find qmod file for metadata file {metadata_path} at {qmod_path}"
16-
)
17-
return qmod_path
12+
13+
def _get_qmod_path_for_metadata(metadata_path: Path) -> tuple[Path, str] | None:
14+
"""
15+
Locate a .qmod or .ipynb file corresponding to the given metadata file.
16+
17+
The metadata file is expected to have a .metadata.json suffix (e.g.,
18+
"example.metadata.json"). This function strips the .metadata.json suffix
19+
to get the base name, then looks for a matching .qmod or .ipynb file in
20+
the same directory (e.g., "example.qmod" or "example.ipynb").
21+
22+
Files are checked in QMOD_DICT order:
23+
(.qmod, native),
24+
then (.ipynb, python).
25+
26+
Returns the matched file path and its dialect, or `None` if no match exists.
27+
"""
28+
meta_data_base_name = f"{metadata_path.parent / Path(metadata_path.stem).stem}"
29+
30+
for suffix, dialect in QMOD_DICT.items():
31+
print(f"base name: {meta_data_base_name}{suffix}")
32+
if Path(f"{meta_data_base_name}{suffix}").exists():
33+
return Path(f"{meta_data_base_name}{suffix}"), dialect
34+
35+
# it is the libraries responsibility to ensure that each metadata file has a corresponding qmod/ipynb file
36+
return None
1837

1938

2039
def _is_json(data: str) -> bool:
@@ -29,12 +48,12 @@ def _is_json(data: str) -> bool:
2948
return True
3049

3150

32-
def _get_qmod_type(qmod_path: Path) -> str:
33-
data = qmod_path.read_text()
34-
if _is_json(data):
35-
return "json"
36-
else:
37-
return "standalone"
51+
def _enrich_metadata_with_qmod_info(
52+
single_metadata: dict, qmod_data: tuple[Path, str], directory: Path
53+
) -> None:
54+
qmod_path, dialect = qmod_data
55+
single_metadata["path"] = str(qmod_path.relative_to(directory))
56+
single_metadata["qmod_dialect"] = dialect
3857

3958

4059
def join_metadata_files(directory: Path, exclude_file: Path) -> List[dict]:
@@ -46,16 +65,12 @@ def join_metadata_files(directory: Path, exclude_file: Path) -> List[dict]:
4665
continue
4766
with metadata_path.open() as fobj:
4867
single_metadata = json.load(fobj)
49-
qmod_path = _get_qmod_path_for_metadata(metadata_path)
50-
single_metadata["path"] = str(qmod_path.relative_to(directory))
51-
if single_metadata.get("qmod_dialect") is None:
52-
try:
53-
qmod_type = _get_qmod_type(qmod_path)
54-
except Exception as exc:
55-
raise RuntimeError(
56-
f"Qmod {qmod_path} is not a valid qmod file"
57-
) from exc
58-
single_metadata["qmod_dialect"] = qmod_type
68+
69+
qmod_data = _get_qmod_path_for_metadata(metadata_path)
70+
if qmod_data is None:
71+
continue
72+
73+
_enrich_metadata_with_qmod_info(single_metadata, qmod_data, directory)
5974
metadata.append(single_metadata)
6075
return metadata
6176

@@ -69,6 +84,9 @@ def generate_unified_metadata_file(qmod_directory: str, metadata_filename: str)
6984

7085

7186
if __name__ == "__main__":
87+
logging.basicConfig(
88+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
89+
)
7290
qmod_dir_path = sys.argv[1]
7391
metadata_file = sys.argv[2]
7492
generate_unified_metadata_file(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
search:
3+
boost: 2.610
4+
---
5+
6+
<!-- spell-checker: disable -->
7+
<!-- prettier-ignore-start -->
8+
::: classiq.open_library.functions.bit_operations
9+
options:
10+
show_if_no_docstrings: false
11+
members:
12+
- cyclic_shift_left
13+
- cyclic_shift_right
14+
- bitwise_negate
15+
<!-- prettier-ignore-end -->
16+
<!-- spell-checker: enable -->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
search:
3+
boost: 2.610
4+
---
5+
6+
<!-- spell-checker: disable -->
7+
<!-- prettier-ignore-start -->
8+
::: classiq.open_library.functions.modular_arithmetics
9+
options:
10+
show_if_no_docstrings: false
11+
members:
12+
- modular_add_inplace
13+
- modular_negate_inplace
14+
- modular_subtract_inplace
15+
- modular_double_inplace
16+
- modular_add_constant_inplace
17+
- modular_multiply
18+
- modular_square
19+
- modular_multiply_constant
20+
- modular_multiply_constant_inplace
21+
- modular_to_montgomery_inplace
22+
- modular_montgomery_to_standard_inplace
23+
- modular_inverse_inplace
24+
- kaliski_iteration
25+
- modular_rsub_inplace
26+
<!-- prettier-ignore-end -->
27+
<!-- spell-checker: enable -->

.internal/docs/qmod-reference/api-reference/functions/open_library/modular_exponentiation.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

.internal/docs/qmod-reference/language-reference/uncomputation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ operation, which is flagged as an error.
376376
allocate(q2)
377377
H(
378378
q2
379-
) # Error - The computation sequence of the local variable 'q2' includes a non-permutation operation
379+
) # Error - The local variable 'q2' cannot be automatically uncomputed because it is mutated by a non-permutation operation.
380380
CX(q2, q1)
381381
```
382382

@@ -387,7 +387,7 @@ operation, which is flagged as an error.
387387
q2: qbit;
388388
allocate(q1);
389389
allocate(q2);
390-
H(q2); // Error - The computation sequence of the local variable 'q2' includes a non-permutation operation
390+
H(q2); // Error - The local variable 'q2' cannot be automatically uncomputed because it is mutated by a non-permutation operation.
391391
CX(q2, q1);
392392
}
393393
```
@@ -417,7 +417,7 @@ of `x_transform` are declared _non-const_.
417417
allocate(aux)
418418
x_transform(
419419
p, aux
420-
) # Error - The computation sequence of the local variable 'aux' includes an operation which mutates the parameter 'p'
420+
) # Error - The local variable 'aux' cannot be automatically uncomputed because it is mutated by an operation which also mutates the parameter 'p'.
421421
```
422422

423423
=== "Native"
@@ -432,7 +432,7 @@ of `x_transform` are declared _non-const_.
432432
aux: qbit;
433433
allocate(p);
434434
allocate(aux);
435-
x_transform(p, aux); // Error - The computation sequence of the local variable 'aux' includes an operation which mutates the parameter 'p'
435+
x_transform(p, aux); // Error - The local variable 'aux' cannot be automatically uncomputed because it is mutated by an operation which also mutates the parameter 'p'.
436436
}
437437
```
438438

@@ -455,7 +455,7 @@ the variable `p`.
455455
allocate(aux)
456456
CX(
457457
p, aux
458-
) # Error - The computation sequence of the local variable 'aux' includes a circular dependency with the variable 'p'
458+
) # Error - The local variable 'aux' cannot be automatically uncomputed because it forms a circular dependency with the variable 'p'.
459459
CX(aux, p)
460460
```
461461

@@ -466,7 +466,7 @@ the variable `p`.
466466
aux: qbit;
467467
allocate(p);
468468
allocate(aux);
469-
CX(p, aux); // Error - The computation sequence of the local variable 'aux' includes a circular dependency with the variable 'p'
469+
CX(p, aux); // Error - The local variable 'aux' cannot be automatically uncomputed because it forms a circular dependency with the variable 'p'.
470470
CX(aux, p);
471471
}
472472
```

.internal/pre_commit_tools/notebook_pre_commit_collection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
DEFAULT_TIMEOUT_SECONDS: float = 20
1717

18+
ENFORCE_TIMEOUTS: bool = False
19+
1820

1921
def main(full_file_paths: Iterable[str]) -> bool:
2022
return validate_unique_names() and all(map(is_valid_notebook, full_file_paths))
@@ -28,18 +30,22 @@ def is_valid_notebook(file_path: str, automatically_add_timeout: bool = True) ->
2830
if _does_contain_dash_in_file_name(file_name):
2931
errors.append(
3032
"File naming format error:\n"
31-
" Dash (-) is not allowed in file named. please use underscore (_)\n"
33+
" Dash (-) is not allowed in file name. please use underscore (_)\n"
3234
f" for example, you may change '{file_path}' to '{file_path.replace('-', '_')}'."
3335
)
3436

3537
if _does_contain_space_in_file_name(file_name):
3638
errors.append(
3739
"File naming format error:\n"
38-
" Space is not allowed in file named. please use underscore (_)\n"
40+
" Space is not allowed in file name. please use underscore (_)\n"
3941
f" for example, you may change '{file_path}' to '{file_path.replace(' ', '_')}'."
4042
)
4143

42-
if not _is_file_in_timeouts(file_name) and should_notebook_be_tested(file_path):
44+
if (
45+
ENFORCE_TIMEOUTS
46+
and not _is_file_in_timeouts(file_name)
47+
and should_notebook_be_tested(file_path)
48+
):
4349
if automatically_add_timeout:
4450
_add_file_to_timeouts(file_name)
4551
errors.append(

.internal/pre_commit_tools/qmod_pre_commit_collection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
DEFAULT_TIMEOUT_SECONDS: float = 10
1717

18+
ENFORCE_TIMEOUTS: bool = False
19+
1820

1921
def main(full_file_paths: Iterable[str]) -> bool:
2022
return validate_unique_names() and all(map(is_valid_qmod, full_file_paths))
@@ -32,18 +34,22 @@ def is_valid_qmod(
3234
if _does_contain_dash_in_file_name(file_name):
3335
errors.append(
3436
"File naming format error:\n"
35-
" Dash (-) is not allowed in file named. please use underscore (_)\n"
37+
" Dash (-) is not allowed in file name. please use underscore (_)\n"
3638
f" for example, you may change '{file_path}' to '{file_path.replace('-', '_')}'."
3739
)
3840

3941
if _does_contain_space_in_file_name(file_name):
4042
errors.append(
4143
"File naming format error:\n"
42-
" Space is not allowed in file named. please use underscore (_)\n"
44+
" Space is not allowed in file name. please use underscore (_)\n"
4345
f" for example, you may change '{file_path}' to '{file_path.replace(' ', '_')}'."
4446
)
4547

46-
if not _is_file_in_timeouts(file_name) and should_notebook_be_tested(file_path):
48+
if (
49+
ENFORCE_TIMEOUTS
50+
and not _is_file_in_timeouts(file_name)
51+
and should_notebook_be_tested(file_path)
52+
):
4753
if automatically_add_timeout:
4854
_add_file_to_timeouts(file_name)
4955
errors.append(

0 commit comments

Comments
 (0)