mqt.core.bench.shor

Shor benchmark instances and options.

Module Contents

class Options(*, number: int, base: int = 2)

Parameters for semiclassical Shor order finding.

property number: int

The odd modulus, from 3 through \(2^{31}-1\).

property base: int

The base, from 2 through the modulus minus one and coprime to it.

class Evaluation

Verified factors recovered from measured phases.

property shots: int

The number of evaluated shots.

property success_probability: float

The fraction of shots that independently yield a verified factor pair.

property factors: tuple[int, int] | None

A sorted factor pair, or None.

class Shor(options: Options)

A validated Shor order-finding benchmark.

The circuit uses a semiclassical inverse QFT and reuses one query qubit across its phase measurements. Modular-arithmetic registers remain allocated.

property options: Options

The resolved benchmark parameters.

property output: Output

The big-endian phase register with twice the modulus bit width.

evaluate(counts: Mapping[str, int]) → Evaluation

Recover factors using exact continued fractions and verify them by division.

generate() → QCProgram

Generate the benchmark as a QC program.

property instance_specification_json: str

The canonical instance specification JSON.

property manifest_json: str

The canonical manifest JSON.

property case_id: str

The stable semantic case ID.

static from_instance_specification_json(json: str, *, source: str = '<instance-specification>') → Shor

Parse a strict benchmark instance specification.

static from_manifest_json(json: str, *, source: str = '<manifest>') → Shor

Parse a strict benchmark manifest.

class FactorStatus

Bases: enum.Enum

Outcome of a factoring workflow.

SUCCESS = 0
PRIME = 1
ATTEMPTS_EXHAUSTED = 2
class FactorResult

Result of a bounded factoring workflow.

property status: FactorStatus
property factors: tuple[int, int] | None

A verified sorted factor pair, or None.

property attempts: int

The number of attempted bases.

factor(number: int, run: Callable[[Shor], Mapping[str, int]], *, max_attempts: int = 16, seed: int = 0) → FactorResult

Find one nontrivial factor pair with a bounded number of attempted bases.

The callback accepts a Shor instance and returns counts. It owns device selection, shots, and execution seeds. Even numbers, primes, and perfect powers are handled classically. Callback failures and invalid counts propagate.