quiche.resources#

Logic for the resource-estimation backend of QUICHE.

Logical costs#

Resource calculations for quantum circuits and routines.

logical_gate_resources(circuit)#

Calculate estimated logical gate cost of a bloq provided an error budget.

Return type:

GateCounts

logical_qubit_resources(circuit)#

Calculate estimated logical gate cost of a bloq provided an error budget.

Return type:

int

logical_rotations_to_tgates(gates, errors, rotation_synthesis)#

Transform rotation gates to T gates according to the error budget.

Return type:

GateCounts

Bloqs#

Core Qualtran routines (Bloqs) used for resource estimation.

Phase estimation#

Quantum phase estimation routines.

class NaiveQPE(simulation, mode)#

Naive, single-ancilla phase estimation (Hadamard test).

Uses a controlled application of the propagator U to estimate its expectation value in a provided initial state. Only one ancilla is used during the Hadamard test.

If the measurement mode is “re”, the bloq represents the following circuit:

|0>   ------H------•--------H----- meas
                   |
|psi> -------------U--------------

and if it is “im”, the bloq represents the following circuit:

|0>   ---H---S†----•------- H ---- meas
                   |
|psi> -------------U--------------
Properties:
  • simulation (Bloq) – Bloq implementing the Hamiltonian simulation.

  • mode ({‘re’, ‘im’}) – Specifies whether to measure the real or imaginary part of the expectation value.

Resources

The bloq uses simulation qubits and a single ancilla qubit.

property exponent: int#

Power to which the propagator is raised (always 1 for Naive QPE).

property apply_feedback: bool#

Whether a feedback rotation is applied (False for Naive QPE).

class KitaevQPE(simulation, k, mode)#

Kitaev single-ancilla phase estimation.

For a unitary operator U and an initial state that approximates some eigenstate |psi>, estimate the phase theta in U|psi> = e^{2 pi i theta} |psi>. The Kitaev QPE estimates the k-th digit of the phase by applying the propagator U^(2^k) for increasing k values. This bloq implements the QPE for a single selection of k. It needs to be called multiple times with different k values to reflect a full phase estimation.

If the measurement mode is “re”, the bloq represents the following circuit:

|0>   ------H------•--------H----- meas
                   |
|psi> -------------U^(2^k)--------

and if it is “im”, the bloq represents the following circuit:

|0>   ---H---S†----•------- H ---- meas
                   |
|psi> -------------U^(2^k)--------
Properties:
  • simulation (Bloq) – Bloq implementing the Hamiltonian simulation.

  • k (int) – Controls the exponent of the propagator U as described above.

  • mode ({‘re’, ‘im’}) – Specifies whether to measure the real or imaginary part of the expectation value.

Resources

The bloq uses simulation qubits and a single ancilla qubit.

property exponent: int#

Power to which the propagator is raised (2^k for Kitaev QPE).

property apply_feedback: bool#

Whether a feedback rotation is applied (False for Kitaev QPE).

class IterativeQPE(simulation, k, mode)#

Iterative phase estimation.

For a unitary operator U and an initial state that approximates some eigenstate |psi>, estimate the phase theta in U|psi> = e^{2 pi i theta} |psi>. In iterative QPE, a rotation around z is inserted between the controlled propagator and the second Hadamard gate. The rotation angle depends on previous measurements, which we cannot evaluate in Qualtran. Instead we use symbolic angles. This bloq implements the QPE for a single selection of k. It needs to be called multiple times with different k values to reflect a full phase estimation.

If the measurement mode is “re”, the bloq represents the following circuit:

|0>   ------H------•----Rz----H----- meas
                   |
|psi> -------------U^(2^k)----------

and if it is “im”, the bloq represents the following circuit:

|0>   ---H---S†----•----Rz---H---- meas
                   |
|psi> -------------U^(2^k)----------
Properties:
  • simulation (Bloq) – Bloq implementing the Hamiltonian simulation.

  • k (int) – Controls the exponent of the propagator U as described above.

  • mode ({‘re’, ‘im’}) – Specifies whether to measure the real or imaginary part of the expectation value.

Resources

The bloq uses simulation qubits and a single ancilla qubit.

property exponent: int#

Power to which the propagator is raised (2^k for Iterative QPE).

property apply_feedback: bool#

Whether a feedback rotation is applied (True for Iterative QPE).

class TextbookQPE(simulation_factory, num_data, num_qpe_ancillas, num_other_ancillas)#

End-to-end QPE routine including state preparation, simulation and QFT.

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

property signature: Signature#

Define input and/or output registers of the bloq.

build_composite_bloq(bb, **soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph for TextbookQPE.

Return type:

Mapping[Bloq, int | Expr]

class TrotterLadder(index, simulation, num_data, num_qpe_ancillas)#

Routine to construct controlled Trotter evolution operator as needed for QPE.

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

property signature: Signature#

Define input and/or output registers of the bloq.

build_composite_bloq(bb, **soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph for TrotterLadder.

Return type:

Mapping[Bloq, int | Expr]

class QubitisationLadder(index, walk, num_data, num_qpe_ancillas, num_selection_ancillas)#

Routine to construct controlled Qubitisation operator as needed for QPE.

property signature: Signature#

Define input and/or output registers of the bloq.

build_composite_bloq(bb, **soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph for QubitisationLadder.

Return type:

Mapping[Bloq, int | Expr]

Hamiltonian simulation#

Hamiltonian simulation routines.

class SelectPauliLCUWrapper(selection_bitsize, target_bitsize, select_unitaries, control_val=None)#

Wrapper for SelectPauliLCU for resource counting.

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

build_call_graph(ssa)#

Build call graph for SelectPauliLCU.

Return type:

Mapping[Bloq, int | Expr]

num_qubits()#

The number of qubits this gate acts on.

Return type:

int

class LCUBlockEncodingWrapper(select, prepare, control_val=None)#

Class that welds the Qualtran to the QUICHE bloq.

classmethod from_hamiltonian(h, phase_bitsize)#

Process the input arguments and return an LCU block encoding.

Return type:

Self

build_call_graph(ssa)#

Build call graph for LCUBlockEncodingWrapper.

Return type:

Mapping[Bloq, int | Expr]

class PauliWordRotation(word, angle, n_qubits, is_controlled=False)#

Routine constructing the Pauli phasor for a given Pauli.

property control_registers: tuple[Register, ...]#

Registers holding the control qubit, if any.

property n_controls: int#

Number of control qubits (1 if controlled, 0 otherwise).

property signature: Signature#

Define input and/or output registers of the bloq.

get_ctrl_system(ctrl_spec)#

Override function to get controlled bloq.

Return type:

tuple[Bloq, AddControlledT]

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

build_composite_bloq(bb, **soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph for PauliWordRotation.

Return type:

Mapping[Bloq, int | Expr]

class QDRIFT(h, t, n_terms, seed, is_controlled=False)#

QDRIFT implementation for a given linear combination of Paulis.

property control_registers: tuple[Register, ...]#

Registers holding the control qubit, if any.

property n_controls: int#

Number of control qubits (1 if controlled, 0 otherwise).

property signature: Signature#

Define input and/or output registers of the bloq.

get_ctrl_system(ctrl_spec)#

Override function to get controlled bloq.

Return type:

tuple[Bloq, AddControlledT]

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

property positive_coefficients: tuple[float, ...]#

Get absolute value of the coefficients.

property lam: float#

Get the 1-norm of the coefficients.

property n_qubits: int#

Get number of qubits of bloq.

property dt: float#

Get timestep for each operator.

build_composite_bloq(bb, **soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Compute call graph for QDRIFT.

Return type:

Mapping[Bloq, int | Expr]

class Trotterisation(h, t, n_steps, order, is_controlled=False)#

General Trotter product formulae.

property control_registers: tuple[Register, ...]#

Registers holding the control qubit, if any.

property n_controls: int#

Number of control qubits (1 if controlled, 0 otherwise).

property signature: Signature#

Define input and/or output registers of the bloq.

get_ctrl_system(ctrl_spec)#

Override function to get controlled bloq.

Return type:

tuple[Bloq, AddControlledT]

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

property n_qubits: int#

Get number of qubits of bloq.

property dt: float#

Determine the time step size in each step of the Trotterization.

get_coeffs_indices(order=None)#

Return the coefficients and indices for the Trotter product.

Return type:

tuple[NDArray[np.float64], NDArray[np.int_]]

build_composite_bloq(bb, **soqs)#

Implement the decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Compute call graph for Trotterisation.

Return type:

Mapping[Bloq, int | Expr]

State preparation#

State preparation routines.

class IdentityStatePrep(n_qubits)#

Routine for trivial state preparation.

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

property signature: Signature#

Define input and/or output registers of the bloq.

build_composite_bloq(bb, **_soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph.

Return type:

Mapping[Bloq, int | Expr]

class BitstringStatePrep(bitstring)#

Routine to prepare an arbitrary computational basis state.

property signature: Signature#

Define input and/or output registers of the bloq.

property num_qubits: int#

Calculate number of qubits.

build_composite_bloq(bb, **soqs)#

Implement bloq decomposition into sub-bloqs.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph.

Return type:

Mapping[Bloq, int | Expr]

my_static_costs(cost_key)#

Return hard-coded qubit counts.

Return type:

int

class PrepareFromStatePrep(stateprep, phase_bitsize, select_nqubits)#

PREP routine for a given phase-gradient state preparation bloq.

Implements the action PREP |0> = \sum_{j=1}^L c_j |j>.

Properties:
  • stateprep (StatePreparationViaRotations) – State preparation bloq.

  • phase_bitsize (int) – Number of qubits used for phase gradient.

  • select_nqubits (int) – Number of qubits on which to prepare the PREP state. Note that L must be equal to 2**select_nqubits.

property selection_registers: tuple[Register, ...]#

Get selection (index) register.

property junk_registers: tuple[Register, ...]#

Get the junk (phase gradient) register.

build_prepare_circuit()#

Get the state preparation bloq. Required by the PrepareOracle interface.

Return type:

Bloq

build_composite_bloq(bb, **soqs)#

Implement decomposition into sub-bloqs using stateprep bloq decomposition.

Return type:

dict[str, Soquet | ndarray[tuple[Any, …], dtype[_SoquetType]]]

build_call_graph(ssa)#

Build call graph for PrepareFromStatePrep.

Return type:

Mapping[Bloq, int | Expr]

num_qubits()#

The number of qubits this gate acts on.

Return type:

int