Python:实现quantum entanglement量子纠缠技术算法(附完整源码)

51CTO 2022-08-06 09:33:11 阅读数:866

Python实现量子quantumentanglement


Python:实现quantum entanglement量子纠缠技术算法

import qiskit


def quantum_entanglement( qubits: int = 2) - > qiskit. result. counts. Counts:

classical_bits = qubits

# Using Aer's qasm_simulator
simulator = qiskit. Aer. get_backend( "qasm_simulator")

# Creating a Quantum Circuit acting on the q register
circuit = qiskit. QuantumCircuit( qubits, classical_bits)

# Adding a H gate on qubit 0 (now q0 in superposition)
circuit. h( 0)

for i in range( 1, qubits):
# Adding CX (CNOT) gate
circuit. cx( i - 1, i)

# Mapping the quantum measurement to the classical bits
circuit. measure( list( range( qubits)), list( range( classical_bits)))

# Now measuring any one qubit would affect other qubits to collapse
# their super position and have same state as the measured one.

# Executing the circuit on the qasm simulator
job = qiskit. execute( circuit, simulator, shots = 1000)

return job. result(). get_counts( circuit)


if __name__ == "__main__":
print( f"Total count for various states are: { quantum_entanglement( 3)} ")
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.


版权声明:本文为[51CTO]所创,转载请带上原文链接,感谢。 https://blog.51cto.com/u_11929818/5551012