You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ra...@apache.org on 2024/01/24 19:29:46 UTC
(mahout) 04/05: add quantum teleportation
This is an automated email from the ASF dual-hosted git repository.
rawkintrevo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git
commit 7840bffe34b2611dee9b5c7f210b93dc6b948ac6
Author: Trevor Grant <tr...@gmail.com>
AuthorDate: Tue Jan 16 14:24:45 2024 -0600
add quantum teleportation
---
README.md | 2 +-
docs/index.md | 5 +++-
examples/quantum_teleportation.py | 62 +++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 83d62cb8b..51751d050 100644
--- a/README.md
+++ b/README.md
@@ -277,7 +277,7 @@ the particularities of each backend, so that you may 'write once, run
anywhere.' Like the Java of quantum computing, but Java is the new COBOL so
we're trying to distance ourselves from that comparison :P
-Check out [basic gates](basic_gates.md) for a quick introduction to the
+Check out [basic gates](docs/basic_gates.md) for a quick introduction to the
basic gates which are basically all that exist right now (and even those
only exist for `qiskit`).
>>>>>>> 94f6b12ef (fix image links)
diff --git a/docs/index.md b/docs/index.md
index e9655d6f5..5ed5a8133 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -10,4 +10,7 @@ we're trying to distance ourselves from that comparison :P
Check out [basic gates](basic_gates.md) for a quick introduction to the
basic gates which are basically all that exist right now (and even those
-only exist for `qiskit`).
\ No newline at end of file
+only exist for `qiskit`).
+
+You can also check out examples in the [examples](examples) directory. The
+cool one is [quantum teleportation](examples/quantum_teleportation.py).
\ No newline at end of file
diff --git a/examples/quantum_teleportation.py b/examples/quantum_teleportation.py
new file mode 100644
index 000000000..3f69f2558
--- /dev/null
+++ b/examples/quantum_teleportation.py
@@ -0,0 +1,62 @@
+# Example of implementing Quantum Teleportation using QuMat
+
+# Initialize your QuMat quantum computer with the chosen backend
+backend_config = {
+ 'backend_name': 'qiskit_simulator',
+ 'backend_options': {
+ 'simulator_type': 'qasm_simulator',
+ 'shots': 1 # Set to 1 for teleportation
+ }
+}
+
+quantum_computer = QuMat(backend_config)
+
+# Create an empty circuit with 3 qubits: one for the state to be teleported,
+# and two for entanglement
+quantum_computer.create_empty_circuit(3)
+
+# Step 1: Create entanglement between qubits 1 and 2
+quantum_computer.apply_hadamard_gate(1)
+quantum_computer.apply_cnot_gate(1, 2)
+
+# Step 2: Prepare the state to be teleported on qubit 0
+quantum_computer.apply_hadamard_gate(0)
+quantum_computer.apply_pauli_z_gate(0) # Simulating an arbitrary state
+
+# Step 3: Perform Bell measurement on qubits 0 and 1
+quantum_computer.apply_cnot_gate(0, 1)
+quantum_computer.apply_hadamard_gate(0)
+
+# Measure qubits 0 and 1
+quantum_computer.circuit.measure([0, 1], [0, 1])
+
+# Step 4: Communicate measurement results to the receiver
+
+# In a real quantum teleportation scenario, you would send the measurement results
+# (classical bits) to the receiver via a classical communication channel.
+
+# Step 5: Apply gates based on the measurement results
+
+# Receiver's side:
+# Initialize a quantum computer with the same backend
+receiver_quantum_computer = QuMat(backend_config)
+receiver_quantum_computer.create_empty_circuit(3)
+
+# Apply X and Z gates based on the received measurement results
+received_measurement_results = [0, 1] # Simulated measurement results
+if received_measurement_results[1] == 1:
+ receiver_quantum_computer.apply_x_gate(2)
+if received_measurement_results[0] == 1:
+ receiver_quantum_computer.apply_z_gate(2)
+
+# The state on qubit 2 now matches the original state on qubit 0
+
+# Step 6: Measure the received state (optional)
+receiver_quantum_computer.circuit.measure(2, 2)
+
+# Execute the quantum circuits and get the measurement results
+sender_results = quantum_computer.execute_circuit()
+receiver_results = receiver_quantum_computer.execute_circuit()
+
+print("Sender's measurement results:", sender_results)
+print("Receiver's measurement results:", receiver_results)