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:42 UTC

(mahout) branch main updated (84ca94603 -> 824582044)

This is an automated email from the ASF dual-hosted git repository.

rawkintrevo pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git


    from 84ca94603 Removing travis yaml
     new 71990f9c0 Qumat Donation
     new d0206bb77 Add docs
     new 2e5f41eaf donate qumat
     new 7840bffe3 add quantum teleportation
     new 824582044 Closes #1

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                        |   6 +++
 README.md                         |  16 ++++++++
 docs/assets/mascot.png            | Bin 0 -> 1004488 bytes
 docs/basic_gates.md               |  27 +++++++++++++
 docs/getting_started.md           |   0
 docs/index.md                     |  16 ++++++++
 examples/quantum_teleportation.py |  62 ++++++++++++++++++++++++++++++
 examples/simple_example.py        |  26 +++++++++++++
 pyproject.toml                    |  17 ++++++++
 qumat/__init__.py                 |   0
 qumat/qumat.py                    |  79 ++++++++++++++++++++++++++++++++++++++
 requirements.txt                  |   1 +
 12 files changed, 250 insertions(+)
 create mode 100644 docs/assets/mascot.png
 create mode 100644 docs/basic_gates.md
 create mode 100644 docs/getting_started.md
 create mode 100644 docs/index.md
 create mode 100644 examples/quantum_teleportation.py
 create mode 100644 examples/simple_example.py
 create mode 100644 pyproject.toml
 create mode 100644 qumat/__init__.py
 create mode 100644 qumat/qumat.py
 create mode 100644 requirements.txt


(mahout) 01/05: Qumat Donation

Posted by ra...@apache.org.
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 71990f9c02c251be65cc06223d9686b3ba2ff83e
Author: trevor grant <tr...@aboriginal-armadillo.com>
AuthorDate: Wed Jan 24 13:27:49 2024 -0600

    Qumat Donation
---
 .gitignore                    |  6 ++++
 examples/simple_example.py    | 26 ++++++++++++++
 requirements.txt              |  1 +
 src/qumat/__init__.py         |  0
 src/qumat/quantum_computer.py | 79 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 112 insertions(+)

diff --git a/.gitignore b/.gitignore
index b89159cee..58fd1b797 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+
 output-asf-email-examples/
 .checkstyle
 .ruleset
@@ -29,3 +30,8 @@ website/_site
 website/Gemfile.lock
 website/.bundle
 website/.sass-cache
+
+*.iml
+.idea
+venv
+
diff --git a/examples/simple_example.py b/examples/simple_example.py
new file mode 100644
index 000000000..f2531ab10
--- /dev/null
+++ b/examples/simple_example.py
@@ -0,0 +1,26 @@
+# Import the QuantumComputer class from your package
+from qumat import QuMat
+
+# Create an instance of QuantumComputer with a specific backend configuration
+backend_config = {
+    'backend_name': 'qiskit_simulator',  # Replace with the actual backend you want to use
+    'backend_options': {
+        'simulator_type': 'qasm_simulator',
+        'shots': 1024  # Number of shots for measurement
+    }
+}
+qumat = QuMat(backend_config)
+
+# Create a quantum circuit
+quantum_circuit = qumat.create_empty_circuit(num_qubits=2)
+
+# Apply quantum gates to the circuit
+quantum_circuit.apply_hadamard_gate(qubit_index=0)
+quantum_circuit.apply_cnot_gate(control_qubit_index=0, target_qubit_index=1)
+quantum_circuit.apply_pauli_x_gate(qubit_index=0)
+
+# Measure the quantum circuit
+measurement_results = quantum_circuit.measure()
+
+# Display the measurement results
+print("Measurement Results:", measurement_results)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 000000000..849ed68fe
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+qiskit
diff --git a/src/qumat/__init__.py b/src/qumat/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/qumat/quantum_computer.py b/src/qumat/quantum_computer.py
new file mode 100644
index 000000000..35e8323bb
--- /dev/null
+++ b/src/qumat/quantum_computer.py
@@ -0,0 +1,79 @@
+import qiskit
+
+
+class QuMat:
+    def __init__(self, backend_config):
+        # Initialize the quantum computer with the chosen backend configuration
+        self.backend_config = backend_config
+        # Initialize the quantum backend (Qiskit, Cirq, Bracket, etc.) based on
+        # the config
+        self.backend = qiskit.Aer.get_backend(backend_config['backend_name'])
+        self.backend = self._initialize_backend()
+        self.backend_name = backend_config['backend_name']
+        # Initialize an empty quantum circuit
+        self.circuit = None
+
+    def _initialize_backend(self):
+
+        # Add logic to initialize the backend using the backend name
+        # For example, if using qiskit:
+        if self.backend_name == 'qiskit_simulator':
+            backend_options = self.backend_config['backend_options']
+            simulator_type = backend_options['simulator_type']
+            shots = backend_options['shots']
+            backend = qiskit.Aer.get_backend(simulator_type)
+            backend.shots = shots
+            return backend
+        else:
+            raise NotImplementedError(f"Backend '{self.backend_name}' is not "
+                                      f"supported.")
+
+    def create_empty_circuit(self, num_qubits):
+        # Create an empty quantum circuit with the specified number of qubits
+        self.circuit = qiskit.QuantumCircuit(num_qubits)
+
+    def apply_not_gate(self, qubit_index):
+        # Apply a NOT gate (X gate) on the specified qubit
+        self.circuit.x(qubit_index)
+
+    def apply_hadamard_gate(self, qubit_index):
+        # Apply a Hadamard gate on the specified qubit
+        self.circuit.h(qubit_index)
+
+    def apply_cnot_gate(self, control_qubit_index, target_qubit_index):
+        # Apply a CNOT gate (controlled-X gate) with the specified control and
+        # target qubits
+        self.circuit.cx(control_qubit_index, target_qubit_index)
+
+    def apply_toffoli_gate(self, control_qubit_index1,
+                           control_qubit_index2,
+                           target_qubit_index):
+        # Apply a Toffoli gate (controlled-controlled-X gate) with the
+        # specified control and target qubits
+        self.circuit.ccx(control_qubit_index1,
+                         control_qubit_index2,
+                         target_qubit_index)
+
+    def apply_swap_gate(self, qubit_index1, qubit_index2):
+        # Apply a SWAP gate to exchange the states of two qubits
+        self.circuit.swap(qubit_index1, qubit_index2)
+
+    def apply_pauli_x_gate(self, qubit_index):
+        # Apply a Pauli X gate on the specified qubit
+        self.circuit.x(qubit_index)
+
+    def apply_pauli_y_gate(self, qubit_index):
+        # Apply a Pauli Y gate on the specified qubit
+        self.circuit.y(qubit_index)
+
+    def apply_pauli_z_gate(self, qubit_index):
+        # Apply a Pauli Z gate on the specified qubit
+        self.circuit.z(qubit_index)
+
+    def execute_circuit(self):
+        # Transpile and execute the quantum circuit using the chosen backend
+        transpiled_circuit = self.circuit.transpile(self.backend)
+        job = qiskit.execute(transpiled_circuit, self.backend,
+                       shots=self.backend_config['backend_options']['shots'])
+        result = job.result()
+        return result.get_counts(transpiled_circuit)


(mahout) 03/05: donate qumat

Posted by ra...@apache.org.
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 2e5f41eafaa6422782a0166a0083c458362fae79
Author: Trevor Grant <tr...@gmail.com>
AuthorDate: Tue Jan 16 14:17:18 2024 -0600

    donate qumat
---
 README.md     | 16 ++++++++++++++++
 docs/index.md |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 2e1c8a106..83d62cb8b 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+
 <!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
@@ -265,3 +266,18 @@ Please see the `NOTICE.txt` included in this directory for more information.
 <!--
 [![Coverage Status](https://coveralls.io/repos/github/apache/mahout/badge.svg?branch=master)](https://coveralls.io/github/apache/mahout?branch=master)
 -->
+
+![QuMat Logo](docs/assets/mascot.png)
+
+# QuMat
+
+QuMat is a POC of a high level Python library for intefacing with multiple
+quantum computing backends. It is designed to be easy to use and to abstract
+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
+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 b13f29fe9..e9655d6f5 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,4 +1,4 @@
-![QuMat Logo](images/mascot.png)
+![QuMat Logo](assets/mascot.png)
 
 # QuMat
 


(mahout) 05/05: Closes #1

Posted by ra...@apache.org.
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 82458204486f04d8d69e83745740ffc2fdf56c12
Author: trevor grant <tr...@aboriginal-armadillo.com>
AuthorDate: Thu Jan 18 15:08:34 2024 -0600

    Closes #1
---
 pyproject.toml                   | 17 +++++++++++++++++
 {src/qumat => qumat}/__init__.py |  0
 {src/qumat => qumat}/qumat.py    |  0
 3 files changed, 17 insertions(+)

diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 000000000..0f0750f43
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,17 @@
+[tool.poetry]
+name = "qumat"
+version = "0.0.1"
+description = "A library for composing quantum machine learning."
+authors = ["rawkintrevo"]
+license = "MIT"
+readme = "README.md"
+
+[tool.poetry.dependencies]
+python = "^3.7"
+qiskit = "^0.45.1"
+qiskit-aer = "^0.13.2"
+
+
+[build-system]
+requires = ["poetry-core"]
+build-backend = "poetry.core.masonry.api"
diff --git a/src/qumat/__init__.py b/qumat/__init__.py
similarity index 100%
rename from src/qumat/__init__.py
rename to qumat/__init__.py
diff --git a/src/qumat/qumat.py b/qumat/qumat.py
similarity index 100%
rename from src/qumat/qumat.py
rename to qumat/qumat.py


(mahout) 02/05: Add docs

Posted by ra...@apache.org.
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 d0206bb777ab0604829b81f3cc7ea9694e949792
Author: Trevor Grant <tr...@gmail.com>
AuthorDate: Tue Jan 16 14:12:04 2024 -0600

    Add docs
---
 docs/assets/mascot.png                      | Bin 0 -> 1004488 bytes
 docs/basic_gates.md                         |  27 +++++++++++++++++++++++++++
 docs/getting_started.md                     |   0
 docs/index.md                               |  13 +++++++++++++
 src/qumat/{quantum_computer.py => qumat.py} |   0
 5 files changed, 40 insertions(+)

diff --git a/docs/assets/mascot.png b/docs/assets/mascot.png
new file mode 100644
index 000000000..ce9ec81bb
Binary files /dev/null and b/docs/assets/mascot.png differ
diff --git a/docs/basic_gates.md b/docs/basic_gates.md
new file mode 100644
index 000000000..9faad7ad5
--- /dev/null
+++ b/docs/basic_gates.md
@@ -0,0 +1,27 @@
+# Quantum Gate Explanations
+
+## NOT Gate (X-Gate)
+The NOT gate, represented by the X-gate, is a fundamental quantum gate used to flip the state of a qubit. It is often referred to as a bit-flip gate. When applied to a qubit in the |0⟩ state, it changes it to the |1⟩ state, and vice versa. Mathematically, if |ψ⟩ represents the qubit's state, applying the X-gate results in X|ψ⟩ = |¬ψ⟩.
+
+## Hadamard Gate (H-Gate)
+The Hadamard gate, denoted as the H-gate, is used to create superposition states. When applied to a qubit in the |0⟩ state, it transforms it into an equal superposition of |0⟩ and |1⟩ states. Mathematically, H|0⟩ = (|0⟩ + |1⟩) / √2. It's a crucial gate in quantum algorithms like Grover's and quantum teleportation.
+
+## CNOT Gate (Controlled-X Gate)
+The CNOT gate, or controlled-X gate, is an entangling gate that acts on two qubits: a control qubit and a target qubit. If the control qubit is in the |1⟩ state, it applies the X-gate to the target qubit; otherwise, it does nothing. It creates entanglement between the two qubits and is essential in building quantum circuits for various applications.
+
+## Toffoli Gate (Controlled-Controlled-X Gate)
+The Toffoli gate is a three-qubit gate that acts as a controlled-controlled-X gate. It applies the X-gate to the target qubit only if both control qubits are in the |1⟩ state. It is used in quantum computing for implementing reversible classical logic operations.
+
+## SWAP Gate
+The SWAP gate exchanges the states of two qubits. When applied, it swaps the state of the first qubit with the state of the second qubit. This gate is fundamental in quantum algorithms and quantum error correction codes.
+
+## Pauli X Gate (X-Gate)
+The Pauli X gate is another name for the NOT gate, as mentioned earlier. It flips the state of a qubit, changing |0⟩ to |1⟩ and vice versa. It's named after Wolfgang Pauli, a pioneer in quantum physics.
+
+## Pauli Y Gate (Y-Gate)
+The Pauli Y gate is a quantum gate that introduces complex phase shifts along with a bit-flip operation. It can be thought of as a combination of bit-flip and phase-flip gates. Mathematically, it is represented as Y|0⟩ = i|1⟩ and Y|1⟩ = -i|0⟩. It's essential in quantum error correction and quantum algorithms.
+
+## Pauli Z Gate (Z-Gate)
+The Pauli Z gate is a gate that introduces a phase flip without changing the qubit's state. It leaves |0⟩ unchanged and transforms |1⟩ to -|1⟩. Mathematically, Z|0⟩ = |0⟩ and Z|1⟩ = -|1⟩. It's used for measuring the phase of a qubit.
+
+These quantum gates are fundamental building blocks in quantum computing, enabling the manipulation and transformation of qubit states to perform various quantum algorithms and computations.
diff --git a/docs/getting_started.md b/docs/getting_started.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/docs/index.md b/docs/index.md
new file mode 100644
index 000000000..b13f29fe9
--- /dev/null
+++ b/docs/index.md
@@ -0,0 +1,13 @@
+![QuMat Logo](images/mascot.png)
+
+# QuMat
+
+QuMat is a POC of a high level Python library for intefacing with multiple 
+quantum computing backends. It is designed to be easy to use and to abstract 
+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 
+basic gates which are basically all that exist right now (and even those 
+only exist for `qiskit`).
\ No newline at end of file
diff --git a/src/qumat/quantum_computer.py b/src/qumat/qumat.py
similarity index 100%
rename from src/qumat/quantum_computer.py
rename to src/qumat/qumat.py


(mahout) 04/05: add quantum teleportation

Posted by ra...@apache.org.
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)