QrSamplerV1 module
- class QrSamplerV1
Creates a QrSamplerV1 object that calculates quasi-probabilities of bitstrings from quantum circuits. Derives from the qiskit SamplerV1 class.
When the quantum circuit is executed using the method
quantumrings.toolkit.qiskit.QrSamplerV1.run()
, this class returns aquantumrings.toolkit.qiskit.QrJobV1
object.Calling the method
quantumrings.toolkit.qiskit.QrJobV1.result()
yields aSamplerResult
object, which contains probabilities or quasi-probabilities of the sampled bitstrings.
- QrSamplerV1(backend=None, options=None, run_options=None)
- Args:
- backend: The QrBackendV2 backend. If no backend is provided, then the sampler will try to load the Quantum Rings backend using theaccount saved locally.options: The options to control the default shots(
shots
)run_options: See options above.
- QrSamplerV1.options: Options
Return the options
- run(self, circuits, parameter_values, **run_options)
Run the sampling job.
Example:
from quantumrings.toolkit.qiskit import QrSamplerV1 as Sampler from qiskit import QuantumCircuit from qiskit.circuit.library import RealAmplitudes # a Bell circuit bell = QuantumCircuit(2) bell.h(0) bell.cx(0, 1) bell.measure_all() # two parameterized circuits pqc = RealAmplitudes(num_qubits=2, reps=2) pqc.measure_all() pqc2 = RealAmplitudes(num_qubits=2, reps=3) pqc2.measure_all() theta1 = [0, 1, 1, 2, 3, 5] theta2 = [0, 1, 2, 3, 4, 5, 6, 7] # initialization of the sampler sampler = Sampler() # Sampler runs a job on the Bell circuit job = sampler.run(circuits=[bell], parameter_values=[[]], parameters=[[]]) job_result = job.result() print([q.binary_probabilities() for q in job_result.quasi_dists]) # Sampler runs a job on the parameterized circuits job2 = sampler.run( circuits=[pqc, pqc2], parameter_values=[theta1, theta2], parameters=[pqc.parameters, pqc2.parameters]) job_result = job2.result() print([q.binary_probabilities() for q in job_result.quasi_dists])
- Args:
- circuits [
QuantumCircuit
]: One of more (parameterized) quantum circuit objects.parameter_values [[float]]: Parameters to be bound to the circuit.run_options: Backend runtime options used for circuit execution. - Returns:
The job object of the result of the sampler. The i-th result corresponds to
circuits[i]
evaluated with parameters bound asparameter_values[i]
.- Raises:
Exception: Invalid arguments are given.