cg-code 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cg_code/qc/qc_p1.py ADDED
@@ -0,0 +1,32 @@
1
+ # Install and configure a quantum computing framework such as IBM Qiskit or Google
2
+ # Cirq, and create basic quantum circuits using single-qubit gates to perform
3
+ # measurements.
4
+
5
+ from qiskit import QuantumCircuit
6
+ from qiskit.providers.basic_provider import BasicSimulator
7
+
8
+ # A Quantum circuit where 1 qubit and 1 classical bit
9
+ qc = QuantumCircuit(1,1)
10
+
11
+ # Apply Pauli-X on Qubit 0, which flip 0 to 1 qubit
12
+ qc.x(0)
13
+
14
+ # Applying Hadamard (H) gate on Qubit 0, which convert into superposition
15
+ qc.h(0)
16
+
17
+ # Measure qubit 0 and store result in classical bit 0
18
+ qc.measure(0,0)
19
+
20
+ print("Quantum Circuit: ")
21
+ print(qc.draw("text"))
22
+
23
+
24
+ # Load local simulator for run circuit
25
+ simulator = BasicSimulator()
26
+
27
+ # Circuit runs 1000 shots run, so that we see probability distribution
28
+ job = simulator.run(qc,shots=1000)
29
+
30
+ result = job.result()
31
+ counts = result.get_counts()
32
+ print("Measurement Results (1000 shots): ",counts)
cg_code/qc/qc_p10.py ADDED
@@ -0,0 +1,40 @@
1
+ import time
2
+
3
+ # PLATFORM 1: IBM QISKIT
4
+ from qiskit import QuantumCircuit
5
+ from qiskit.providers.basic_provider import BasicSimulator
6
+
7
+ start_qiskit = time.time()
8
+ qc_qiskit = QuantumCircuit(2,2)
9
+ qc_qiskit.h(0)
10
+ qc_qiskit.cx(0,1)
11
+ qc_qiskit.measure([0,1],[0,1])
12
+
13
+ sim_qiskit = BasicSimulator()
14
+ res_qiskit = sim_qiskit.run(qc_qiskit,shots=1000).result().get_counts()
15
+ time_qiskit = time.time() - start_qiskit
16
+
17
+ print("IBM QISKIT:")
18
+ print(f"Result: {res_qiskit}")
19
+ print(f"Execution Time: {time_qiskit} seconds")
20
+
21
+
22
+ # PLATFORM 2: GOOGLE CIRC
23
+ import cirq
24
+
25
+ start_cirq = time.time()
26
+
27
+ q0,q1 = cirq.LineQubit.range(2)
28
+ qc_cirq = cirq.Circuit(
29
+ cirq.H(q0),
30
+ cirq.CNOT(q0,q1),
31
+ cirq.measure(q0,q1,key="result")
32
+ )
33
+
34
+ sim_cirq = cirq.Simulator()
35
+ res_cirq = sim_cirq.run(qc_cirq,repetitions=1000).histogram(key="result")
36
+ time_criq = time.time() - start_cirq
37
+
38
+ print("GOOGLE CIRQ:")
39
+ print(f"Result (0='00', 3='11'): {res_cirq}")
40
+ print(f"Execution Time: {time_criq} seconds")
cg_code/qc/qc_p2.py ADDED
@@ -0,0 +1,25 @@
1
+ # Write a program to visualise qubit states and their rotations on the Bloch Sphere using
2
+ # suitable simulation tools.
3
+
4
+ from qiskit import QuantumCircuit
5
+ from qiskit.quantum_info import Statevector
6
+ from qiskit.visualization import plot_bloch_multivector
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
+
10
+ # 1 Qubit circuit, no measurement use because after measurement state has been collapse
11
+ qc = QuantumCircuit(1)
12
+
13
+ # Rotate pi/2 (90 degree) at x-axis
14
+ qc.rx(np.pi/2,0)
15
+
16
+ # Rotate pi/4 (45 degree) ast y-axis
17
+ qc.ry(np.pi/4,0)
18
+
19
+ # Find exact mathematical statevector of circuit
20
+ state = Statevector.from_instruction(qc)
21
+
22
+ # Statevector plot on Bloch Sphere
23
+ plot_bloch_multivector(state)
24
+ plt.title("Qubit State on Bloch Sphere")
25
+ plt.show()
cg_code/qc/qc_p3.py ADDED
@@ -0,0 +1,25 @@
1
+ # Implement a program to demonstrate the concepts of superposition and entanglement
2
+ # using multi-qubit circuits.
3
+
4
+ from qiskit import QuantumCircuit
5
+ from qiskit.providers.basic_provider import BasicSimulator
6
+
7
+ # 2 qubits and 2 classical bits circuit system
8
+ qc = QuantumCircuit(2,2)
9
+
10
+ # Hadamard gate applying on Qubit 0 --> convert into superposition
11
+ qc.h(0)
12
+
13
+ # CNOT gate applying, where 0 qubit is control and 1 qubit is target
14
+ qc.cx(0,1)
15
+
16
+ # Measure both qubits
17
+ qc.measure([0,1],[0,1])
18
+
19
+ # Draw circuit
20
+ print(qc.draw("text"))
21
+
22
+ simulator = BasicSimulator()
23
+ counts = simulator.run(qc,shots=1000).result().get_counts()
24
+
25
+ print(f"Entangled State Results: {counts}")
cg_code/qc/qc_p4.py ADDED
@@ -0,0 +1,42 @@
1
+ # Write a program to simulate the process of quantum teleportation using an entangled
2
+ # qubit pair.
3
+
4
+ from qiskit import QuantumCircuit
5
+ from qiskit.providers.basic_provider import BasicSimulator
6
+
7
+ qc = QuantumCircuit(3,3)
8
+
9
+ # Qubit 0 applying X Gate
10
+ qc.x(0)
11
+ qc.barrier() # Visual line for clear Circuit
12
+
13
+ # Qubit 1 use for entanglement
14
+ qc.h(1)
15
+ qc.cx(1,2)
16
+ qc.barrier()
17
+
18
+ # Bell measurement operation apply on Qubits 0 and 1
19
+ qc.cx(0,1)
20
+ qc.h(0)
21
+ qc.barrier()
22
+
23
+ # Measure qubits and store in classical bits 0 and 1
24
+ qc.measure([0,1],[0,1])
25
+ qc.barrier()
26
+
27
+ # # Qubits 2 correction basis on classical bits
28
+ # with qc.if_test((1,1)): # if classical bit 1 value is 1 then apply X gate
29
+ # qc.x(2)
30
+
31
+ # with qc.if_test((0,1)): # if classical bit 0 value is 1 then apply Z gate
32
+ # qc.z(2)
33
+
34
+ qc.cx(1,2)
35
+ qc.cz(0,2)
36
+
37
+ # Verify mesaure qubit 2
38
+ qc.measure([0,1,2],[0,1,2])
39
+
40
+ simulator = BasicSimulator()
41
+ counts = simulator.run(qc,shots=1000).result().get_counts()
42
+ print(f"Teleportation Results (c2 c1 c0): {counts}")
cg_code/qc/qc_p5.py ADDED
@@ -0,0 +1,37 @@
1
+ # Implement the Deutsch–Jozsa algorithm to identify whether a given function is constant
2
+ # or balanced.
3
+
4
+ from qiskit import QuantumCircuit
5
+ from qiskit.providers.basic_provider import BasicSimulator
6
+
7
+ # 2 Input qubits and 1 output qubit + 2 classical bits
8
+ qc = QuantumCircuit(3,2)
9
+
10
+ # Set output qubit in |1> state
11
+ qc.x(2)
12
+
13
+ # Hadamard gate applying in three gates
14
+ qc.h([0,1,2])
15
+ qc.barrier()
16
+
17
+ # Oracle function: Build oracle of "Balanced" fucntion
18
+ qc.cx(0,2)
19
+ qc.cx(1,2)
20
+ qc.barrier()
21
+
22
+ # Hadamard gate applying in Input qubits (q0,q1)
23
+ qc.h([0,1])
24
+
25
+ # Measure input qubits
26
+ qc.measure([0,1],[0,1])
27
+
28
+ simulator = BasicSimulator()
29
+ counts = simulator.run(qc,shots=1000).result().get_counts()
30
+ print(f"Measurement Output: {counts}")
31
+
32
+ # Result if 00 means Constant, otherwise balanced
33
+ if '00' in counts and len(counts) == 1:
34
+ print("Conclusion: The function is CONSTANT")
35
+ else:
36
+ print("Conclusion: The function is BALANCED")
37
+
cg_code/qc/qc_p6.py ADDED
@@ -0,0 +1,32 @@
1
+ # Write a program to implement Grover’s search algorithm for an unstructured search
2
+ # problem and analyze its efficiency.
3
+
4
+ from qiskit import QuantumCircuit
5
+ from qiskit.providers.basic_provider import BasicSimulator
6
+
7
+ qc = QuantumCircuit(2,2)
8
+
9
+ # Superposition: All states equal probability
10
+ qc.h([0,1])
11
+ qc.barrier()
12
+
13
+ # Oracle: Mark '11' to target state
14
+ # Controlled-Z (cz) gate when flip the state, both qubits are 1
15
+ qc.cz(0,1)
16
+ qc.barrier()
17
+
18
+ # Markeed state probabilty increase
19
+ qc.h([0,1])
20
+ qc.z([0,1])
21
+ qc.cz(0,1)
22
+ qc.h([0,1])
23
+ qc.barrier()
24
+
25
+
26
+ # Measure qubits
27
+ qc.measure([0,1],[0,1])
28
+
29
+ print(qc.draw("text"))
30
+ simulator = BasicSimulator()
31
+ counts = simulator.run(qc,shots=1000).result().get_counts()
32
+ print(f"Grover's Search Result (Target '11'): {counts}")
cg_code/qc/qc_p7.py ADDED
@@ -0,0 +1,35 @@
1
+ import numpy as np
2
+ from qiskit import QuantumCircuit
3
+ from qiskit.providers.basic_provider import BasicSimulator
4
+
5
+ # 3 Qubits circuit
6
+ n = 3
7
+ qc = QuantumCircuit(n,n)
8
+
9
+ # input states
10
+ qc.x(0)
11
+ qc.x(2)
12
+ qc.barrier()
13
+
14
+ # QFT Logic: Hadamard and Controlled-Phase rotations apply each qubit
15
+ for j in range(n-1,-1,-1):
16
+ qc.h(j)
17
+ for k in range(j-1,-1,-1):
18
+ # Angle pi/2^(j-k)
19
+ angle = np.pi/(2**(j-k))
20
+ qc.cp(angle,k,j)
21
+ qc.barrier()
22
+
23
+ for i in range(n//2):
24
+ qc.swap(i,n-1-i)
25
+ qc.barrier()
26
+
27
+ # Measurement qubits
28
+ qc.measure(range(n),range(n))
29
+
30
+ print("Qubits QFT Circuit: ")
31
+ print(qc.draw("text"))
32
+
33
+ simulator = BasicSimulator()
34
+ counts = simulator.run(qc,shots=1000).result().get_counts()
35
+ print(f"QFT Measurement Counts: {counts}")
cg_code/qc/qc_p8.py ADDED
@@ -0,0 +1,42 @@
1
+ import numpy as np
2
+ from qiskit import QuantumCircuit
3
+ from qiskit.providers.basic_provider import BasicSimulator
4
+ from scipy.optimize import minimize
5
+
6
+ def create_qaoa_circuit(params):
7
+ gamma,beta = params[0],params[1]
8
+
9
+ qc = QuantumCircuit(2,2)
10
+
11
+ # Initial Superposition
12
+ qc.h([0,1])
13
+
14
+ # Cost Hamiltonian
15
+ qc.cx(0,1)
16
+ qc.rz(2*gamma,1)
17
+ qc.cx(0,1)
18
+
19
+ # Mizer Hamiltonian (X rotations)
20
+ qc.rx(2*beta,0)
21
+ qc.rx(2*beta,1)
22
+
23
+ qc.measure([0,1],[0,1])
24
+ return qc
25
+
26
+ simulator = BasicSimulator()
27
+
28
+ def cost_function(params):
29
+ qc = create_qaoa_circuit(params)
30
+ counts = simulator.run(qc,shots=500).result().get_counts()
31
+
32
+ # '01' yaa '10' comes then -1 score
33
+ cut_value = counts.get('01',0) + counts.get('10',0)
34
+ return -cut_value/500.0
35
+
36
+ result = minimize(cost_function,[0.5,0.5],method="COBYLA")
37
+ best_params = result.x
38
+
39
+ final_qc = create_qaoa_circuit(best_params)
40
+ final_counts = simulator.run(final_qc,shots=1000).result().get_counts()
41
+ print(f"Optimal Parameters (gamma, beta): {best_params}")
42
+ print(f"QAOA Max-Cut Results ('01' and '10' are optimal cuts): {final_counts}")
cg_code/qc/qc_p9.py ADDED
@@ -0,0 +1,24 @@
1
+ from qiskit import QuantumCircuit
2
+ from qiskit.providers.basic_provider import BasicSimulator
3
+ import matplotlib.pyplot as plt
4
+
5
+ num_qubits = 4
6
+ qc = QuantumCircuit(num_qubits,num_qubits)
7
+
8
+ qc.h(range(num_qubits))
9
+
10
+ qc.measure(range(num_qubits),range(num_qubits))
11
+
12
+ simulator = BasicSimulator()
13
+ binary_samples = simulator.run(qc,shots=1000,memory=True).result().get_memory()
14
+
15
+ random_numbers = [int(b,2) for b in binary_samples]
16
+
17
+ print(f"First 15 Quantum Random Numbers (0 to 15): {random_numbers}")
18
+
19
+ plt.hist(random_numbers,bins=range(17),align="left",rwidth=0.8,color="teal")
20
+ plt.title("Quantum Random Number Distribution (1000 samples)")
21
+ plt.xlabel("Random Number")
22
+ plt.ylabel("Frequency")
23
+ plt.xticks(range(16))
24
+ plt.show()
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: cg-code
3
+ Version: 0.1.0
4
+ Summary: Unique work Python library
5
+ Author-email: Deepu Mondal <deepu143w@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
@@ -0,0 +1,44 @@
1
+ cg_code/__init__.py,sha256=RfXbTZyOgsW9hgm6OkFUrJmHQ_mDIaS1Gia5_jse30o,76
2
+ cg_code/hci/__init__.py,sha256=d4AWT-90lG2jQnAuU8bgogR4uOK3NNq5tXX8vNYnbnQ,231
3
+ cg_code/hci/hci_p1.py,sha256=nE8cViI9pYVpQhL18QAtq2IfIGiFSxtdMGtMS_RsIog,630
4
+ cg_code/hci/hci_p10.py,sha256=zaK6gsK8F4i_cTPV034McAyFmH88TBmlket9R4Wr-ws,675
5
+ cg_code/hci/hci_p2.py,sha256=6_VHRjF8KHWOyg9Eob6AJCXTjkk3BO9QjteAoKO_JjA,674
6
+ cg_code/hci/hci_p3.py,sha256=8ui231vypiVgHVaW091m3IVU6J0LHijp8c2aPMqnNuk,538
7
+ cg_code/hci/hci_p4.py,sha256=WKageU8v6ieSHx_iLcG4rEGLqBeKHyOVdrnKrT74CCQ,610
8
+ cg_code/hci/hci_p5.py,sha256=R0LgAkLCVE0ixaklDou3IcF6BqoZBuyA_lf101lHkGQ,626
9
+ cg_code/hci/hci_p6.py,sha256=1Tzx_r6lCl7rWhL7pjEBjvQOFxVw-CaclzpN_mazWSg,702
10
+ cg_code/hci/hci_p7.py,sha256=SGMnw0gPilegAoG8WUJgJFzdg_wzwakxl3-zjFeKAnE,480
11
+ cg_code/hci/hci_p8.py,sha256=UfeIjhJV-xVj2K-O0zU-p1sTD9tJbC7UIY5M_3qY69E,712
12
+ cg_code/hci/hci_p9.py,sha256=6-Ypgz-f42jigtQroBS4e2eAmPX36dLfos_2n_ZkUFc,901
13
+ cg_code/nlp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ cg_code/om/__init__.py,sha256=2FsXnrIx59rJVjs7rIU62DAj8aKZNQr8km1Y1iQ7E-I,342
15
+ cg_code/om/om_all.py,sha256=HtFFXuDQU97DCAbCGkQy6Sdns3FoyM0A9RX2vWrZYN4,33689
16
+ cg_code/om/om_p1_1.py,sha256=heic5pavbqDJJNLeYsjTcwCtewbG_jSctopM12wdMPw,2514
17
+ cg_code/om/om_p1_2.py,sha256=Eo5MWDdxnSO5NzC0izTrzYThRf0A3f4CkPl-xwUtowk,1305
18
+ cg_code/om/om_p1_3.py,sha256=ZGjUUng-HX6wNxW_jRH7GS2z2o-qJ1dRLiIAnT6bLYY,1629
19
+ cg_code/om/om_p1_4.py,sha256=TCWyfzAAf5iEklcPLVenO75FV3MLS2uhi0XH5YhkfQU,1198
20
+ cg_code/om/om_p2_1.py,sha256=BFh7AB6iXWcaDQwEsKHPGnfVne--Qfyzk-zd33juCww,1837
21
+ cg_code/om/om_p3_1.py,sha256=_fG-1Xs016MoKBS-ptZwLND_bViJOIvQrnA4qZj9_Vc,2497
22
+ cg_code/om/om_p3_4.py,sha256=Q6oe_i6upySbOXMh3M6NpwvigCAS6aP9-sSyakJWD48,2041
23
+ cg_code/om/om_p4_1.py,sha256=gxLmddP_onVMjMKwMCqDT1Wf3M5d4xo491scF2JeWKs,3847
24
+ cg_code/om/om_p_2_2.py,sha256=Qdc2EZks_4shICt4KgrGH8o1UdGAXhC6UyhwnGkz04E,998
25
+ cg_code/om/om_p_2_3.py,sha256=BlhonTBYjBHIlr9j8ORPeuzo2L4oPVu-OwE8S8k5Sco,1045
26
+ cg_code/om/om_p_3_2.py,sha256=MIU1qB8ayErMr6yeO76Oo2Zo-6rqXJPLmCDj-Np7fGU,808
27
+ cg_code/om/om_p_3_3.py,sha256=epAwodtNIU_1LDxFnySGOWYJsQWDIkgkrBdt9IxFUxA,979
28
+ cg_code/om/om_p_4_2.py,sha256=mtXq2IXqF7_qupyhMu7QPBrBmugrBFheVMOIYzkunLM,1684
29
+ cg_code/qc/__init__.py,sha256=5N3q3LlkwRTDr4kqwyG1UV_ylKkol_xSjuMKYBT09is,221
30
+ cg_code/qc/qc_p1.py,sha256=x2HIyZbvBtQRNQvJ5tyd6P3bDM7z-tZahzZD_BFv5M4,930
31
+ cg_code/qc/qc_p10.py,sha256=_dqj5EuYqxod1OStieNoAL0GUNLkJFTO_PjpPSUCvew,995
32
+ cg_code/qc/qc_p2.py,sha256=45_fxw8_ciVFlStM9oXgiEs3WidMPeCwv0IIKnuJjbk,760
33
+ cg_code/qc/qc_p3.py,sha256=qbGXQCwa9bFy5G6oG3ztqhodHmaFD6gDkbY0vqybESc,684
34
+ cg_code/qc/qc_p4.py,sha256=tu0prVVsQAa2JPwOEvB2SBYc4Nll7hID1lqGuR-N1lA,1035
35
+ cg_code/qc/qc_p5.py,sha256=InpwMhiCAsT4YUYDeXi89roFo0RSaKtsuvwKGaf-GjY,959
36
+ cg_code/qc/qc_p6.py,sha256=vDVUU9K1O2_Dsknqg93J1V1dAeLTc3qQzVe_doyx0Yo,785
37
+ cg_code/qc/qc_p7.py,sha256=REUpACJ0RhCr68UONEq_ntZS94kWlNAjyWY2KquD-sE,776
38
+ cg_code/qc/qc_p8.py,sha256=LNHsX0tQJBGpmdeJqGXK4VWXz-ixNc6kgTuQPg0zRm8,1178
39
+ cg_code/qc/qc_p9.py,sha256=pmXus6175uzkTDQZCih2-wU9RPeCWzCXukTtrzkiebg,740
40
+ cg_code-0.1.0.dist-info/licenses/LICENSE,sha256=Vh_SqZLCriQN9MisauMJpotzTWni_AliIcfOT0xDst0,1079
41
+ cg_code-0.1.0.dist-info/METADATA,sha256=E1VQKpzK9jSLdgpoRZIwB2Q4zFi5xjz0afvFl0ZF_gM,401
42
+ cg_code-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
43
+ cg_code-0.1.0.dist-info/top_level.txt,sha256=xX5oO3Atv_vOy-H0BQE-oshlrZWW50icr8AtVl_UD20,8
44
+ cg_code-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,15 @@
1
+ Copyright © 2026 shiv2310
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ documentation files (the “Software”), to deal in the Software without restriction, including without limitation
5
+ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
6
+ and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of
9
+ the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
12
+ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
14
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
15
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ cg_code