Execution
expectation(x, observable, values=None, state=None, backend=BackendName.PYQTORCH, diff_mode=None, noise=None, endianness=Endianness.BIG, configuration=None)
Section titled “
expectation(x, observable, values=None, state=None, backend=BackendName.PYQTORCH, diff_mode=None, noise=None, endianness=Endianness.BIG, configuration=None)
”Convenience wrapper for the QuantumModel.expectation method.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Circuit, block, or (register+block) to run.
TYPE:
|
observable
|
Observable(s) w.r.t. which the expectation is computed.
TYPE:
|
values
|
User-facing parameter dict.
TYPE:
|
state
|
Initial state.
TYPE:
|
backend
|
Name of the backend to run on.
TYPE:
|
diff_mode
|
Which differentiation mode to use.
TYPE:
|
endianness
|
The target device endianness.
TYPE:
|
configuration
|
The backend configuration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A wavefunction |
from qadence import RX, Z, Register, QuantumCircuit, expectation
reg = Register(1)block = RX(0, 0.5)observable = Z(0)circ = QuantumCircuit(reg, block)
# You can compute the expectation for a# QuantumCircuit with a given observable.expectation(circ, observable)
# You can also use only a block.# In this case the register is constructed automatically to# Register.line(block.n_qubits)expectation(block, observable)
# Or a register and blockexpectation(reg, block, observable)Source code in qadence/execution.py
184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233@singledispatchdef expectation( x: Union[QuantumCircuit, AbstractBlock, Register, int], observable: Union[list[AbstractBlock], AbstractBlock], values: Union[dict, None] = None, state: Tensor = None, backend: BackendName = BackendName.PYQTORCH, diff_mode: Union[DiffMode, str, None] = None, noise: Union[NoiseHandler, None] = None, endianness: Endianness = Endianness.BIG, configuration: Union[BackendConfiguration, dict, None] = None,) -> Tensor: """Convenience wrapper for the `QuantumModel.expectation` method.
Arguments: x: Circuit, block, or (register+block) to run. observable: Observable(s) w.r.t. which the expectation is computed. values: User-facing parameter dict. state: Initial state. backend: Name of the backend to run on. diff_mode: Which differentiation mode to use. endianness: The target device endianness. configuration: The backend configuration.
Returns: A wavefunction
```python exec="on" source="material-block" from qadence import RX, Z, Register, QuantumCircuit, expectation
reg = Register(1) block = RX(0, 0.5) observable = Z(0) circ = QuantumCircuit(reg, block)
# You can compute the expectation for a # QuantumCircuit with a given observable. expectation(circ, observable)
# You can also use only a block. # In this case the register is constructed automatically to # Register.line(block.n_qubits) expectation(block, observable)
# Or a register and block expectation(reg, block, observable) ``` """
raise ValueError(f"Cannot execute {type(x)}")
run(x, *args, values=None, state=None, backend=BackendName.PYQTORCH, endianness=Endianness.BIG, configuration=None)
Section titled “
run(x, *args, values=None, state=None, backend=BackendName.PYQTORCH, endianness=Endianness.BIG, configuration=None)
”Convenience wrapper for the QuantumModel.run method.
This is a
functools.singledispatched function so it can be called with a number of different arguments.
See the examples of the expectation function. This function
works exactly the same.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Circuit, block, or (register+block) to run.
TYPE:
|
values
|
User-facing parameter dict.
TYPE:
|
state
|
Initial state.
TYPE:
|
backend
|
Name of the backend to run on.
TYPE:
|
endianness
|
The target device endianness.
TYPE:
|
configuration
|
The backend configuration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A wavefunction |
Source code in qadence/execution.py
3435363738394041424344454647484950515253545556575859606162@singledispatchdef run( x: Union[QuantumCircuit, AbstractBlock, Register, int], *args: Any, values: Union[dict, None] = None, state: Tensor = None, backend: BackendName = BackendName.PYQTORCH, endianness: Endianness = Endianness.BIG, configuration: Union[BackendConfiguration, dict, None] = None,) -> Tensor: """Convenience wrapper for the `QuantumModel.run` method.
This is a `functools.singledispatch`ed function so it can be called with a number of different arguments. See the examples of the [`expectation`][qadence.execution.expectation] function. This function works exactly the same.
Arguments: x: Circuit, block, or (register+block) to run. values: User-facing parameter dict. state: Initial state. backend: Name of the backend to run on. endianness: The target device endianness. configuration: The backend configuration.
Returns: A wavefunction """ raise ValueError(f"Cannot run {type(x)}")
sample(x, *args, values=None, state=None, n_shots=100, backend=BackendName.PYQTORCH, endianness=Endianness.BIG, noise=None, configuration=None)
Section titled “
sample(x, *args, values=None, state=None, n_shots=100, backend=BackendName.PYQTORCH, endianness=Endianness.BIG, noise=None, configuration=None)
”Convenience wrapper for the QuantumModel.sample method.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Circuit, block, or (register+block) to run.
TYPE:
|
values
|
User-facing parameter dict.
TYPE:
|
state
|
Initial state.
TYPE:
|
n_shots
|
Number of shots per element in the batch.
TYPE:
|
backend
|
Name of the backend to run on.
TYPE:
|
endianness
|
The target device endianness.
TYPE:
|
noise
|
The noise model to use if any.
TYPE:
|
configuration
|
The backend configuration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Counter]
|
A list of Counter instances with the sample results |
Source code in qadence/execution.py
112113114115116117118119120121122123124125126127128129130131132133134135136137138139@singledispatchdef sample( x: Union[QuantumCircuit, AbstractBlock, Register, int], *args: Any, values: Union[dict, None] = None, state: Union[Tensor, None] = None, n_shots: int = 100, backend: BackendName = BackendName.PYQTORCH, endianness: Endianness = Endianness.BIG, noise: Union[NoiseHandler, None] = None, configuration: Union[BackendConfiguration, dict, None] = None,) -> list[Counter]: """Convenience wrapper for the `QuantumModel.sample` method.
Arguments: x: Circuit, block, or (register+block) to run. values: User-facing parameter dict. state: Initial state. n_shots: Number of shots per element in the batch. backend: Name of the backend to run on. endianness: The target device endianness. noise: The noise model to use if any. configuration: The backend configuration.
Returns: A list of Counter instances with the sample results """ raise ValueError(f"Cannot sample from {type(x)}")