Skip to main content

Adversary-bound SDP and space-efficient transducer tools for Boolean query complexity

Project description

query-complexity

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.

The package intentionally keeps the compact one-vector transducer construction and removes the older direct-sum bit-flip implementation.

Install

From the repository root:

pip install -e .

For development tools:

pip install -e .[dev]

For MOSEK or Qiskit support:

pip install -e .[mosek,qiskit]

General Boolean functions

Use solve_adversary_sdp for arbitrary, non-symmetric Boolean functions.

import query_complexity as qc

inputs = qc.all_binary_inputs(3)
outputs = [int(x[0] and x[1] and x[2]) for x in inputs]

sol = qc.solve_adversary_sdp(
    inputs,
    outputs,
    solver="MOSEK",
    epsilon=1e-5,
)

td = qc.build_adversary_transducer(sol)

print("adversary objective:", sol.objective_value)
print("private dimension:", td.private_dim)
print("map error:", td.map_error)

Symmetric Boolean functions

For functions that depend only on Hamming weight, use the Terwilliger/orbit-reduced solver and expand it to the full Boolean basis:

import query_complexity as qc

n = 4
k = 2

sol = qc.solve_symmetric_adversary_sdp(
    n,
    qc.THRESHOLD_layers(n, k),
    solver="MOSEK",
    epsilon=1e-5,
)

td = qc.build_adversary_transducer(sol)

print("adversary objective:", sol.objective_value)
print("witness dimensions:", sol.witness_dims)
print("private dimension:", td.private_dim)

If you only want the compact orbit-level SDP solution, use:

orbit = qc.solve_symmetric_orbit_sdp(n, qc.THRESHOLD_layers(n, k))

Analytic helpers

import query_complexity as qc

sol = qc.analytic_or_solution(2)
td = qc.build_adversary_transducer(sol)
qc.show_catalysts(sol)

blocks = qc.threshold_eta_blocks(4, 2)
for r, data in blocks.items():
    print(r, data["labels"], data["eta"])

Main API

  • solve_adversary_sdp(...): full one-vector adversary SDP for arbitrary Boolean domains.
  • solve_symmetric_orbit_sdp(...): compact Terwilliger/orbit-reduced SDP for symmetric functions.
  • solve_symmetric_adversary_sdp(...): symmetric solver plus expansion to the Boolean input basis.
  • build_adversary_transducer(...): construct the input-independent transducer unitary.
  • adversary_query(...): build the input-dependent phase oracle on the witness space.
  • adversary_step(...): return the single-query transducer step.
  • run_adversary_algorithm(...): simulate the repeated transducer algorithm.
  • qiskit_adversary_circuit(...): optional dense-unitary Qiskit circuit export.
  • analytic_or_solution(...): closed-form adversary solution for OR.
  • threshold_eta_blocks(...): closed-form rank-one Schrijver blocks for thresholds.

Value-only SDP solvers

If you only need the adversary bound and do not want the second trace-minimization pass, use the value-only APIs.

For a general Boolean function:

import query_complexity as qc

inputs = qc.all_binary_inputs(3)
outputs = [int(any(x)) for x in inputs]

res = qc.solve_adversary_value_sdp(inputs, outputs, solver="MOSEK")
print(res.objective_value)        # phase-normalized value T
print(res.usual_adversary_value)  # usual adversary value 2T

For a symmetric function using Schrijver/Terwilliger blocks:

res = qc.solve_symmetric_orbit_value_sdp(
    10,
    qc.THRESHOLD_layers(10, 4),
    solver="MOSEK",
)
print(res.objective_value)
print(res.usual_adversary_value)

These functions skip witness extraction and trace minimization.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

query_complexity-0.1.1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

query_complexity-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file query_complexity-0.1.1.tar.gz.

File metadata

  • Download URL: query_complexity-0.1.1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for query_complexity-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a6ef512f139f80f4000959a8dce8d8189e70d5e1a7d20e8600626dae7da42ebf
MD5 f11044fd226cdd53eb352030f87c14c6
BLAKE2b-256 5cd3cabe8d0c4242cf418983c10c025c0b2b1bb6d32ec2f390da2c0cfd75b111

See more details on using hashes here.

File details

Details for the file query_complexity-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for query_complexity-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 343cf760b1d37303887c79308e8ebb8c69890b19ae38243e76f91faeaebffda5
MD5 b860ffffa5e66cd44864f32bb15d7756
BLAKE2b-256 c7e7010e1e8fff057b4214c54732483dfc16e1737ffbc40a0293c03f9df36ee1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page