Circuit builders#
Qiskit circuits for the quantum-like model families.
Every builder returns (circuit, decode), where decode(counts) turns measurement counts into the
same probability vectors that the analytic model predicts, so circuit and model can be compared
directly.
Forms. 'dynamic' circuits use mid-circuit measurement and reset (IBM hardware, Aer).
'deferred' circuits copy each measurement to a fresh ancilla and read everything at the end (the
deferred-measurement principle); they run on hardware without mid-circuit measurement (for example ion
traps on Amazon Braket) and on OpenQASM 3 simulators.
Binary projective measurement. To ask “is the state in the subspace of projector P (rank r)?”, a unitary V maps that subspace onto the first r computational basis states, an ancilla is flipped for each of those basis states (multi-controlled X), only the ancilla is measured, and V is undone. The system is never measured directly, so the post-measurement state follows the Lüders rule.
Examples
>>> from quantum_mind.families.order_effects import QuantumOrderModel
>>> from quantum_mind.circuits import order_effects_circuit, run
>>> model = QuantumOrderModel(a=0.8, b=1.2, g=0.3)
>>> qc, decode = order_effects_circuit(model, 'AB')
>>> decode(run(qc, 'aer', shots=20000)).round(2)
Functions
Unitary that maps the range of a projector onto the first basis states. |
|
Circuit for a sequence of yes/no questions. |
|
Circuit for a question-order model. |
|
Quantum-like Bayesian network inference as a circuit. |
|
Quantum-walk circuit at time t. |
|
Circuit for an |
|
Number of qubits needed for a dimension. |
- subspace_unitary(P, n)[source]#
Unitary that maps the range of a projector onto the first basis states.
- Parameters:
P (
numpy.ndarray) –d x dprojector withd <= 2**n.n (
int) – Number of qubits; padding dimensions are completed to a full unitary.
- Returns:
V (
numpy.ndarray) –2**n x 2**nunitary whose first r rows are an orthonormal basis (conjugated) of range(P), so it maps range(P) onto span(|0>, …,|r-1>).r (
int) – Rank of P.
- projective_sequence_circuit(psi, projectors, order, form='dynamic')[source]#
Circuit for a sequence of yes/no questions.
- Parameters:
- Returns:
circuit (
qiskit.QuantumCircuit)decode (
callable) –decode(counts)->{answer tuple: probability}with 1 = yes, in the order asked.
- order_effects_circuit(model, order='AB', form='dynamic')[source]#
Circuit for a question-order model.
- Parameters:
model (
QuantumOrderModel,QuantumOrderModel4DorProjectiveQuestionModel) – The model.order (
{'AB', 'BA'}, optional) – Question order.form (
{'dynamic', 'deferred'}, optional) – Circuit form.
- Returns:
circuit (
qiskit.QuantumCircuit)decode (
callable) –decode(counts)->[yy, yn, ny, nn].
- qlbn_circuit(net, query, evidence=None, phases=None)[source]#
Quantum-like Bayesian network inference as a circuit.
The amplitudes \(\sqrt{P(v, e, h)}\,e^{i\theta_h}\) are loaded with
StatePreparation; the hidden register goes through Hadamard gates and is post-selected on 0, which sums the amplitudes over the hidden configurations.
- walk_circuit(model, t)[source]#
Quantum-walk circuit at time t.
State preparation, \(U(t) = e^{-iHt}\) as a unitary gate on the padded space, and measurement of every qubit.
- Parameters:
model (
QuantumWalk)t (
float)
- Returns:
circuit (
qiskit.QuantumCircuit)decode (
callable) –decode(counts)-> distribution over the model’s response categories.