Quantum Transformer?

I was chatting with chatGPT today and parsed down these ideas.

I was given an example of code that could do quantum cross validation using qiskit using QVC coupled with sklearn’s linearmodel to do Quantum Cross Validation derived model and error metrics. I then developed an idea around how to build a quantum transformer. The response was to build one on a quantum computer which can be used as classical ‘quantum’ transformers as standins for qbits for functions like QVC.

I don’t have qiskit [setup], but I thought it would be interesting to try this out and maybe have quantum transformers (which are already being used in the 5g realm https://quantumtransformers.com/). I’m thinking of the research potential such as for doing quantum cross validation, maybe somehow modelling a wormhole in a classical computer.

I even have sample code for how to develop a quantum transformer, but I don’t have qiskit.

#Qiskit provides a template for creating a classical transformer using their QuantumCircuit class. The following code example shows how to construct a classical transformer in Python using the Qiskit library:


from qiskit import QuantumCircuit

# Create the quantum circuit with 3 qubits and 3 classical bits
qc = QuantumCircuit(3, 3)

# Add the gates to generate a "classical transformer"
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.measure([0,1,2], [0,1,2])

# Execute the quantum circuit and get the result
result = qc.execute()

# Print out the results
print(result.get_counts())

Here is the code I boiled down for quantum cross validation

def qcv(df):

import relevant libraries

from qiskit import Aer,execute
from qiskit.aqua.algorithms.classifiers.vqc import VQC
from sklearn.linear_model import LinearRegression

define input as all variables except forecast

X = df.drop(‘forecast’,axis=1)

define output as forecast

y = df[‘forecast’]

set the backend and create a quantum instance

backend = Aer.get_backend(‘qasm_simulator’)
quantum_instance = QuantumInstance(backend,shots=100)

create an instance of VQC using the model and quantum instance

vqc_model = VQC(LinearRegression(),quantum_instance=quantum_instance)

fit the model on the data

vqc_model.fit(X,y)

return the optimal parameters

return vqc_model.optimal_params

If it’s wrong, it’s wrong, but I know it can put together python code pretty effectively for smaller concepts, and coding a transformer. I don’t know how hard that is, but maybe this is kind of silly because a quantum state is like random noise maybe to a variable on a quantum system, I don’t know. Maybe it’s making wild guesses, but it’s using what it knows about qiskit and those are real functions.

1 Like