MQSSPennylaneDevice¶
Bases: Device
Implements a Custom Pennylane Device that uses MQSS as a backend.
Attributes¶
TOKEN : str Munich Quantum Portal (MQP) Token BACKENDS : str Munich Quantum Portal (MQP) Backend Methods
init(self): Constructor execute(self, circuits, execution_config, shots): Sends the Pennylane circuit to the specified MQSS backend.
__init__ ¶
__init__(token: str, backends: str, wires=None, shots=None, seed=None, supports_derivatives=False)
Construct an MQSSPennylaneDevice Object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
str
|
Munich Quantum Portal (MQP) token |
required |
backends
|
str
|
MQP backend |
required |
wires
|
int
|
Number of wires in the circuit Defaults to None. |
None
|
shots
|
int
|
Number of shots, for expectation values leave it as None. Defaults to None. |
None
|
seed
|
int
|
Defaults to None. |
None
|
supports_derivatives
|
bool
|
Boolean flag for autograd support. Defaults to False. |
False
|
append_measurement_gates ¶
append_measurement_gates(circuits: QuantumScriptOrBatch, obs: ops, is_hamiltonian: bool) -> QuantumScriptOrBatch
Append gates for basis change for measurements in non-Z basis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circuits
|
QuantumScriptOrBatch
|
Pennylane circuit |
required |
obs
|
ops
|
The measured observable |
required |
is_hamiltonian
|
bool
|
Indicates if there is a hamiltonian expectation value calculation |
required |
calculate_measurement_type ¶
calculate_measurement_type(counts: TensorLike, circuits: QuantumScriptOrBatch, shots: int, is_hamiltonian: bool) -> Union[list[TensorLike], list[float]]
Given a measurement type (e.g. probs, exp. val.), return the measurement result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts
|
list
|
List of sampled measurements |
required |
circuits
|
Qnode
|
Pennylane circuit |
required |
shots
|
int
|
Number of shots |
required |
is_hamiltonian
|
bool
|
Indicates if there is a hamiltonian expectation value calculation |
required |
create_batch_circuits_for_hamiltonians ¶
create_batch_circuits_for_hamiltonians(tape: QuantumScriptOrBatch, is_hamiltonian: bool) -> list[QuantumScriptOrBatch]
Creates a batched job where there is a Hamiltonian expectation value calculation as measurement
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tape
|
QuantumScriptOrBatch
|
Original quantum circuit |
required |
is_hamiltonian
|
bool
|
Indicates if there is a hamiltonian expectation value calculation |
required |
Returns:
Type | Description |
---|---|
list[QuantumScriptOrBatch]
|
list[QuantumScriptOrBatch]: Batch of circuits for each term in the Hamiltonian |
execute ¶
execute(circuits: QuantumScriptOrBatch, execution_config: DefaultExecutionConfig, shots=1024) -> TensorLike
Sends the Pennylane circuit to the specified MQSS backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circuits
|
QuantumScriptOrBatch
|
Pennylane circuit |
required |
execution_config
|
DefaultExecutionConfig
|
Additional config for the circuit if necessary |
required |
shots
|
int
|
Number of shots. Defaults to 1024. |
1024
|
Returns:
Name | Type | Description |
---|---|---|
TensorLike |
TensorLike
|
Measurement results |
fetch_counts ¶
fetch_counts(result: Union[Result, ResultBatch], shots: int) -> list[Result]
Given a dictionary representing the measurements, return the probability distribution as an array
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
Result
|
Results of the quantum job |
required |
shots
|
int
|
Number of shots |
required |
Returns:
Name | Type | Description |
---|---|---|
probs |
ndarray
|
The probability distribution of the measurements |
get_expectation_value ¶
get_expectation_value(count: list[float], measured_qubits: list[int], num_qubits: int, shots: int)
Calculate the expectation value from the counts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts
|
list[float]
|
List of sampled measurements |
required |
measured_qubits
|
list[int]
|
The qubits involved in measurement process |
required |
num_qubits
|
int
|
Number of circuits of the given circuit |
required |
shots
|
int
|
Number of shots |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Raised in case of the number of wires missing |
validate_tape_operations ¶
validate_tape_operations(tape: QuantumScriptOrBatch)
Validate if the operations in the tape are all supported
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tape
|
QuantumScriptOrBatch
|
Pennylane circuit |
required |