Oracle 查询算法¶
oracq.algorithms.basics.oracle_algorithms
Deutsch–Jozsa, Bernstein–Vazirani, and Simon query algorithms.
- oracq.algorithms.basics.oracle_algorithms.deutsch_jozsa(function)[源代码]¶
Generate the D-J query circuit; the caller asserts the function is constant or balanced.
- 参数:
function -- An XOR database with one-bit results, satisfying the constant or balanced promise.
- 返回:
Query circuit with registers input and answer; read out input to decide constant versus balanced.
- 返回类型:
- oracq.algorithms.basics.oracle_algorithms.bernstein_vazirani(function)[源代码]¶
Generate the Bernstein–Vazirani secret string readout circuit.
- 参数:
function -- An XOR database with one-bit results; the caller guarantees f(x)=s·x XOR c.
- 返回:
Exposes input and answer. When the input promise holds, reading input yields s.
- 返回类型:
The oracle may stay as an open declaration, with a gate or QRAM implementation bound later.
- oracq.algorithms.basics.oracle_algorithms.affine_boolean_oracle(width, secret, *, bias=0)[源代码]¶
Build a plain gate oracle for BV; bit i of secret corresponds to bit i of the address.
- 参数:
width -- Address register bit width, in 1..64.
secret -- Integer encoding of the secret string, in 0..2^width−1.
bias -- Constant bias c, either 0 or 1.
- 返回:
Gate-level XOR database handle implementing f(x)=s·x XOR c.
- 返回类型:
- oracq.algorithms.basics.oracle_algorithms.simon_sample(function)[源代码]¶
Generate one Simon sampling circuit.
- 参数:
function -- An XOR database; the caller guarantees a two-to-one map with a nonzero XOR period.
- 返回:
Exposes input and output. Reading input alone yields an orthogonality constraint on the period.
- 返回类型:
The output register need not be measured inside the circuit; elimination over repeated samples happens on the classical side.
- oracq.algorithms.basics.oracle_algorithms.simon_nullspace(samples, width)[源代码]¶
Compute the GF(2) null space of the Simon sample constraints.
- 参数:
samples -- Integer samples encoded in little endian.
width -- Bit width of the secret string.
- 返回:
Null space basis vectors. Only a one-dimensional null space determines the nonzero period directly; with insufficient samples several basis vectors remain.
- 返回类型:
tuple