PennyLaneCircuit#

class discopy.quantum.pennylane.PennyLaneCircuit(ops, symbols, params, wires, probabilities, post_selection, scale, n_qubits, backend_config, diff_method)[source]#

Bases: object

Implement a pennylane circuit with post-selection.

get_device(backend_config)[source]#

Return a PennyLane device with the specified backend configuration.

initialise_device_and_circuit()[source]#

Initialise the PennyLane device and circuit when instantiating the PennyLaneCirucit, or loading from disk.

contains_sympy()[source]#

Determine if the circuit parameters are concrete or contain SymPy symbols.

Returns:

Whether the circuit parameters contain SymPy symbols.

Return type:

bool

initialise_concrete_params(symbol_weight_map)[source]#

Given concrete values for each of the SymPy symbols, substitute the symbols for the values to obtain concrete parameters, via the param_substitution method.

draw()[source]#

Print a string representation of the circuit similar to qml.draw, but including post-selection.

Parameters:
  • symbols (list of sympy.core.symbol.Symbol, default: None) – The symbols from the original DisCoPy circuit.

  • weights (list of torch.FloatTensor, default: None) – The weights to substitute for the symbols.

get_valid_states()[source]#

Determine which of the output states of the circuit are compatible with the post-selections.

Returns:

The indices of the circuit output that are compatible with the post-selections.

Return type:

list of int

make_circuit()[source]#

Construct the qml.Qnode, a circuit that can be used with autograd to construct hybrid models.

Returns:

A Pennylane circuit without post-selection.

Return type:

qml.Qnode

post_selected_circuit(params)[source]#

Run the circuit with the given parameters and return the post-selected output.

Parameters:

params (torch.FloatTensor) – The concrete parameters for the gates in the circuit.

Returns:

The post-selected output of the circuit.

Return type:

torch.Tensor

param_substitution(weights)[source]#

Substitute symbolic parameters (SymPy symbols) with floats.

Parameters:

weights (list of torch.FloatTensor) – The weights to substitute for the symbols.

Returns:

The concrete (non-symbolic) parameters for the circuit.

Return type:

torch.FloatTensor

eval()[source]#

Evaluate the circuit. The symbols should be those from the original DisCoPy diagram, which will be substituted for the concrete parameters in weights.

Parameters:
  • symbols (list of sympy.core.symbol.Symbol, default: None) – The symbols from the original DisCoPy circuit.

  • weights (list of torch.FloatTensor, default: None) – The weights to substitute for the symbols.

Returns:

The post-selected output of the circuit.

Return type:

torch.Tensor