QNNCircuit#

class QNNCircuit(num_qubits=None, feature_map=None, ansatz=None)[source]#

Bases: BlueprintCircuit

The QNN circuit is a blueprint circuit that wraps feature map and ansatz circuits. It can be used to simplify the composition of these two.

If only the number of qubits is provided the RealAmplitudes ansatz and the ZZFeatureMap feature map are used. If the number of qubits is 1 the ZFeatureMap is used. If only a feature map is provided, the RealAmplitudes ansatz with the corresponding number of qubits is used. If only an ansatz is provided the ZZFeatureMap with the corresponding number of qubits is used.

At least one parameter has to be provided. If a feature map and an ansatz is provided, the number of qubits must be the same.

In case number of qubits is provided along with either a feature map, an ansatz or both, a potential mismatch between the three inputs with respect to the number of qubits is resolved by constructing the QNNCircuit with the given number of qubits. If one of the QNNCircuit properties is set after the class construction, the circuit is adjusted to incorporate the changes. This means, a new valid configuration that considers the latest property update will be derived. This ensures that the classes properties are consistent at all times.

Example:

from qiskit_machine_learning.circuit.library import QNNCircuit
qnn_qc = QNNCircuit(2)
print(qnn_qc)
# prints:
#      ┌──────────────────────────┐»
# q_0: ┤0                         ├»
#      │  ZZFeatureMap(x[0],x[1]) │»
# q_1: ┤1                         ├»
#      └──────────────────────────┘»
# «     ┌──────────────────────────────────────────────────────────┐
# «q_0: ┤0                                                         ├
# «     │  RealAmplitudes(θ[0],θ[1],θ[2],θ[3],θ[4],θ[5],θ[6],θ[7]) │
# «q_1: ┤1                                                         ├
# «     └──────────────────────────────────────────────────────────┘

print(qnn_qc.num_qubits)
# prints: 2

print(qnn_qc.input_parameters)
# prints: ParameterView([ParameterVectorElement(x[0]), ParameterVectorElement(x[1])])

print(qnn_qc.weight_parameters)
# prints: ParameterView([ParameterVectorElement(θ[0]), ParameterVectorElement(θ[1]),
#         ParameterVectorElement(θ[2]), ParameterVectorElement(θ[3]),
#         ParameterVectorElement(θ[4]), ParameterVectorElement(θ[5]),
#         ParameterVectorElement(θ[6]), ParameterVectorElement(θ[7])])

Although all parameters default to None at least one parameter must be provided, to determine the number of qubits from it, when the instance is created.

If more than one parameter is passed:

1) If num_qubits is provided the feature map and/or ansatz supplied will be overridden to circuits with num_qubits, as long as the respective circuit supports updating its number of qubits.

2) If num_qubits is not provided the feature_map and ansatz must be set to the same number of qubits.

প্যারামিটার:
  • num_qubits (int | None) -- Number of qubits, a positive integer. Optional if feature_map or ansatz is provided, otherwise required. If not provided num_qubits defaults from the sizes of feature_map and ansatz.

  • feature_map (QuantumCircuit | None) -- A feature map. Optional if num_qubits or ansatz is provided, otherwise required. If not provided defaults to ZZFeatureMap or ZFeatureMap if num_qubits is determined to be 1.

  • ansatz (QuantumCircuit | None) -- An ansatz. Optional if num_qubits or feature_map is provided, otherwise required. If not provided defaults to RealAmplitudes.

রিটার্নস:

The composed feature map and ansatz circuit.

রেইজেস:

QiskitMachineLearningError -- If a valid number of qubits cannot be derived from the provided input arguments.

রিটার্ন টাইপ:

None

Attributes

ansatz#

Returns ansatz.

রিটার্নস:

The ansatz.

feature_map#

Returns feature_map.

রিটার্নস:

The feature map.

input_parameters#

Returns the parameters of the feature map.

রিটার্নস:

The parameters of the feature map.

num_input_parameters#

Returns the number of input parameters in the circuit.

রিটার্নস:

The number of input parameters.

num_qubits#

Returns the number of qubits in this circuit.

রিটার্নস:

The number of qubits.

num_weight_parameters#

Returns the number of weights in the circuit.

রিটার্নস:

The number of weights.

weight_parameters#

Returns the parameters of the ansatz. These corresponding to the trainable weights.

রিটার্নস:

The parameters of the ansatz.

Methods