# PySpark: read CSV and compute aggregate
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("BigDataQuantum").getOrCreate()
df = spark.read.csv("hdfs://data/sales.csv", header=True)
df.groupBy("region").sum("revenue").show()# Qiskit example: superposition + entanglement
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0); qc.cx(0,1)
qc.draw()# Example QUBO for MaxCut on 3 vertices
# Maximize sum_{(i,j) in E} (1 - s_i s_j)/2 → minimize s^T W s
# Convert to QUBO: Q matrix
import numpy as np
Q = np.array([[-0.5, 1, 1], [0, -0.5, 1], [0, 0, -0.5]]) # upper triangular
# Solve via simulated annealing or quantum annealerimport pennylane as qml
import torch
dev = qml.device('default.qubit', wires=2)
@qml.qnode(dev, interface='torch')
def circuit(x, weights):
qml.AngleEmbedding(x, wires=[0,1])
qml.BasicEntanglerLayers(weights, wires=[0,1])
return qml.expval(qml.PauliZ(0))
# Hybrid model
class HybridModel(torch.nn.Module):
def __init__(self):
super().__init__()
self.clayer = torch.nn.Linear(2, 2)
self.qweights = torch.randn(2,2, requires_grad=True)
def forward(self, x):
x = self.clayer(x)
return circuit(x, self.qweights)# Quantum kernel with PennyLane
dev = qml.device('default.qubit', wires=2)
@qml.qnode(dev)
def kernel_circuit(x1, x2):
qml.AngleEmbedding(x1, wires=[0,1])
qml.adjoint(qml.AngleEmbedding)(x2, wires=[0,1])
return qml.probs(wires=[0,1])
# Kernel = probability of |00⟩ after interference# D‑Wave Ocean SDK example
from dwave.system import DWaveSampler, EmbeddingComposite
sampler = EmbeddingComposite(DWaveSampler())
Q = {('x1','x1'): -1, ('x2','x2'): -1, ('x1','x2'): 2}
sampleset = sampler.sample_qubo(Q, num_reads=100)
print(sampleset.first)# Using TensorLy and quimb
import tensornetwork as tn
# Create a random MPS for 10 sites, bond dimension 4
nodes = [tn.Node(np.random.rand(2,4,4)) for _ in range(10)]
# Contract to compute expectation value
result = tn.contractors.auto(nodes).tensor# AWS Braket hybrid job (simulator)
from braket.circuits import Circuit
from braket.devices import LocalSimulator
from braket.aws import AwsDevice
circ = Circuit().h(0).cnot(0,1)
device = LocalSimulator()
result = device.run(circ, shots=1000).result()
# For real hardware: device = AwsDevice("arn:aws:braket:...")