qulacs

Dependencies

Install with pip install qc-executor[qulacs]. Requires:

  • qulacs>=0.6.4.1

Executor

class qc_executor.qulacs.QulacsExecutor(shots=None, seed=None, log_file=None, log_level='WARNING', caching=None, cache_dir='cache', max_cache_size=None)[source]

Bases: ExecutorBase

Qulacs backend executor implementation.

Parameters:
  • shots (int | None, optional) – Number of shots for sampling.

  • seed (int | None, optional) – Random seed for reproducibility.

  • log_file (str | None, optional) – Path to the log file.

  • log_level (str, optional) – Logging level.

  • caching (bool | None, optional) – Whether to use in-memory caching.

  • cache_dir (str, optional) – Directory for caching.

  • max_cache_size (int | None, optional) – Maximum number of entries kept in each in-memory cache.

property shots: int | None

Return the number of shots.

property remote: bool

Return True if the execution access a remote backend.

classmethod get_accepted_backend_types()[source]

Return all object types accepted as backend in factory auto-detection.

QulacsExecutor does not accept backend objects during initialization.

Return type:

List[type]

classmethod get_accepted_backend_aliases()[source]

Return string aliases accepted by this executor in Executor.create.

Return type:

List[str]

Native abstraction

Circuit

class qc_executor.qulacs.QulacsCircuit(circuit)[source]

Bases: object

Wrapper class that converts a generic QuantumCircuit into a Qulacs-compatible circuit.

Parameters:

circuit (QuantumCircuit)

classmethod from_quantum_circuit(circuit)[source]

Create a Qulacs native circuit from a generic circuit.

Return type:

QulacsCircuit

Parameters:

circuit (QuantumCircuit)

property num_qubits: int

Number of qubits of the circuit

property qulacs_circuit: Callable | None

Qulacs circuit that can be called with parameters

property parameter_names: list

List of circuit parameter names

property parameter_dimensions: dict

Dictionary with the dimension of each circuit parameter

property circuit_arguments: dict

Dictionary of all circuit and observable parameters names

property hash: int

Hashable object of the circuit and observable for caching

property free_parameters: set

Return the set of free (non-bound) parameters in the circuit.

get_qulacs_circuit()[source]

Builds and returns the Qulacs circuit as callable function

Return type:

Callable

get_circuit_func(gradient_param=None)[source]

Returns the Qulacs circuit function for the circuit.

get_gradient_outer_jacobian(gradient_parameters=None)[source]

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 (ParameterVectorElement | List[ParameterVectorElement] | None) – Parameters to calculate the gradient for

Operator

class qc_executor.qulacs.QulacsOperator(operator)[source]

Bases: object

Qulacs native operator wrapper for expectation value and gradient computation.

Parameters:

operator (QuantumOperatorBase | List[QuantumOperatorBase])

classmethod from_quantum_operator(operator)[source]

Create a Qulacs native operator from generic operator(s).

Return type:

QulacsOperator

Parameters:

operator (QuantumOperatorBase | List[QuantumOperatorBase])

property num_qubits: int

Number of qubits of the circuit

property parameter_names: list

List of operator parameter names

property parameter_dimensions: dict

Dictionary with the dimension of each circuit parameter

property hash: str

Hashable object of the circuit and operator for caching

property free_parameters: set

Return the set of free (non-bound) parameters in the operator.

build_operator_instructions(operator)[source]

Function to build the instructions for the Qulacs operator from the Qiskit operator.

This functions converts the Qiskit SparsePauli and parameter expressions to Qulacs compatible Pauli words and functions.

Parameters:

operator (List[SparsePauliOp] | SparsePauliOp) – Qiskit operator to convert to Qulacs

Returns:

Tuple with lists of Qulacs operator parameter functions, Qulacs Pauli words, Qulacs operator parameters and Qulacs operator parameter dimensions

get_operator_func()[source]

Returns the Qulacs operator function for the operator depending on parameters.

get_gradient_outer_jacobian_operators_new(gradient_parameters=None)[source]

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 (ParameterVectorElement | List[ParameterVectorElement] | None) – Parameters to calculate the gradient for.

get_operators_for_gradient(gradient_parameters=None)[source]

Returns the Qulacs operator function for the operators depending on parameters.

Parameters:

gradient_parameters (ParameterVectorElement | List[ParameterVectorElement] | None)