PennyLaneCircuit
PennyLaneCircuit#
- class discopy.quantum.pennylane.PennyLaneCircuit(ops, params, wires, probabilities, post_selection, scale, n_qubits, device)[source]#
Bases:
object
Implement a pennylane circuit with post-selection.
- property post_selection#
The post-selection dictionary.
- 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
- draw(symbols=None, weights=None)[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(symbols, weights)[source]#
Substitute symbolic parameters (SymPy symbols) with floats.
- Parameters
symbols (list of
sympy.core.symbol.Symbol
) – The symbols from the original DisCoPy circuit.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(symbols=None, weights=None)[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