diff --git a/README.md b/README.md index 32b82ca..9345ba7 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Apply various quantum gates to the qubits: ```python simulator.h(0) # Hadamard gate -simulator.x(1) # Pauli-X gate -simulator.cx(0, 1) # Controlled-Not gate +simulator.t(1) # π/8 gate +simulator.cx(0, 2) # Controlled-Not gate ``` ### Custom Gates @@ -40,7 +40,7 @@ Define and apply custom gates using angles: import numpy as np theta, phi, lambda_ = np.pi/4, np.pi/3, np.pi/2 -simulator.u(0, theta, phi, lambda_) # Generic gate +simulator.u(1, theta, phi, lambda_) # Generic gate ``` ### Measurements @@ -51,7 +51,7 @@ Measure the state of the qubits: results = simulator.run(shots=100) ``` -> {'100': 24, '110': 30, '000': 29, '010': 17} +> {'010': 24, '101': 28, '111': 25, '000': 23} ### Circuit Representation @@ -63,15 +63,19 @@ print(simulator) ```plaintext ----------------- -| H | | C | U | -| | X | X | | -| | | | | +| H | | C | | +| | T | | U | +| | | X | | ----------------- ``` ## Testing -Tests are included in the package to verify its functionality. +Tests are included in the package to verify its functionality: + +```shell +python3 -m pytest tests/ +``` ## License diff --git a/requirements.txt b/requirements.txt index 1cc18fc..0dc7293 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -numpy -pytest +numpy>=1.16.0 +pytest>=2.1.0 diff --git a/setup.py b/setup.py index 26c03bc..b257985 100644 --- a/setup.py +++ b/setup.py @@ -2,16 +2,16 @@ setup( name="qubit_simulator", - version="0.0.1", + version="0.0.2", description="A simple qubit simulator", long_description=open("README.md").read(), long_description_content_type="text/markdown", author="Spencer Churchill", author_email="churchill@ionq.com", packages=find_packages(), - install_requires=["numpy"], + install_requires=["numpy>=1.10.1"], classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", diff --git a/tests/test_gates.py b/tests/test_gates.py new file mode 100644 index 0000000..ce97d4f --- /dev/null +++ b/tests/test_gates.py @@ -0,0 +1,9 @@ +import numpy as np +from qubit_simulator import Gates + + +def test_create_controlled_gate(): + # Test for a controlled-X gate + controlled_X = Gates.create_controlled_gate(Gates.X, 0, 1, 2) + expected_result = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]) + assert np.allclose(controlled_X, expected_result) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 8013c3d..ac7b016 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -154,18 +154,21 @@ def test_gate_reversibility(): def test_measure_probabilities(): - shots = 10000 + shots = 1000 simulator = QubitSimulator(1) simulator.h(0) results = simulator.run(shots=shots) assert abs(results.get("0", 0) - results.get("1", 0)) < shots / 4 -def test_str(): +def test_circuit_string(): simulator = QubitSimulator(3) simulator.h(0) - simulator.cx(0, 2) - expected_string = "---------\n| H | C |\n| | |\n| | X |\n---------" + simulator.x(1) + simulator.cx(2, 1) + expected_string = ( + "-------------\n| H | | |\n| | X | X |\n| | | C |\n-------------" + ) assert str(simulator) == expected_string