vqc_lite.circuit_stack_pennylane package
Submodules
vqc_lite.circuit_stack_pennylane.block module
- class vqc_lite.circuit_stack_pennylane.block.Block_CNOT_P(pm1=0)
Bases:
Block_PThis block consists of a Controlled-X gate, followed by 2 general single qubit unitaries (GU1), one on each qubit. It takes 6 parameters.
- assemble()
Automatically called during initialization to generate the circuit function.
- class vqc_lite.circuit_stack_pennylane.block.Block_CZ_P(pm1=0)
Bases:
Block_PThis 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 circuit function.
- class vqc_lite.circuit_stack_pennylane.block.Block_GU1_P(pm1=0)
Bases:
Block_PThis block consists of only 1 general single qubit unitary. It’s takes 3 parameters.
- assemble()
Automatically called during initialization to generate the circuit function.
- class vqc_lite.circuit_stack_pennylane.block.Block_GU2_P
Bases:
Block_PThis block consists of only 1 general two qubit unitary (GU2). It takes 15 parameters.
- assemble()
Automatically called during initialization to generate the circuit function.
- class vqc_lite.circuit_stack_pennylane.block.Block_P(pm1=0)
Bases:
objectThe Pennylane version of the circuit stack consists of 3 levels, which from bottom to top are: gate, block and circuit.
Note that because of functions such as “qml.MPS” and “qml.broadcast”, the arrangement of blocks could be easily handled at the circuit level for many common Ansätze. Thus, at the moment the “layer” level which exists in the other circuit stack is omitted here. However, when more complicated Ansätze come in the future, maybe it’s better to also introduce the layer here.
In the other stack where attributes are passed from one level to the next and only assembled and mapped to gate functions at the circuit level. In the Pennylane stack, in contrary, we directly pass callable gate functions called “circuit”.
A Block is the repeating unit in a layer. A block consists of >= 1 parmaterized or fixed gate(s).
- Parameters
pm1 (int) – parametrization method for GU1
- assemble()
Automatically called during initialization to generate the circuit function.
vqc_lite.circuit_stack_pennylane.circuit module
- class vqc_lite.circuit_stack_pennylane.circuit.Circuit_P(nq=4, **kwargs)
Bases:
objectThe Pennylane version of the circuit stack consists of 3 levels, which from bottom to top are: gate, block and circuit.
Circuits are at the top level of the stack.
Some important attributes of a circuit include:
nq: The number of qubits involved in the circuit.
components: A list of circuits of the constituent layer(s).
param_shape: The shape of parameters for each component.
mq: “measure_qubits”. By default, it is False, meaning all qubits are measured and the exact output statevector will be returned. Else, it could be a list of the indices of the qubits to be measured. Then the probability distribution of bitstrings of the output qubits will be returned.
- Parameters
nq (int) – the number of qubits
mq (list of integers or False) – the qubits to be measured
- assemble()
Automatically called during initialization to generate the circuit function.
- 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')
Applicable when mq is False.
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:
coordinate-wise distance
squared coordinate-wise distance
1 - fidelity
trace distance
- get_np()
Compute the total number of parameters in the block.
- Return type
int
- params_to_proper_shape(flattened_params)
Reshape a flattened array of parameters into the form ready to be fed into the circuit.
- Parameters
flattened_params ((jax) numpy array / list of float) – flattened parameters
- Returns
parameters reshaped according to param_shape
- Return type
list of (jax) numpy arrays
- plot(file_name=None, **kwargs)
Make a plot of the circuit and optionally save as a file.
- Parameters
file_name (str) – The name of the file that saves the plot
fig_size (tuple of int) – size of the image
dpi (int) – quality of the image
- run_with_param_input(params)
Run the full circuit with parameter inputs for the parametrized gates.
- Parameters
params ((jax) numpy array / list) – parameter inputs
- to_qasm(params, file_name)
Outputs the gate sequence with parameter inputs in OpenQASM format. May fail, depending on the type of gates involved.
- Parameters
params ((jax) numpy array / list) – parameter inputs
file_name (str) – The name of the file that saves the plot
vqc_lite.circuit_stack_pennylane.circuit_mps module
- class vqc_lite.circuit_stack_pennylane.circuit_mps.MPS_CNOT_P(nl=1, nq=11, irb=None, version=0, pm1=0, **kwargs)
Bases:
MPS_PMPS with CNOT blocks.
- Parameters
pm1 (int) – parameterization method for GU1. See gate.py
- class vqc_lite.circuit_stack_pennylane.circuit_mps.MPS_CZ_P(nl=1, nq=11, irb=None, version=0, pm1=0, **kwargs)
Bases:
MPS_PMPS with CZ blocks.
- Parameters
pm1 (int) – parameterization method for GU1. See gate.py
- class vqc_lite.circuit_stack_pennylane.circuit_mps.MPS_GU2_P(nl=1, nq=11, version=0, **kwargs)
Bases:
MPS_PMPS with GU2 blocks.
- class vqc_lite.circuit_stack_pennylane.circuit_mps.MPS_P(block, nl=1, nq=11, irb=None, version=0, **kwargs)
Bases:
Circuit_PThis is the basis class for all circuits inspired by matrix product states (MPS).
- Parameters
block (Block_P) – The block 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.
version (int) –
define the block arrangement in:
right canonical form
right canonical form with periodic condition
mixed canonical form