Skip to main content
IBM Quantum Platform
이 페이지는 Qiskit SDK 의 이전 버전에서 가져온 것으로, 최신 버전에는 존재하지 않습니다. 최신 버전으로 업데이트하시기를 권장합니다. 자세한 정보는 릴리스 정보를 참조하십시오.

CircuitSampler

class qiskit.opflow.converters.CircuitSampler(backend, statevector=None, param_qobj=False, attach_results=False, caching='last')

GitHub

Bases: ConverterBase

Deprecated: The CircuitSampler traverses an Operator and converts any CircuitStateFns into approximations of the state function by a DictStateFn or VectorStateFn using a quantum backend. Note that in order to approximate the value of the CircuitStateFn, it must 1) send state function through a depolarizing channel, which will destroy all phase information and 2) replace the sampled frequencies with square roots of the frequency, rather than the raw probability of sampling (which would be the equivalent of sampling the square of the state function, per the Born rule.

The CircuitSampler aggressively caches transpiled circuits to handle re-parameterization of the same circuit efficiently. If you are converting multiple different Operators, you are better off using a different CircuitSampler for each Operator to avoid cache thrashing.

Deprecated since version 0.24.0

The class qiskit.opflow.converters.circuit_sampler.CircuitSampler is deprecated as of qiskit-terra 0.24.0. It will be removed in the Qiskit 1.0 release. For code migration guidelines, visit https://qisk.it/opflow_migration.

Parameters

  • backend (Backend |QuantumInstance) – The quantum backend or QuantumInstance to use to sample the circuits.
  • statevector (bool | None) – If backend is a statevector backend, whether to replace the CircuitStateFns with DictStateFns (from the counts) or VectorStateFns (from the statevector). None will set this argument automatically based on the backend.
  • attach_results (bool) – Whether to attach the data from the backend Results object for a given CircuitStateFn` to an execution_results field added the converted DictStateFn or VectorStateFn.
  • param_qobj (bool) – Whether to use Aer’s parameterized Qobj capability to avoid re-assembling the circuits.
  • caching (str) – The caching strategy. Can be ‘last’ (default) to store the last operator that was converted, set to ‘all’ to cache all processed operators.

Raises

ValueError – Set statevector or param_qobj True when not supported by backend.


Attributes

quantum_instance

Returns the quantum instance.

Returns

The QuantumInstance used by the CircuitSampler


Methods

clear_cache

clear_cache()

Clear the cache of sampled operator expressions.

convert

convert(operator, params=None)

Converts the Operator to one in which the CircuitStateFns are replaced by DictStateFns or VectorStateFns. Extracts the CircuitStateFns out of the Operator, caches them, calls sample_circuits below to get their converted replacements, and replaces the CircuitStateFns in operator with the replacement StateFns.

Parameters

Returns

The converted Operator with CircuitStateFns replaced by DictStateFns or VectorStateFns.

Raises

OpflowError – if extracted circuits are empty.

Return type

OperatorBase

sample_circuits

sample_circuits(circuit_sfns=None, param_bindings=None)

Samples the CircuitStateFns and returns a dict associating their id() values to their replacement DictStateFn or VectorStateFn. If param_bindings is provided, the CircuitStateFns are broken into their parameterizations, and a list of StateFns is returned in the dict for each circuit id(). Note that param_bindings is provided here in a different format than in convert, and lists of parameters within the dict is not supported, and only binding dicts which are valid to be passed into Terra can be included in this list.

Parameters

Returns

The dictionary mapping ids of the CircuitStateFns to their replacement StateFns.

Raises

OpflowError – if extracted circuits are empty.

Return type

Dict[int, List[StateFn]]

이 페이지가 도움이 되었습니까?
GitHub에서 버그, 오타를 보고하거나 컨텐츠를 요청하십시오.