From 852f2e1e83a935f385f0a9fde3425418d4610b5e Mon Sep 17 00:00:00 2001 From: 123freezebrennan Date: Sun, 15 Sep 2024 20:44:53 -0700 Subject: [PATCH] First wave of examples that pretty much go over basic API usage --- examples/controlledphasegate.py | 13 ------------ examples/create_quantum_circuit.py | 3 +++ examples/createcircuit.py | 7 ------ examples/entangledqubits.py | 13 ------------ examples/hadamard.py | 9 -------- examples/hadamardstate.py | 11 ---------- examples/qsphere.py | 12 ----------- examples/quantumentanglement.py | 11 ---------- examples/reversecnot.py | 19 ----------------- examples/show_quantum_circuit_drawing.py | 8 +++++++ examples/statevector.py | 26 ----------------------- examples/swapgate.py | 11 ---------- examples/toffoli.py | 13 ------------ examples/use_custon_quantum_gates.py | 10 +++++++++ examples/use_quantum_gates.py | 6 ++++++ examples/use_quantum_tools.py | 8 +++++++ examples/use_visualize_quantum_circuit.py | 7 ++++++ 17 files changed, 42 insertions(+), 145 deletions(-) delete mode 100644 examples/controlledphasegate.py create mode 100644 examples/create_quantum_circuit.py delete mode 100644 examples/createcircuit.py delete mode 100644 examples/entangledqubits.py delete mode 100644 examples/hadamard.py delete mode 100644 examples/hadamardstate.py delete mode 100644 examples/qsphere.py delete mode 100644 examples/quantumentanglement.py delete mode 100644 examples/reversecnot.py create mode 100644 examples/show_quantum_circuit_drawing.py delete mode 100644 examples/statevector.py delete mode 100644 examples/swapgate.py delete mode 100644 examples/toffoli.py create mode 100644 examples/use_custon_quantum_gates.py create mode 100644 examples/use_quantum_gates.py create mode 100644 examples/use_quantum_tools.py create mode 100644 examples/use_visualize_quantum_circuit.py diff --git a/examples/controlledphasegate.py b/examples/controlledphasegate.py deleted file mode 100644 index 85eda963..00000000 --- a/examples/controlledphasegate.py +++ /dev/null @@ -1,13 +0,0 @@ -from qcpy import quantumcircuit, u - -# Create Quantum Circuit class object of 3 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, little_endian=True) - -# Create variable to store matrix representation of the U gate. -u = u() -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call to the customControlPhase, which will use qubit 0 as a control and qubit 1 as a target -# the matrix in the U gate is then used to designate what will be enacted on the qubits. -qc.customcontrolled(0, 1, u) -print(qc.state()) diff --git a/examples/create_quantum_circuit.py b/examples/create_quantum_circuit.py new file mode 100644 index 00000000..675c47b7 --- /dev/null +++ b/examples/create_quantum_circuit.py @@ -0,0 +1,3 @@ +from qcpy import quantumciruit + +qc = quantumciruit(qubits=4, big_endian=True, prep="z") diff --git a/examples/createcircuit.py b/examples/createcircuit.py deleted file mode 100644 index c7bec7f3..00000000 --- a/examples/createcircuit.py +++ /dev/null @@ -1,7 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, little_endian=True) - -# Print the state of quantum circuit. -print(qc.state) diff --git a/examples/entangledqubits.py b/examples/entangledqubits.py deleted file mode 100644 index e3d9a73c..00000000 --- a/examples/entangledqubits.py +++ /dev/null @@ -1,13 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, prep="z", little_endian=True) - -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call the CNOT gate and have the control be qubit 0 and the target be qubit 1. -qc.cnot(0, 1) -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Print the state of the quantum circuit. -print(qc.state) diff --git a/examples/hadamard.py b/examples/hadamard.py deleted file mode 100644 index 294d0678..00000000 --- a/examples/hadamard.py +++ /dev/null @@ -1,9 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, little_endian=True) - -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Print the state of the quantum circuit. -print(qc.state) diff --git a/examples/hadamardstate.py b/examples/hadamardstate.py deleted file mode 100644 index 1a192b8e..00000000 --- a/examples/hadamardstate.py +++ /dev/null @@ -1,11 +0,0 @@ -from qcpy import quantumcircuit - -number_of_qubits = 3 -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=number_of_qubits, little_endian=True, prep="z") - -# Enact the hadamard gate on each and every qubit in the quantum circuit. -for i in range(number_of_qubits): - qc.h(i) -# Print the probabilites of the quantum circuit. -print(qc.probabilities()) diff --git a/examples/qsphere.py b/examples/qsphere.py deleted file mode 100644 index 852d70d4..00000000 --- a/examples/qsphere.py +++ /dev/null @@ -1,12 +0,0 @@ -from qcpy import qsphere, quantumcircuit - -# creates a circuitfor 3 qubits -qc = quantumcircuit(3) -# call the hadamard gate on all 3 qubits -qc.h(0) -qc.h(1) -qc.h(2) -# call the QSphere class on the circuit -sphere_test = qsphere(qc) -# call the makeSphere method, this will show the sphere in a new window -sphere_test.make(save=False, show=True) diff --git a/examples/quantumentanglement.py b/examples/quantumentanglement.py deleted file mode 100644 index 02ad456b..00000000 --- a/examples/quantumentanglement.py +++ /dev/null @@ -1,11 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, prep="z", little_endian=True) - -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call the CNOT gate and have the control be qubit 0 and the target be qubit 1. -qc.cnot(0, 1) -# Print the state of the quantum circuit. -print(qc.state) diff --git a/examples/reversecnot.py b/examples/reversecnot.py deleted file mode 100644 index 2b3cbad8..00000000 --- a/examples/reversecnot.py +++ /dev/null @@ -1,19 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, prep="z", little_endian=True) - -# Call the hadamard gate and have it be placed on qubit 1. -qc.h(1) -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call the hadamard gate and have it be placed on qubit 1. -qc.h(1) -# Call the CNOT gate and have the control be qubit 0 and the target be qubit 1. -qc.cnot(0, 1) -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call the hadamard gate and have it be placed on qubit 1. -qc.h(1) -# Print the state of the quantum circuit. -print(qc.state) diff --git a/examples/show_quantum_circuit_drawing.py b/examples/show_quantum_circuit_drawing.py new file mode 100644 index 00000000..7d77489b --- /dev/null +++ b/examples/show_quantum_circuit_drawing.py @@ -0,0 +1,8 @@ +from qcpy import quantumcircuit + + +qc = quantumcircuit(qubits=5, big_endian=True) + +qc.h([i for i in range(5)]) +qc.cnot(0, 4) +print(qc) diff --git a/examples/statevector.py b/examples/statevector.py deleted file mode 100644 index dff40534..00000000 --- a/examples/statevector.py +++ /dev/null @@ -1,26 +0,0 @@ -import numpy as np - -from qcpy import quantumcircuit -from qcpy.visualizer import statevector - -circuit = quantumcircuit(5, little_endian=True) -circuit.h(0) -circuit.h(1) -circuit.h(2) -circuit.h(3) -circuit.h(4) - -circuit.cnot(0, 1) -circuit.toffoli(0, 1, 2) -circuit.t(1) -circuit.t(2) -circuit.h(1) -circuit.h(2) -circuit.z(3) -circuit.toffoli(0, 2, 1) -circuit.sdg(2) -circuit.u(2, np.pi / 2) -circuit.rz(4) - -test = statevector(circuit) -test.make(save=False, show=True, darkmode=True) diff --git a/examples/swapgate.py b/examples/swapgate.py deleted file mode 100644 index 8723e114..00000000 --- a/examples/swapgate.py +++ /dev/null @@ -1,11 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 2 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=2, little_endian=True, prep="z") - -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call the swap gate to switch the values of qubit 0 and qubit 1. -qc.swap(0, 1) -# Print the state of the quantum circuit. -print(qc.state) diff --git a/examples/toffoli.py b/examples/toffoli.py deleted file mode 100644 index 8fc3e958..00000000 --- a/examples/toffoli.py +++ /dev/null @@ -1,13 +0,0 @@ -from qcpy import quantumcircuit - -# Create Quantum Circuit class object of 3 qubits and represent the placement of values in little_endian format. -qc = quantumcircuit(qubits=3, little_endian=True) - -# Call the hadamard gate and have it be placed on qubit 0. -qc.h(0) -# Call the hadamard gate and have it be placed on qubit 1. -qc.h(1) -# Call to the Toffoli gate where the qubits 0 and 1 are control qubits, and qubit 2 is the target. -qc.toffoli(0, 1, 2) -# Print the state of quantum circuit. -print(qc.state) diff --git a/examples/use_custon_quantum_gates.py b/examples/use_custon_quantum_gates.py new file mode 100644 index 00000000..0f19343f --- /dev/null +++ b/examples/use_custon_quantum_gates.py @@ -0,0 +1,10 @@ +from qcpy import quantumcircuit +import numpy as numpy + + +pauli_x = np.array([[0 + 0j, 1 + 0j], [1 + 0j, 0 + 0j]], "F") + +qc = quantumcircuit(qubits=4, big_endian=True, prep="y") + +qc.custom(3, pauli_x) +print(qc) diff --git a/examples/use_quantum_gates.py b/examples/use_quantum_gates.py new file mode 100644 index 00000000..e4c78138 --- /dev/null +++ b/examples/use_quantum_gates.py @@ -0,0 +1,6 @@ +from qcpy import quantumcircuit, gates + +qc = quantumcircuit(qubits=4, big_endian=False) + +qc.custom(gates.paulix(), 0) +print(qc) diff --git a/examples/use_quantum_tools.py b/examples/use_quantum_tools.py new file mode 100644 index 00000000..51b21e42 --- /dev/null +++ b/examples/use_quantum_tools.py @@ -0,0 +1,8 @@ +from qcpy import quantumcircuit, amplitude + +qc = quantumcircuit(qubits=4, big_endian=False) + +qc.h(3) +qc.x(0) +qc.x(3) +print(ampltiude(qc)) diff --git a/examples/use_visualize_quantum_circuit.py b/examples/use_visualize_quantum_circuit.py new file mode 100644 index 00000000..b1fbbbf1 --- /dev/null +++ b/examples/use_visualize_quantum_circuit.py @@ -0,0 +1,7 @@ +from qcpy import quantumcircuit, visualize + +qc = quantumcircuit(qubits=4) + +qc.h([i for i in range(4)]) + +visualize.qsphere(qc)