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=4096)[source]¶
Bases:
ExecutorBaseQulacs 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;
Nonemakes them unbounded.
- property shots: int | None¶
Return the number of shots.
- property remote: bool¶
Return True if the execution access a remote backend.
Native abstraction¶
Circuit¶
- class qc_executor.qulacs.QulacsCircuit(num_qubits=0, num_clbits=0, *, _ir=None)[source]¶
Bases:
QuantumCircuitBaseA quantum circuit that compiles to Qulacs.
Built like any other circuit –
QulacsCircuit(2)thencircuit.h(0)– or converted from an existing one withfrom_quantum_circuit(). Compilation into Qulacs operations is lazy and re-runs whenever the instruction store changes.- Parameters:
num_qubits (
int) – Number of qubits in the circuit.num_clbits (
int) – Number of classical bits. Qulacs cannot execute mid-circuit measurement, so these exist only for interface parity._ir (
CircuitIR|None) – Adopt this instruction store instead of starting empty.
- classmethod supported_opcodes()[source]¶
Return the opcodes Qulacs executes directly.
- Return type:
frozenset
- 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.
Derived from the instruction store rather than from the compiled operations, so it answers without forcing compilation. Lowering does not change which parameters appear, only which gates carry them.
- property circuit_arguments: dict¶
Dictionary of all circuit and observable parameters names
- 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_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 (Parameter | List[Parameter] | None) – Parameters to calculate the gradient for
Operator¶
- class qc_executor.qulacs.QulacsOperator(paulis=None, coeffs=None, num_qubits=None, *, _ir=None)[source]¶
Bases:
QuantumOperatorBaseAn observable that compiles to Qulacs operators.
Built like any other operator –
QulacsOperator(["ZI"], [1.0])– or converted from an existing one withfrom_quantum_operator(). Compilation is lazy, so the inherited algebra (compose(),adjoint(),apply_layout(), …) works without paying for it.- Parameters:
paulis (
Optional[Sequence[str]]) – Pauli labels, qubit 0 leftmost.coeffs (
Optional[Sequence[Any]]) – One coefficient per label.num_qubits (
int|None) – Width, required only when no labels are given._ir (
PauliIR|None) – Adopt this representation instead of building one.
- property parameter_dimensions: Dict[str, int]¶
Number of parameter occurrences, keyed by vector name.
- property parameter_names: list¶
List of operator parameter names
- property free_parameters: set¶
Return the set of free (non-bound) parameters in the operator.
- property terms: List[str]¶
The Qulacs term strings, one per Pauli.
- build_operator(values)[source]¶
Build the Qulacs operator for one set of parameter values.
- Parameters:
values (
Sequence) – Values for this operator’s parameters, in order.- Return type:
GeneralQuantumOperator- Returns:
The Qulacs operator.
- gradient_terms(gradient_parameters)[source]¶
Return the Pauli terms whose coefficient depends on a requested parameter.
- Return type:
List[PauliOperator]- Parameters:
gradient_parameters (Sequence[Parameter])
- coefficient_jacobian(gradient_parameters, values)[source]¶
Return d(coefficient)/d(parameter) for the terms that depend on one.
- Parameters:
gradient_parameters (
Sequence[Parameter]) – Parameters the gradient is taken with respect to.values (
Sequence) – Values for this operator’s parameters, in order.
- Return type:
ndarray- Returns:
An array of shape
(relevant terms, len(gradient_parameters)).