query-complexity 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- query_complexity-0.1.0/LICENSE +21 -0
- query_complexity-0.1.0/PKG-INFO +140 -0
- query_complexity-0.1.0/README.md +106 -0
- query_complexity-0.1.0/pyproject.toml +47 -0
- query_complexity-0.1.0/setup.cfg +4 -0
- query_complexity-0.1.0/src/query_complexity/__init__.py +5 -0
- query_complexity-0.1.0/src/query_complexity/core.py +1126 -0
- query_complexity-0.1.0/src/query_complexity.egg-info/PKG-INFO +140 -0
- query_complexity-0.1.0/src/query_complexity.egg-info/SOURCES.txt +11 -0
- query_complexity-0.1.0/src/query_complexity.egg-info/dependency_links.txt +1 -0
- query_complexity-0.1.0/src/query_complexity.egg-info/requires.txt +14 -0
- query_complexity-0.1.0/src/query_complexity.egg-info/top_level.txt +1 -0
- query_complexity-0.1.0/tests/test_smoke.py +13 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ke Li
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: query-complexity
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Adversary-bound SDP and space-efficient transducer tools for Boolean query complexity
|
|
5
|
+
Author: Ke Li
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-org/query-complexity
|
|
8
|
+
Project-URL: Repository, https://github.com/your-org/query-complexity
|
|
9
|
+
Project-URL: Issues, https://github.com/your-org/query-complexity/issues
|
|
10
|
+
Keywords: quantum,query complexity,adversary bound,sdp,semidefinite programming
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.23
|
|
23
|
+
Requires-Dist: scipy>=1.9
|
|
24
|
+
Requires-Dist: cvxpy>=1.3
|
|
25
|
+
Provides-Extra: mosek
|
|
26
|
+
Requires-Dist: mosek; extra == "mosek"
|
|
27
|
+
Provides-Extra: qiskit
|
|
28
|
+
Requires-Dist: qiskit; extra == "qiskit"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest; extra == "dev"
|
|
32
|
+
Requires-Dist: twine; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# query-complexity
|
|
36
|
+
|
|
37
|
+
`query-complexity` is a small Python package for computing adversary-bound SDPs and building the associated space-efficient phase-oracle transducers for Boolean query complexity.
|
|
38
|
+
|
|
39
|
+
The package intentionally keeps the compact one-vector transducer construction and removes the older direct-sum bit-flip implementation.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
From the repository root:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install -e .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For development tools:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install -e .[dev]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For MOSEK or Qiskit support:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install -e .[mosek,qiskit]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## General Boolean functions
|
|
62
|
+
|
|
63
|
+
Use `solve_adversary_sdp` for arbitrary, non-symmetric Boolean functions.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import query_complexity as qc
|
|
67
|
+
|
|
68
|
+
inputs = qc.all_binary_inputs(3)
|
|
69
|
+
outputs = [int(x[0] and x[1] and x[2]) for x in inputs]
|
|
70
|
+
|
|
71
|
+
sol = qc.solve_adversary_sdp(
|
|
72
|
+
inputs,
|
|
73
|
+
outputs,
|
|
74
|
+
solver="MOSEK",
|
|
75
|
+
epsilon=1e-5,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
td = qc.build_adversary_transducer(sol)
|
|
79
|
+
|
|
80
|
+
print("adversary objective:", sol.objective_value)
|
|
81
|
+
print("private dimension:", td.private_dim)
|
|
82
|
+
print("map error:", td.map_error)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Symmetric Boolean functions
|
|
86
|
+
|
|
87
|
+
For functions that depend only on Hamming weight, use the Terwilliger/orbit-reduced solver and expand it to the full Boolean basis:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import query_complexity as qc
|
|
91
|
+
|
|
92
|
+
n = 4
|
|
93
|
+
k = 2
|
|
94
|
+
|
|
95
|
+
sol = qc.solve_symmetric_adversary_sdp(
|
|
96
|
+
n,
|
|
97
|
+
qc.THRESHOLD_layers(n, k),
|
|
98
|
+
solver="MOSEK",
|
|
99
|
+
epsilon=1e-5,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
td = qc.build_adversary_transducer(sol)
|
|
103
|
+
|
|
104
|
+
print("adversary objective:", sol.objective_value)
|
|
105
|
+
print("witness dimensions:", sol.witness_dims)
|
|
106
|
+
print("private dimension:", td.private_dim)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
If you only want the compact orbit-level SDP solution, use:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
orbit = qc.solve_symmetric_orbit_sdp(n, qc.THRESHOLD_layers(n, k))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Analytic helpers
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import query_complexity as qc
|
|
119
|
+
|
|
120
|
+
sol = qc.analytic_or_solution(2)
|
|
121
|
+
td = qc.build_adversary_transducer(sol)
|
|
122
|
+
qc.show_catalysts(sol)
|
|
123
|
+
|
|
124
|
+
blocks = qc.threshold_eta_blocks(4, 2)
|
|
125
|
+
for r, data in blocks.items():
|
|
126
|
+
print(r, data["labels"], data["eta"])
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Main API
|
|
130
|
+
|
|
131
|
+
- `solve_adversary_sdp(...)`: full one-vector adversary SDP for arbitrary Boolean domains.
|
|
132
|
+
- `solve_symmetric_orbit_sdp(...)`: compact Terwilliger/orbit-reduced SDP for symmetric functions.
|
|
133
|
+
- `solve_symmetric_adversary_sdp(...)`: symmetric solver plus expansion to the Boolean input basis.
|
|
134
|
+
- `build_adversary_transducer(...)`: construct the input-independent transducer unitary.
|
|
135
|
+
- `adversary_query(...)`: build the input-dependent phase oracle on the witness space.
|
|
136
|
+
- `adversary_step(...)`: return the single-query transducer step.
|
|
137
|
+
- `run_adversary_algorithm(...)`: simulate the repeated transducer algorithm.
|
|
138
|
+
- `qiskit_adversary_circuit(...)`: optional dense-unitary Qiskit circuit export.
|
|
139
|
+
- `analytic_or_solution(...)`: closed-form adversary solution for OR.
|
|
140
|
+
- `threshold_eta_blocks(...)`: closed-form rank-one Schrijver blocks for thresholds.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# query-complexity
|
|
2
|
+
|
|
3
|
+
`query-complexity` is a small Python package for computing adversary-bound SDPs and building the associated space-efficient phase-oracle transducers for Boolean query complexity.
|
|
4
|
+
|
|
5
|
+
The package intentionally keeps the compact one-vector transducer construction and removes the older direct-sum bit-flip implementation.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
From the repository root:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install -e .
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For development tools:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install -e .[dev]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For MOSEK or Qiskit support:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install -e .[mosek,qiskit]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## General Boolean functions
|
|
28
|
+
|
|
29
|
+
Use `solve_adversary_sdp` for arbitrary, non-symmetric Boolean functions.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import query_complexity as qc
|
|
33
|
+
|
|
34
|
+
inputs = qc.all_binary_inputs(3)
|
|
35
|
+
outputs = [int(x[0] and x[1] and x[2]) for x in inputs]
|
|
36
|
+
|
|
37
|
+
sol = qc.solve_adversary_sdp(
|
|
38
|
+
inputs,
|
|
39
|
+
outputs,
|
|
40
|
+
solver="MOSEK",
|
|
41
|
+
epsilon=1e-5,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
td = qc.build_adversary_transducer(sol)
|
|
45
|
+
|
|
46
|
+
print("adversary objective:", sol.objective_value)
|
|
47
|
+
print("private dimension:", td.private_dim)
|
|
48
|
+
print("map error:", td.map_error)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Symmetric Boolean functions
|
|
52
|
+
|
|
53
|
+
For functions that depend only on Hamming weight, use the Terwilliger/orbit-reduced solver and expand it to the full Boolean basis:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import query_complexity as qc
|
|
57
|
+
|
|
58
|
+
n = 4
|
|
59
|
+
k = 2
|
|
60
|
+
|
|
61
|
+
sol = qc.solve_symmetric_adversary_sdp(
|
|
62
|
+
n,
|
|
63
|
+
qc.THRESHOLD_layers(n, k),
|
|
64
|
+
solver="MOSEK",
|
|
65
|
+
epsilon=1e-5,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
td = qc.build_adversary_transducer(sol)
|
|
69
|
+
|
|
70
|
+
print("adversary objective:", sol.objective_value)
|
|
71
|
+
print("witness dimensions:", sol.witness_dims)
|
|
72
|
+
print("private dimension:", td.private_dim)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
If you only want the compact orbit-level SDP solution, use:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
orbit = qc.solve_symmetric_orbit_sdp(n, qc.THRESHOLD_layers(n, k))
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Analytic helpers
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import query_complexity as qc
|
|
85
|
+
|
|
86
|
+
sol = qc.analytic_or_solution(2)
|
|
87
|
+
td = qc.build_adversary_transducer(sol)
|
|
88
|
+
qc.show_catalysts(sol)
|
|
89
|
+
|
|
90
|
+
blocks = qc.threshold_eta_blocks(4, 2)
|
|
91
|
+
for r, data in blocks.items():
|
|
92
|
+
print(r, data["labels"], data["eta"])
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Main API
|
|
96
|
+
|
|
97
|
+
- `solve_adversary_sdp(...)`: full one-vector adversary SDP for arbitrary Boolean domains.
|
|
98
|
+
- `solve_symmetric_orbit_sdp(...)`: compact Terwilliger/orbit-reduced SDP for symmetric functions.
|
|
99
|
+
- `solve_symmetric_adversary_sdp(...)`: symmetric solver plus expansion to the Boolean input basis.
|
|
100
|
+
- `build_adversary_transducer(...)`: construct the input-independent transducer unitary.
|
|
101
|
+
- `adversary_query(...)`: build the input-dependent phase oracle on the witness space.
|
|
102
|
+
- `adversary_step(...)`: return the single-query transducer step.
|
|
103
|
+
- `run_adversary_algorithm(...)`: simulate the repeated transducer algorithm.
|
|
104
|
+
- `qiskit_adversary_circuit(...)`: optional dense-unitary Qiskit circuit export.
|
|
105
|
+
- `analytic_or_solution(...)`: closed-form adversary solution for OR.
|
|
106
|
+
- `threshold_eta_blocks(...)`: closed-form rank-one Schrijver blocks for thresholds.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "query-complexity"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Adversary-bound SDP and space-efficient transducer tools for Boolean query complexity"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Ke Li"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["quantum", "query complexity", "adversary bound", "sdp", "semidefinite programming"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"numpy>=1.23",
|
|
28
|
+
"scipy>=1.9",
|
|
29
|
+
"cvxpy>=1.3",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
mosek = ["mosek"]
|
|
34
|
+
qiskit = ["qiskit"]
|
|
35
|
+
dev = ["build", "pytest", "twine"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/your-org/query-complexity"
|
|
39
|
+
Repository = "https://github.com/your-org/query-complexity"
|
|
40
|
+
Issues = "https://github.com/your-org/query-complexity/issues"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
pythonpath = ["src"]
|