Source code for mqt.bench.benchmarks.bmw_quark_cardinality
# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM# Copyright (c) 2025 Munich Quantum Software Company GmbH# All rights reserved.## SPDX-License-Identifier: MIT## Licensed under the MIT License# Copyright 2021 The QUARK Authors. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License."""Cardinality circuit from the generative modeling application in QUARK framework. https://github.com/QUARK-framework/QUARK."""from__future__importannotationsfromqiskit.circuitimportParameter,ParameterVector,QuantumCircuitfromqiskit.circuit.libraryimportRXXGatefrom._registryimportregister_benchmark
[docs]@register_benchmark("bmw_quark_cardinality",description="Cardinality Circuit (QUARK)")defcreate_circuit(num_qubits:int,depth:int=3)->QuantumCircuit:"""Returns a Qiskit circuit based on the cardinality circuit architecture from the QUARK framework. Arguments: num_qubits: number of qubits of the returned quantum circuit depth: depth of the returned quantum circuit """qc=QuantumCircuit(num_qubits)# === Precompute parameter count ===num_initial=2*num_qubitsnum_rxx=depth*(num_qubits-1)num_mid_layers=(depth-2)*2*num_qubitsifdepth>1else0num_final_layer=3*num_qubitsifdepth>=2else0total_params=num_initial+num_rxx+num_mid_layers+num_final_layerparam_vector=ParameterVector("p",length=total_params)param_index=0defget_param()->Parameter:nonlocalparam_indexparam=param_vector[param_index]param_index+=1returnparam# === Initial single-qubit rotations ===forqinrange(num_qubits):qc.rx(get_param(),q)qc.rz(get_param(),q)# === Layered structure ===fordinrange(depth):qc.barrier()forqinrange(num_qubits-1):qc.append(RXXGate(get_param()),[q,q+1])qc.barrier()ifd==depth-2:forqinrange(num_qubits):qc.rx(get_param(),q)qc.rz(get_param(),q)qc.rx(get_param(),q)elifd<depth-2:forqinrange(num_qubits):qc.rx(get_param(),q)qc.rz(get_param(),q)qc.measure_all()qc.name="bmw_quark_cardinality"returnqc