squlearn.util.qulacs
.QulacsCircuit
- class squlearn.util.qulacs.QulacsCircuit(circuit: QuantumCircuit, observable: None | SparsePauliOp | List[SparsePauliOp] | str = None)
Class for converting a Qiskit circuit to a Qulacs circuit.
- Parameters:
circuit (QiskitQuantumCircuit) – Qiskit circuit to convert to Qulacs
observable (Union[None, SparsePauliOp, List[SparsePauliOp]]) – Observable to be measured, if None, no observable is defined.
Attributes:
- num_qubits
Number of qubits in the circuit
- Type:
int
- circuit_parameter_names
List of circuit parameter names
- Type:
list
- observable_parameter_names
List of observable parameter names
- Type:
list
- argument_names
List of all circuit and observable parameters names
- Type:
list
- hash
Hashable object of the circuit and observable for caching
- Type:
str
Methods:
- build_observable_instructions(observables: List[SparsePauliOp] | SparsePauliOp)
Function to build the instructions for the Qulacs observable from the Qiskit observable.
This functions converts the Qiskit SparsePauli and parameter expressions to Qulacs compatible Pauli words and functions.
- Parameters:
observable (Union[List[SparsePauliOp], SparsePauliOp]) – Qiskit observable to convert to Qulacs
- Returns:
Tuple with lists of Qulacs observable parameter functions, Qulacs Pauli words, Qulacs observable parameters and Qulacs observable parameter dimensions
- get_circuit_func(gradient_param: None | ParameterVectorElement | List[ParameterVectorElement] = None) callable
Returns the function for the creating the qulacs circuit and its gradients.
- Parameters:
gradient_param (Union[None, ParameterVectorElement, List[ParameterVectorElement]]) – Parameters to calculate the gradient for
- get_observable_func()
Returns a function for creating the qulacs observable depending on the parameters.
- get_observables_for_gradient(gradient_parameters: None | ParameterVectorElement | List[ParameterVectorElement] = None) callable
Returns the Qulacs observable function for the observable depending on parameters.
- Parameters:
gradient_parameters (Union[None, ParameterVectorElement, List[ParameterVectorElement]]) – Parameters to calculate the gradient for
- Returns:
Function that returns the Qulacs observable for the given parameters
- Return type:
callable
- get_outer_jacobian_circuit(gradient_parameters: None | ParameterVectorElement | List[ParameterVectorElement] = None) callable
Returns the outer jacobian needed for the chain rule in circuit derivatives.
Qulacs does not support multiple parameters and parameter expressions, so we need to calculate a transformation which also includes the gradient of the parameter expression.
- Parameters:
gradient_parameters (Union[None, ParameterVectorElement, List[ParameterVectorElement]]) – Parameters to calculate the gradient for
- Returns:
Function that calculates the outer jacobian for given parameters values
- Return type:
callable
- get_outer_jacobian_observables(gradient_parameters: None | ParameterVectorElement | List[ParameterVectorElement] = None) callable
Returns the outer jacobian needed for the chain rule in circuit derivatives.
Qulacs does not support multiple parameters and parameter expressions, so we need to calculate a transformation which also includes the gradient of the parameter expression.
- Parameters:
gradient_parameters (Union[None, ParameterVectorElement, List[ParameterVectorElement]]) – Parameters to calculate the gradient for
- Returns:
Function that calculates the outer jacobian for the observable parameters
- Return type:
callable