From b1fff2bd197100db7ad8332e0b70a6ce15b8b307 Mon Sep 17 00:00:00 2001 From: Kevin Joven <59969678+KevinJoven11@users.noreply.github.com> Date: Fri, 7 Oct 2022 00:22:50 -0400 Subject: [PATCH] Create superdense_coding.py This is part of the contribution to #Hacktoberfest. This is the superdense coding a quantum circuit related with the quantum entanglement. The circuit send two classical bits using one quantum bit. I hope that this can be consider for contribution. I am preparing the next quantum circuit to send to the hack. Best, Kevin J. --- quantum/superdense_coding.py | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 quantum/superdense_coding.py diff --git a/quantum/superdense_coding.py b/quantum/superdense_coding.py new file mode 100644 index 000000000000..37e4075ba6ab --- /dev/null +++ b/quantum/superdense_coding.py @@ -0,0 +1,70 @@ +""" +Build the superdense coding protocol. This quantum +circuit can send two classical bits using one quantum +bit. This circuit is designed using the Qiskit +framework. This experiment run in IBM Q simulator +with 1000 shots. +. +References: +https://qiskit.org/textbook/ch-algorithms/superdense-coding.html +https://en.wikipedia.org/wiki/Superdense_coding +""" + +import qiskit +from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer + +def superdense_coding( + c_information: str = '11' + ) -> qiskit.result.counts.Counts: + """ + # >>> superdense_coding(c_information) + # The input refer to the classical message + # that you wants to send. {'00','01','10','11'} + # result for default values: {11: 1000} + ┌───┐ ┌───┐ + qr_0: ─────┤ X ├──────────┤ X ├───── + ┌───┐└─┬─┘┌───┐┌───┐└─┬─┘┌───┐ + qr_1: ┤ H ├──■──┤ X ├┤ Z ├──■──┤ H ├ + └───┘ └───┘└───┘ └───┘ + cr: 2/══════════════════════════════ + Args: + c_information: classical information to send. + Returns: + qiskit.result.counts.Counts: counts of send state. + """ + # build registers + qr = QuantumRegister(2, 'qr') + cr = ClassicalRegister(2, 'cr') + + quantum_circuit = QuantumCircuit(qr,cr) + + # entanglement the qubits + quantum_circuit.h(1) + quantum_circuit.cx(1,0) + + # send the information + + if c_information == '11': + quantum_circuit.x(1) + quantum_circuit.z(1) + elif c_information == '10': + quantum_circuit.z(1) + elif c_information == '01': + quantum_circuit.x(1) + else: + quantum_circuit.i(1) + + #unentangled the circuit + quantum_circuit.cx(1,0) + quantum_circuit.h(1) + + # measure the circuit + quantum_circuit.measure(qr,cr) + + backend = Aer.get_backend('qasm_simulator') + job = execute(quantum_circuit, backend, shots=1000) + + return job.result().get_counts(quantum_circuit) + +if __name__ == "__main__": + print(f"Count for classical state send: {superdense_coding()}")