qpe_toolbox.tensor.mpomps_tools

Functions

kron_mpos(mpo1, mpo2)

Construct the Kronecker (tensor) product of two MPOs.

kron_mps(mps1, mps2, *[, verbosity])

Construct the Kronecker (tensor) product of two MPS objects.

apply_gate_from_mpo(circ, mpo, *[, compress, cutoff, ...])

Apply an MPO-defined gate to a circuit state and return a new CircuitMPS.

add_creg_mpo(mpo, mpo_reg, creg, cket)

Add multiple control qubits to an MPO.

add_cqubit_mpo(mpo, location)

Add a single control qubit to an MPO.

controlled_mpo(mpo, phys_reg, aux_reg, k_ctrl, *[, ctrl])

Construct an MPO controlled on an auxiliary qubit being in a given state.

Module Contents

qpe_toolbox.tensor.mpomps_tools.kron_mpos(mpo1, mpo2)[source]

Construct the Kronecker (tensor) product of two MPOs.

This returns an MPO representing \(\mathrm{MPO}_1 \otimes \mathrm{MPO}_2\), with tensors arranged in the left, right, up, down index ordering

The function supports both single-site and multi-site MPOs and handles boundary tensor reshaping explicitly.

Parameters:
Returns:

The Kronecker product MPO acting on the concatenated Hilbert space.

Return type:

MatrixProductOperator

Raises:

ValueError – If the tensor shapes of either MPO are not compatible with the expected MPO boundary conventions.

qpe_toolbox.tensor.mpomps_tools.kron_mps(mps1, mps2, *, verbosity=0)[source]

Construct the Kronecker (tensor) product of two MPS objects.

This returns an MPS representing \(\mathrm{MPS}_1 \otimes \mathrm{MPS}_2\), with tensors arranged in the left, right, physical index ordering.

Parameters:
  • mps1 (MatrixProductState) – First MPS operand.

  • mps2 (MatrixProductState) – Second MPS operand.

  • verbosity (int, default 0) – If > 0, print the shapes of the resulting tensors.

Returns:

The Kronecker product MPS on the combined physical register.

Return type:

MatrixProductState

Raises:

ValueError – If the tensor shapes of either MPS are not compatible with the expected MPS boundary conventions.

qpe_toolbox.tensor.mpomps_tools.apply_gate_from_mpo(circ, mpo, *, compress=False, cutoff=1e-10, max_bond=0)[source]

Apply an MPO-defined gate to a circuit state and return a new CircuitMPS.

The MPO is applied to the circuit wavefunction circ.psi. Optional compression can be performed during and/or after application.

Parameters:
  • circ (Circuit or CircuitMPS) – Input circuit whose state will be acted on.

  • mpo (MatrixProductOperator) – MPO representing the quantum gate or evolution operator.

  • compress (bool, default False) – Whether to compress the resulting MPS during application.

  • cutoff (float, default 1e-10) – Singular value cutoff used during compression.

  • max_bond (int, default 0) – Maximum allowed bond dimension. 0 means no explicit limit.

Returns:

New circuit with the updated MPS state.

Return type:

CircuitMPS

Notes

This function does not modify the input circuit in place.

qpe_toolbox.tensor.mpomps_tools.add_creg_mpo(mpo, mpo_reg, creg, cket)[source]

Add multiple control qubits to an MPO.

The resulting MPO represents a controlled operation acting on the original MPO, conditioned on the control register being in a specified computational basis state.

Parameters:
  • mpo (MatrixProductOperator) – Base MPO representing the target operation.

  • mpo_reg (list[int]) – Indices of the physical register acted on by mpo.

  • creg (list[int]) – Control qubit indices, indexed with respect to the MPO ordering.

  • cket (str or int) – Control state. Can be a bitstring (e.g. "11") or an integer encoding the computational basis state.

Returns:

MPO with added control qubits.

Return type:

MatrixProductOperator

Raises:
  • ValueError – If an unsupported control state is requested.

  • TypeError – If cket is neither str nor int.

Notes

This function is not fully tested and should be used with care for multi-control configurations.

qpe_toolbox.tensor.mpomps_tools.add_cqubit_mpo(mpo, location)[source]

Add a single control qubit to an MPO.

The control qubit is added either before or after the existing MPO, depending on register ordering.

Parameters:
  • mpo (MatrixProductOperator) – Base MPO representing the target operation.

  • location ({"before", "after"}) – Whether to add the control qubit before or after the MPO qubits.

Returns:

MPO augmented with a single control qubit.

Return type:

MatrixProductOperator

Raises:

ValueError – If location is not one of "before" or "after".

qpe_toolbox.tensor.mpomps_tools.controlled_mpo(mpo, phys_reg, aux_reg, k_ctrl, *, ctrl=1)[source]

Construct an MPO controlled on an auxiliary qubit being in a given state.

The MPO is assumed to be of the form Id U, where Id acts on the auxiliary register and U acts on the physical register.

Parameters:
  • mpo (MatrixProductOperator) – Input MPO in the form Id U.

  • phys_reg (list[int]) – Indices of the physical register qubits.

  • aux_reg (list[int]) – Indices of the auxiliary (control) register qubits.

  • k_ctrl (int) – Index of the control qubit relative to aux_reg.

  • ctrl (int, default 1) – Control value (0 or 1) conditioning the operation.

Returns:

Controlled MPO.

Return type:

MatrixProductOperator

Raises:

ValueError – If the register ordering assumption is violated.

Notes

This implementation assumes that all auxiliary-register tensors initially correspond to identity operators.