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

subspace_unitary

Unitary that maps the range of a projector onto the first basis states.

projective_sequence_circuit

Circuit for a sequence of yes/no questions.

order_effects_circuit

Circuit for a question-order model.

qlbn_circuit

Quantum-like Bayesian network inference as a circuit.

walk_circuit

Quantum-walk circuit at time t.

belief_circuit

Circuit for an OpenSystemBelief over a sequence of events.

n_qubits

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 d projector with d <= 2**n.

  • n (int) – Number of qubits; padding dimensions are completed to a full unitary.

Returns:

  • V (numpy.ndarray) – 2**n x 2**n unitary 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:
  • psi (array_like) – State of length d (normalised here).

  • projectors (dict) – {name: d x d "yes" projector}.

  • order (sequence of str) – Questions in the order asked.

  • form ({'dynamic', 'deferred'}, optional) – Mid-circuit measurement, or deferred measurement on fresh ancillas.

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, QuantumOrderModel4D or ProjectiveQuestionModel) – 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.

Parameters:
  • net (BayesNet)

  • query (str)

  • evidence (dict, optional)

  • phases (array_like, optional)

Returns:

  • circuit (qiskit.QuantumCircuit)

  • decode (callable) – decode(counts) -> distribution of the query.

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.

belief_circuit(model, events, queries, form='dynamic')[source]#

Circuit for an OpenSystemBelief over a sequence of events.

Dephasing of strength gamma is applied by an ancilla that triggers Z with probability gamma / 2.

Parameters:
  • model (OpenSystemBelief)

  • events (sequence of int)

  • queries (sequence of int)

  • form ({'dynamic', 'deferred'}, optional)

Returns:

  • circuit (qiskit.QuantumCircuit)

  • decode (callable) – decode(counts) -> P(yes) at the last query.

n_qubits(d)[source]#

Number of qubits needed for a dimension.

Parameters:

d (int) – Hilbert-space dimension.

Returns:

int – \(\lceil \log_2 d \rceil\), at least 1.