Skip to content

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=1024, 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

Legacy attribute for number of shots. Now, shots attribute is expected at the QNode level, but this attribute stays as a legacy fallback option. Defaults to 1024.

1024
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(result, circuits: QuantumScriptOrBatch, shots: int, is_hamiltonian: bool) -> Union[list[TensorLike], Union[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(circuit: QuantumScriptOrBatch, is_hamiltonian: bool) -> Union[list[QuantumScriptOrBatch], QuantumScriptOrBatch]

Creates a batched job where there is a Hamiltonian expectation value calculation as measurement

Parameters:

Name Type Description Default
circuit QuantumScriptOrBatch

Original quantum circuit

required
is_hamiltonian bool

Indicates if there is a hamiltonian expectation value calculation

required

Returns:

Type Description
Union[list[QuantumScriptOrBatch], QuantumScriptOrBatch]

list[QuantumScriptOrBatch]: Batch of circuits for each term in the Hamiltonian

determine_measurement_type

determine_measurement_type(circuit: QuantumScriptOrBatch) -> MeasurementType

Determines the measurement type of the given tape.

Parameters:

Name Type Description Default
tape QuantumScriptOrBatch

Pennylane circuit

required

Returns:

Name Type Description
MeasurementType MeasurementType

The type of measurement in the tape

execute

execute(circuits: Tuple[QuantumScriptOrBatch] | QuantumScriptOrBatch, execution_config: ExecutionConfig) -> TensorLike

Sends the Pennylane circuit to the specified MQSS backend.

Parameters:

Name Type Description Default
circuits QuantumScriptOrBatch

Pennylane circuit

required
execution_config ExecutionConfig

Additional config for the circuit if necessary

required

Returns:

Name Type Description
TensorLike TensorLike

Measurement results

fetch_counts

fetch_counts(counts: dict[str, int] | list[dict[str, int]], shots: int) -> dict[str, int] | list[dict[str, int]]

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: dict[str, int] | list[dict[str, int]], measured_qubits: tuple[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 tuple[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

reverse_bit_order

reverse_bit_order(counts: dict) -> dict

Reverse the order of bits in a bitstring. Pennylane uses big-endian ending which contradicts with Qiskit's little-endian ordering, so we need to reverse the bit order when converting between the two formats. This function takes a bitstring as input and returns the reversed bitstring.

Parameters:

Name Type Description Default
counts dict

The counts dictionary whose input bitstrings is to be reversed.

required

Returns:

Name Type Description
dict dict

The reversed bitstring.

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