0

Basically old qiskit-machine learning had QuantumKernel a class that did all the work.(feature_map, traning_parameters, construct_circuit, evalute etc.). However, it's been seperated and changed as BaseKernel, FidelityQuantumKernel, TrainableKernel, TrainableFidelityQuantumKernel. A quantum circuit could have been created with a kernel created with "Quantumkernel", with the selected simulator and parameters, but this does not seem possible at the moment. Below is an example made with QuantumKernel, but it does not work because it is no longer in use. In short, which Kernel class can I use to do the same job instead of QuantumKernel?

So, I need to use one of these new QuantumKernels with qasm as simulator, ZZfeatureMap as my feature map, with some parameters, shots, seed_simulator and seeds_transpiler to calculate its amplitude

sample code:

x = [-0.1,0.2]
y = [0.4,-0.6]

zz_map = ZZFeatureMap(feature_dimension=2, reps=4) zz_kernel=QuantumKernel(feature_map=zz_map,quantum_instance=Aer.get_backend('statevector_simulator')) zz_circuit =zz_kernel.construct_circuit(x,y) backend =Aer.get_backend('qasm_simulator') job = execute(zz_circuit,backend,shots=8192, seed_simulator=1024, seed_transpiler=1024) counts = job.result().get_counts(zz_circuit)

amplitude= counts['00']/sum(counts.values())

Also i have tried many different codes but i failed:

Here is one of them (issues: FidelityQKernel has no construct_circuit):

x = [-0.1,0.2]
y = [0.4,-0.6]

zz_map = ZZFeatureMap(feature_dimension=2, reps=4, entanglement="linear")

sampler = Sampler() backend = Aer.get_backend('qasm_simulator') fidelity = ComputeUncompute(sampler=sampler) zz_kernel = FidelityQuantumKernel(fidelity=fidelity, feature_map=zz_map) qc = zz_kernel.construct_circuit(x, y) kernel_matrix = zz_kernel.evaluate(x_vec=[x], y_vec=[y]) job = backend.run(kernel_matrix ,shots=8192, seed_simulator=1024, seed_transpiler=1024) job = backend.run(qc ,shots=8192, seed_simulator=1024, seed_transpiler=1024) amplitude = kernel_matrix[0][0] print(amplitude) counts = job.result().get_counts(kernel_matrix) amplitude2= counts['00']/sum(counts.values()) print(amplitude2)

```

0 Answers0