vqc_lite.circuit_stack package

Submodules

vqc_lite.circuit_stack.block module

class vqc_lite.circuit_stack.block.Block

Bases: object

The circuit stack consists of 4 levels, which from bottom to top are: gate, block, layer and circuit.

A block is the repeating unit in a layer. A block consists of >= 1 parameterized or fixed gate(s). The most important attributes of a block are three lists, called “gs”, “il” and “npl”.

  1. “gs” stands for gate sequence,

    which is a list of strings (names of the gates). The functions realizing the gates are defined in the file gate.py. The strings will be mapped to the functions at the circuit level.

  2. “il” stands for index list,

    which is a list of lists of integers called ‘local indices’, which defines the qubits on which the gates apply.

  3. “npl” stands for number of parameter list,

    which is a list storing the number of parameters each gate takes.

assemble()

Automatically called during initialization to generate the three attributes.

get_np()

Compute the total number of parameters in the block.

class vqc_lite.circuit_stack.block.Block_CNOT

Bases: Block

This block consists of a Controlled-X gate, followed by 2 general single qubit unitaries (GU1), one on each qubit. It takes 6 parameters. As an example, the three attributes for this block writes:

  1. gs = [‘CNOT’, ‘GU1’, ‘GU1’]

  2. il = [[0, 1], [0], [1]]

  3. npl = [0, 3, 3]

assemble()

Automatically called during initialization to generate the three attributes.

class vqc_lite.circuit_stack.block.Block_CZ

Bases: Block

This block consists of a Controlled-Z gate, followed by 2 general single qubit unitaries, one on each qubit. It takes 6 parameters.

assemble()

Automatically called during initialization to generate the three attributes.

class vqc_lite.circuit_stack.block.Block_GU1

Bases: Block

This block consists of only 1 general single qubit unitary. It’s takes 3 parameters.

assemble()

Automatically called during initialization to generate the three attributes.

class vqc_lite.circuit_stack.block.Block_GU2

Bases: Block

This block consists of only 1 general two qubit unitary (GU2). It takes 15 parameters.

assemble()

Automatically called during initialization to generate the three attributes.

vqc_lite.circuit_stack.circuit module

class vqc_lite.circuit_stack.circuit.Circuit(nq=4, **kwargs)

Bases: object

The circuit stack consists of 4 levels, which from bottom to top are: gate, block, layer and circuit.

Circuits are at the top level of the stack.

  1. The most important attributes of a circuit are also “gs”, “il” and “npl”, which are formed by concatenating the ones of its layer components.

  2. The attribute “components” is a list of layers, which could be of different kinds.

  3. The attribute “filled_circuit” is a list of arrays, each corresponds to a fixed gate, or a parametrized gate filled with parameters.

Parameters
  • nq (int) – the number of qubits in the circuit.

  • pmd (dictionary mapping str to int) – the parameterization method dictionary, which defines how a gate should be parametrized if there are multiple ways to do so

assemble()

Automatically called during initialization to generate the three attributes.

backward_contraction(psi_out, ng=numpy.inf)

Contract the filled circuit in backward direction until some stopping point and compute the input state.

Parameters
  • psi_out ((jax) numpy array) – A bra state. When using in optimization, if psi is the target state, psi_out = psi.conjugate()

  • ng (int) – The number of gates to contract before stop.

Returns

ket state after contraction

Return type

(jax) numpy array

environment_contraction(psi_in, psi_out, ig)

Compute the environment tensor of a gate, by performing forward contraction from the input state, and backward contraction from the output state, toward the gate. This function is usually called during sweeping optimization.

Parameters
  • psi_in ((jax) numpy array) – A ket state. Usually |0>.

  • psi_out ((jax) numpy array) – A bra state. When using in optimization, if psi is the target state, psi_out = psi.conjugate()

  • ig (int) – The index of the target gate. We start counting from 1!

Returns

The environment tensor

Return type

(jax) numpy array

fill_params(params)

Form the filled_circuit by filling parameters into the parametrized gates.

Parameters

params ((jax) numpy array / list) – parameter inputs

forward_contraction(psi_in, ng=numpy.inf)

Contract the filled circuit in forward direction until some stopping point, and compute the output state

Parameters
  • psi_in ((jax) numpy array) – A ket state. Usually |0>.

  • ng (int) – The number of gates to contract before stop.

Returns

ket state after contraction

Return type

(jax) numpy array

get_distance_with(params, psi)

Compute the coordinate-wise distance between the output state of the VQC with parameter inputs and a target state psi.

Parameters
  • params ((jax) numpy array / list) – parameter inputs

  • psi ((jax) numpy array) – target state

get_fidelity_with(params, psi)

Compute the fidelity between the output state of the VQC with parameter inputs and a target state psi.

Parameters
  • params ((jax) numpy array / list) – parameter inputs

  • psi ((jax) numpy array) – target state

get_loss(params, psi, lf='td')

Compute the “loss” of the output state of the VQC with parameter inputs compared to a target state psi.

Often called during optimization for state preparation. Could also be used for more general purposes.

Parameters
  • params ((jax) numpy array / list) – parameter inputs

  • psi ((jax) numpy array) – target state

  • lf (int) –

    choice of loss function, currently supports:

    1. coordinate-wise distance

    2. squared coordinate-wise distance

    3. 1 - fidelity

    4. trace distance

get_np()

Compute the total number of parameters in the block.

Return type

int

get_where_parametrized()

Return an array of integer indices, telling which gates of the gate sequence are parametrized gates

Return type

array of int

run_with_gate_input(gates)

Run the full circuit with gate inputs that would replace the parametrized gates and form the filled circuit together with the fixed gates in the gate sequence.

First compute the filled circuit and then perform a full forward contraction starting from state |0>.

Parameters

gates (list of (jax) numpy arrays) – gate inputs

run_with_param_input(params)

Run the full circuit with parameter inputs for the parametrized gates.

First compute the filled circuit and then perform a full forward contraction starting from state |0>.

Parameters

params ((jax) numpy array / list) – parameter inputs

vqc_lite.circuit_stack.circuit_mps module

class vqc_lite.circuit_stack.circuit_mps.MPS(layer, nl=1, nq=4, irb=None, **kwargs)

Bases: Circuit

This is the basis class for all circuits inspired by matrix product states (MPS).

Parameters
  • layer (Layer) – The layer object underlying the circuit.

  • nl (int) – The number of layers in the circuit.

  • nq (int) – The number of qubits in the circuit.

  • irb (Block) – The block object for initial rotation, if applicable. It’s None by default.

class vqc_lite.circuit_stack.circuit_mps.MPS_CNOT(nl=1, nq=4, irb=None, pm1=0, version=0, **kwargs)

Bases: MPS

MPS with CNOT blocks.

Parameters
  • pm1 (int) – parameterization method for GU1. See gate.py

  • version (int) –

    define the block arrangement in:

    1. right canonical form

    2. right canonical form with periodic condition

    3. mixed canonical form

class vqc_lite.circuit_stack.circuit_mps.MPS_CZ(nl=1, nq=4, irb=None, pm1=0, version=0, **kwargs)

Bases: MPS

MPS with CZ blocks.

Parameters
  • pm1 (int) – parameterization method for GU1. See gate.py

  • version (int) –

    define the block arrangement in:

    1. right canonical form

    2. right canonical form with periodic condition

    3. mixed canonical form

class vqc_lite.circuit_stack.circuit_mps.MPS_GU2(nl=1, nq=4, version=0, **kwargs)

Bases: MPS

MPS with GU2 blocks.

Parameters

version (int) –

define the block arrangement in:

  1. right canonical form

  2. right canonical form with periodic condition

  3. mixed canonical form

vqc_lite.circuit_stack.gate module

vqc_lite.circuit_stack.gate.CNOT()

The circuit stack consists of 4 levels, which from bottom to top are: gate, block, layer and circuit.

Gates are at the bottom level of the stack. Functions in this module realize gates that can be either parametrized or unparametrized. Parametrized gates take parameters as input, while unparametrized gates are without input. Functions of both kinds output a unitary matrix in jax numpy array form.

Controlled X gates. Native entangling gate of many superconducting quantum computers.

vqc_lite.circuit_stack.gate.CZ()

Controlled Z gates. Native entangling gate of many superconducting quantum computers.

vqc_lite.circuit_stack.gate.GU1(params, parametrization=0)

A wrapper function for the various functions realizing the general 1Q unitary. There are many ways to parametrize a general single qubit unitary with 3 parameters.

Parameters
  • params ((jax) numpy array / list of float) – An array of 3 elements.

  • parametrization (int) –

    An integer that defines the parametrization method. Currently, 5 methods are supported.

    1. Pauli basis parametrization

    2. Euler angle parametrization, RZ - RY - RZ. Same as “qml.Rot” from Pennylane

    3. Euler angle parametrization, RY - RZ - RY.

    4. Euler angle parametrization, RX - RZ - RX.

    5. Euler angle parametrization, qiskit version

vqc_lite.circuit_stack.gate.GU2(params)

General 2Q unitary parametrized by 15 coefficients of the 2Q Pauli basis (excluding Id)

Parameters

params ((jax) numpy array / list of float) – An array of 15 elements.

vqc_lite.circuit_stack.gate.Haar_Random(nq, key)

Randomly generates a general nq-qubit unitary, with respect to Haar measure, by using QR-decomposition. Ref: https://arxiv.org/abs/math-ph/0609050

Parameters
  • nq (int) – the number of qubits

  • key (jax key) – the random key

vqc_lite.circuit_stack.gate.Id1()

The identity matrix for the 1Q space

vqc_lite.circuit_stack.gate.PauliBasis1()

1-Q Pauli basis stored in array

vqc_lite.circuit_stack.gate.PauliBasis2()

2-Q Pauli basis stored in array

vqc_lite.circuit_stack.gate.PauliX()

Pauli-X matrix / 1Q X-gate

vqc_lite.circuit_stack.gate.PauliY()

Pauli-Y matrix / 1Q Y-gate

vqc_lite.circuit_stack.gate.PauliZ()

Pauli-Z matrix / 1Q Z-gate

vqc_lite.circuit_stack.gate.RX(x)

The parametrized RX-gate

Parameters

x (float) – the rotation angle

vqc_lite.circuit_stack.gate.RY(x)

The parametrized RY-gate

Parameters

x (float) – the rotation angle

vqc_lite.circuit_stack.gate.RZ(x)

The parametrized RY-gate

Parameters

x (float) – the rotation angle

vqc_lite.circuit_stack.gate.U3_Pauli(params)

General 1Q unitary, parametrized by Pauli basis decomposition of the exponent Hermitian matrix.

Parameters

params ((jax) numpy array / list of float) – the 3 coefficients of Pauli basis elements (excluding that of Id, which would only contributes to an additional global phase).

vqc_lite.circuit_stack.gate.U3_Rot(params)

General 1Q unitary. Same parametrization method as “U3Gate” from Qiskit.

Parameters

params ((jax) numpy array / list of float) – the 3 rotation angles, theta, phi, and lambda.

vqc_lite.circuit_stack.layer module

class vqc_lite.circuit_stack.layer.IRLayer(block, **kwargs)

Bases: Layer

A flat layer of single qubit unitaries. Typically used for initial rotations on the qubits.

assemble()

Automatically called during initialization to generate the three attributes.

class vqc_lite.circuit_stack.layer.Layer(block, **kwargs)

Bases: object

The circuit stack consists of 4 levels, which from bottom to top are: gate, block, layer and circuit.

A layer is a component of the circuit, which could repeat itself a few times in the circuit. A layer is an arrangement of repeating blocks that covers all qubits.

The most important attributes of a circuit are also “gs”, “il” and “npl”, which are formed by concatenating the ones of its block components.

Parameters
  • block (Block) – The repeating block in the layer

  • nq (int) – The number of qubits

assemble()

Automatically called during initialization to generate the three attributes.

get_np()

Compute the total number of parameters in the block.

class vqc_lite.circuit_stack.layer.MCMPSLayer(block, **kwargs)

Bases: Layer

A ladder-shaped layer that grows in both directions, inspired by MPS of mixed canonical form.

assemble()

Automatically called during initialization to generate the three attributes.

class vqc_lite.circuit_stack.layer.PRCMPSLayer(block, **kwargs)

Bases: Layer

A ladder-shaped layer that grows in one direction, inspired by MPS of right canonical form with periodic boundary condition.

assemble()

Automatically called during initialization to generate the three attributes.

class vqc_lite.circuit_stack.layer.RCMPSLayer(block, **kwargs)

Bases: Layer

A ladder-shaped layer that grows in one direction, inspired by MPS of right canonical form.

assemble()

Automatically called during initialization to generate the three attributes.

Module contents