[docs]defcircuit_method(idx:int,target_circuit:QuantumCircuit,target_key:str,exp_name:str,unitary_operator:Union[Operator,Gate,Literal["x","y","z"]],i:int,j:int,)->QuantumCircuit:"""Build the circuit for the experiment. Args: idx (int): Index of the quantum circuit. target_circuit (QuantumCircuit): Target circuit. target_key (Hashable): Target key. exp_name (str): Experiment name. unitary_operator (Union[Operator, Gate, Literal["x", "y", "z"]]): The unitary operator to apply. It can be a `qiskit.quantum_info.Operator`, a `qiskit.circuit.Gate`, or a string representing the axis of rotation ('x', 'y', or 'z'). i (int): The index of the target qubit. j (int): The index of the target qubit. Returns: QuantumCircuit: The circuit for the experiment. """old_name=""ifisinstance(target_circuit.name,str)elsetarget_circuit.nameqc_exp1=target_circuit.copy(f"{exp_name}_{idx}_{i}_{j}"+(""iftarget_keyelsef".{target_key}")+(""ifold_nameelsef".{old_name}"))c_meas1=ClassicalRegister(2,"c_m1")qc_exp1.add_register(c_meas1)qc_exp1.barrier()ifisinstance(unitary_operator,Operator):qc_exp1.unitary(unitary_operator,[qc_exp1.qubits[i]],label="U")qc_exp1.unitary(unitary_operator,[qc_exp1.qubits[j]],label="U")elifisinstance(unitary_operator,Gate):qc_exp1.append(unitary_operator,[qc_exp1.qubits[i]])qc_exp1.append(unitary_operator,[qc_exp1.qubits[j]])elifunitary_operator=="x":qc_exp1.x(qc_exp1.qubits[i])qc_exp1.x(qc_exp1.qubits[j])elifunitary_operator=="y":qc_exp1.y(qc_exp1.qubits[i])qc_exp1.y(qc_exp1.qubits[j])elifunitary_operator=="z":...else:raiseValueError(f"Invalid unitary operator: {unitary_operator}. ""It should be an Operator, Gate, or one of 'x', 'y', 'z'.")qc_exp1.measure(qc_exp1.qubits[i],c_meas1[0])qc_exp1.measure(qc_exp1.qubits[j],c_meas1[1])returnqc_exp1