Qcover


NameQcover JSON
Version 2.6.0 PyPI version JSON
download
home_pagehttps://github.com/BAQIS-Quantum/Qcover
SummaryQuantum computing solver
upload_time2023-11-21 05:45:37
maintainer
docs_urlNone
authorntyz&finleyzhuang
requires_python>=3.8
licenseApache-2.0 License
keywords qaoa based combinational optimization solver qubo quantum
VCS
bugtrack_url
requirements cirq cirq-aqt cirq-core cirq-google cirq-ionq cirq-pasqal cirq-rigetti cirq-web networkx projectq pyquafu qiskit qiskit-aer qiskit-ibmq-provider qiskit-terra quimb qulacs opt_einsum autoray
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <img src=./resources/Qcover_label_readme.png>
</div>
Qcover is an open source effort to help exploring combinatorial optimization problems in Noisy Intermediate-scale Quantum(NISQ) processor. It is developed by the quantum operating system team in Beijing Academy of Quantum Information Sciences (BAQIS). Qcover supports fast output of optimal parameters in shallow QAOA circuits. It can be used as a powerful tool to assist NISQ processor to demonstrate application-level quantum advantages. 

# Getting started
Use the following command to complete the installation of Qcover
```git
pip install Qcover
```
or

```git
git clone https://github.com/BAQIS-Quantum/Qcover
pip install -r requirements.yml
python setup.py install
```
More example codes and tutorials can be found in the tests folder here on GitHub.

# Examples
1. Using algorithm core module to generate the ising random weighted graph and calculate it's Hamiltonian expectation
    ```python
    from Qcover.core import Qcover
    from Qcover.backends import CircuitByQulacs
    from Qcover.optimizers import COBYLA
    from Qcover.utils import generate_graph_data, generate_weighted_graph
    import networkx as nx
    
    node_num, edge_num = 6, 9
    p = 1
    nodes, edges = generate_graph_data(node_num, edge_num)
    g = generate_weighted_graph(nodes, edges)
   
    # If you want to customize the Ising weight graph model, you can use the following code
    # g = nx.Graph()
    # nodes = [(0, 3), (1, 2), (2, 1), (3, 1)]
    # edges = [(0, 1, 1), (0, 2, 1), (3, 1, 2), (2, 3, 3)]
    # for nd in nodes:
    #    u, w = nd[0], nd[1]
    #    g.add_node(int(u), weight=int(w))
    # for ed in edges:
    #     u, v, w = ed[0], ed[1], ed[2]
    #     g.add_edge(int(u), int(v), weight=int(w))

    qulacs_bc = CircuitByQulacs()
    optc = COBYLA(options={'tol': 1e-3, 'disp': True})
    qc = Qcover(g, p=p, optimizer=optc, backend=qulacs_bc)
    res = qc.run()
    print("the result of problem is:\n", res)
    qc.backend.optimization_visualization()
    ```
2. Solving specific binary combinatorial optimization problems, Calculating the expectation value of the Hamiltonian of the circuit which corresponding to the problem.
for example, if you want to using Qcover to solve a max-cut problem, just coding below:
    ```python
    from Qcover.core import Qcover
    from Qcover.backends import CircuitByQiskit
    from Qcover.optimizers import COBYLA
    from Qcover.applications.max_cut import MaxCut
   
    node_num, degree = 6, 3
    p = 1
    mxt = MaxCut(node_num=node_num, node_degree=degree)
    ising_g, shift = mxt.run()
    qiskit_bc = CircuitByQiskit(expectation_calc_method="statevector")
    optc = COBYLA(options={'tol': 1e-3, 'disp': True})
    qc = Qcover(ising_g, p=p, optimizer=optc, backend=qiskit_bc)
    res = qc.run()
    print("the result of problem is:\n", res)
    counts = qc.backend.get_result_counts(res['Optimal parameter value'])
    qc.backend.sampling_visualization(counts)
    ```
   
3. If you want to solve combinatorial optimization problems with real quantum computers on
 quafu quantum computing cloud platform, you can refer to the following example code
    ```python
    from Qcover.core import Qcover
    from Qcover.backends import CircuitByQulacs
    from Qcover.optimizers import COBYLA
    from Qcover.compiler import CompilerForQAOA
    import networkx as nx
    import matplotlib.pyplot as plt
    
    # Qcover supports real quantum computers to solve combinatorial optimization problems.
    # You only need to transform the combinatorial optimization problem into a weight graph,
    # and you can use the quafu quantum computing cloud platform  (http://quafu.baqis.ac.cn/)
    # to solve the corresponding problem. The following is an example of a max-cut problem.
    
    # The weight graph corresponding to the combinatorial optimization problem and transformed it to networkx format.
    nodes = [(0, 1), (1, 3), (2, 2), (3, 1), (4, 0), (5, 3)]
    edges = [(0, 1, -1), (1, 2, -4), (2, 3, 2), (3, 4, -2), (4, 5, -1), (1, 3, 0), (2, 4, 3)]
    graph = nx.Graph()
    for nd in nodes:
        u, w = nd[0], nd[1]
        graph.add_node(int(u), weight=int(w))
    for ed in edges:
        u, v, w = ed[0], ed[1], ed[2]
        graph.add_edge(int(u), int(v), weight=int(w))
    
    # draw weighted graph to be calculated
    new_labels = dict(map(lambda x: ((x[0], x[1]), str(x[2]['weight'])), graph.edges(data=True)))
    pos = nx.spring_layout(graph)
    # pos = nx.circular_layout(g)
    nx.draw_networkx(graph, pos=pos, node_size=400, font_size=13, node_color='y')
    # nx.draw_networkx_edge_labels(g, pos=pos, edge_labels=new_labels, font_size=15)
    nx.draw_networkx_edges(graph, pos, width=2, edge_color='g', arrows=False)
    plt.show()
    
    # Using Qcover to calculate the optimal parameters of QAOA circuit.
    p = 1
    bc = CircuitByQulacs()
    optc = COBYLA(options={'tol': 1e-3, 'disp': True})
    qc = Qcover(graph, p=p, optimizer=optc, backend=bc)
    res = qc.run()
    optimal_params = res['Optimal parameter value']
    
    # Compile and send the QAOA circuit to the quafu cloud.
    # Token parameter should be set according to your own account
    # For more introduction see https://github.com/ScQ-Cloud/pyquafu
    token = "E-SowFQdKJ427YhZDGdxoNmOk2SB02xpgODiz_4WtAS.9dDOwUTNxgjN2EjOiAHelJCLzITM6ICZpJye.9JiN1IzUIJiOicGbhJCLiQ1VKJiOiAXe0Jye"
    cloud_backend = 'ScQ-P20'
    qcover_compiler = CompilerForQAOA(graph, p=p, optimal_params=optimal_params, apitoken=token, cloud_backend=cloud_backend)
    task_id = qcover_compiler.send(wait=True, shots=5000, task_name='MaxCut')
    # If you choose wait=Ture, you have to wait for the result to return.
    # If you choose wait=False, you can execute the following command to query the result status at any time,
    # and the result will be returned when the task is completed.
    quafu_solver = qcover_compiler.task_status_query(task_id)
    if quafu_solver:
        counts_energy = qcover_compiler.results_processing(quafu_solver)
        qcover_compiler.visualization(counts_energy, problem='MaxCut', solutions=3)
    ```

The results obtained by running this example code are shown in the following two figures

<div align="center">
  <img src=./tests/test_compiler_graph.png width="300"/><img src=./tests/test_compiler_res.png width="300"/>
</div>

# How to contribute
For information on how to contribute, please send an e-mail to members of developer of this project.

# Please cite
When using Qcover for research projects, please cite

- Wei-Feng Zhuang, Ya-Nan Pu, Hong-Ze Xu, Xudan Chai, Yanwu Gu, Yunheng Ma, Shahid Qamar, 
Chen Qian, Peng Qian, Xiao Xiao, Meng-Jun Hu, and Done E. Liu, "Efficient Classical
Computation of Quantum Mean Value for Shallow QAOA Circuits", arXiv:2112.11151 (2021).


- BAQIS Quafu Group, "Quafu-Qcover: Explore Combinatorial Optimization Problems on Cloud-based Quantum Computers", arXiv:2305.17979 (2023).


# Authors
The first release of Qcover was developed by the quantum operating system team in Beijing Academy of Quantum Information Sciences.

Qcover is constantly growing and many other people have already contributed to it in the meantime.

# License
Qcover is released under the Apache 2 license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/BAQIS-Quantum/Qcover",
    "name": "Qcover",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "QAOA based combinational optimization solver QUBO quantum",
    "author": "ntyz&finleyzhuang",
    "author_email": "puyn@baqis.ac.cn",
    "download_url": "https://files.pythonhosted.org/packages/25/7e/76da3f459f8b93b68ee3b00dab1a08a39588687a63ed6e672ac375d2a0f5/Qcover-2.6.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <img src=./resources/Qcover_label_readme.png>\n</div>\nQcover is an open source effort to help exploring combinatorial optimization problems in Noisy Intermediate-scale Quantum(NISQ) processor. It is developed by the quantum operating system team in Beijing Academy of Quantum Information Sciences (BAQIS). Qcover supports fast output of optimal parameters in shallow QAOA circuits. It can be used as a powerful tool to assist NISQ processor to demonstrate application-level quantum advantages. \n\n# Getting started\nUse the following command to complete the installation of Qcover\n```git\npip install Qcover\n```\nor\n\n```git\ngit clone https://github.com/BAQIS-Quantum/Qcover\npip install -r requirements.yml\npython setup.py install\n```\nMore example codes and tutorials can be found in the tests folder here on GitHub.\n\n# Examples\n1. Using algorithm core module to generate the ising random weighted graph and calculate it's Hamiltonian expectation\n    ```python\n    from Qcover.core import Qcover\n    from Qcover.backends import CircuitByQulacs\n    from Qcover.optimizers import COBYLA\n    from Qcover.utils import generate_graph_data, generate_weighted_graph\n    import networkx as nx\n    \n    node_num, edge_num = 6, 9\n    p = 1\n    nodes, edges = generate_graph_data(node_num, edge_num)\n    g = generate_weighted_graph(nodes, edges)\n   \n    # If you want to customize the Ising weight graph model, you can use the following code\n    # g = nx.Graph()\n    # nodes = [(0, 3), (1, 2), (2, 1), (3, 1)]\n    # edges = [(0, 1, 1), (0, 2, 1), (3, 1, 2), (2, 3, 3)]\n    # for nd in nodes:\n    #    u, w = nd[0], nd[1]\n    #    g.add_node(int(u), weight=int(w))\n    # for ed in edges:\n    #     u, v, w = ed[0], ed[1], ed[2]\n    #     g.add_edge(int(u), int(v), weight=int(w))\n\n    qulacs_bc = CircuitByQulacs()\n    optc = COBYLA(options={'tol': 1e-3, 'disp': True})\n    qc = Qcover(g, p=p, optimizer=optc, backend=qulacs_bc)\n    res = qc.run()\n    print(\"the result of problem is:\\n\", res)\n    qc.backend.optimization_visualization()\n    ```\n2. Solving specific binary combinatorial optimization problems, Calculating the expectation value of the Hamiltonian of the circuit which corresponding to the problem.\nfor example, if you want to using Qcover to solve a max-cut problem, just coding below:\n    ```python\n    from Qcover.core import Qcover\n    from Qcover.backends import CircuitByQiskit\n    from Qcover.optimizers import COBYLA\n    from Qcover.applications.max_cut import MaxCut\n   \n    node_num, degree = 6, 3\n    p = 1\n    mxt = MaxCut(node_num=node_num, node_degree=degree)\n    ising_g, shift = mxt.run()\n    qiskit_bc = CircuitByQiskit(expectation_calc_method=\"statevector\")\n    optc = COBYLA(options={'tol': 1e-3, 'disp': True})\n    qc = Qcover(ising_g, p=p, optimizer=optc, backend=qiskit_bc)\n    res = qc.run()\n    print(\"the result of problem is:\\n\", res)\n    counts = qc.backend.get_result_counts(res['Optimal parameter value'])\n    qc.backend.sampling_visualization(counts)\n    ```\n   \n3. If you want to solve combinatorial optimization problems with real quantum computers on\n quafu quantum computing cloud platform, you can refer to the following example code\n    ```python\n    from Qcover.core import Qcover\n    from Qcover.backends import CircuitByQulacs\n    from Qcover.optimizers import COBYLA\n    from Qcover.compiler import CompilerForQAOA\n    import networkx as nx\n    import matplotlib.pyplot as plt\n    \n    # Qcover supports real quantum computers to solve combinatorial optimization problems.\n    # You only need to transform the combinatorial optimization problem into a weight graph,\n    # and you can use the quafu quantum computing cloud platform  (http://quafu.baqis.ac.cn/)\n    # to solve the corresponding problem. The following is an example of a max-cut problem.\n    \n    # The weight graph corresponding to the combinatorial optimization problem and transformed it to networkx format.\n    nodes = [(0, 1), (1, 3), (2, 2), (3, 1), (4, 0), (5, 3)]\n    edges = [(0, 1, -1), (1, 2, -4), (2, 3, 2), (3, 4, -2), (4, 5, -1), (1, 3, 0), (2, 4, 3)]\n    graph = nx.Graph()\n    for nd in nodes:\n        u, w = nd[0], nd[1]\n        graph.add_node(int(u), weight=int(w))\n    for ed in edges:\n        u, v, w = ed[0], ed[1], ed[2]\n        graph.add_edge(int(u), int(v), weight=int(w))\n    \n    # draw weighted graph to be calculated\n    new_labels = dict(map(lambda x: ((x[0], x[1]), str(x[2]['weight'])), graph.edges(data=True)))\n    pos = nx.spring_layout(graph)\n    # pos = nx.circular_layout(g)\n    nx.draw_networkx(graph, pos=pos, node_size=400, font_size=13, node_color='y')\n    # nx.draw_networkx_edge_labels(g, pos=pos, edge_labels=new_labels, font_size=15)\n    nx.draw_networkx_edges(graph, pos, width=2, edge_color='g', arrows=False)\n    plt.show()\n    \n    # Using Qcover to calculate the optimal parameters of QAOA circuit.\n    p = 1\n    bc = CircuitByQulacs()\n    optc = COBYLA(options={'tol': 1e-3, 'disp': True})\n    qc = Qcover(graph, p=p, optimizer=optc, backend=bc)\n    res = qc.run()\n    optimal_params = res['Optimal parameter value']\n    \n    # Compile and send the QAOA circuit to the quafu cloud.\n    # Token parameter should be set according to your own account\n    # For more introduction see https://github.com/ScQ-Cloud/pyquafu\n    token = \"E-SowFQdKJ427YhZDGdxoNmOk2SB02xpgODiz_4WtAS.9dDOwUTNxgjN2EjOiAHelJCLzITM6ICZpJye.9JiN1IzUIJiOicGbhJCLiQ1VKJiOiAXe0Jye\"\n    cloud_backend = 'ScQ-P20'\n    qcover_compiler = CompilerForQAOA(graph, p=p, optimal_params=optimal_params, apitoken=token, cloud_backend=cloud_backend)\n    task_id = qcover_compiler.send(wait=True, shots=5000, task_name='MaxCut')\n    # If you choose wait=Ture, you have to wait for the result to return.\n    # If you choose wait=False, you can execute the following command to query the result status at any time,\n    # and the result will be returned when the task is completed.\n    quafu_solver = qcover_compiler.task_status_query(task_id)\n    if quafu_solver:\n        counts_energy = qcover_compiler.results_processing(quafu_solver)\n        qcover_compiler.visualization(counts_energy, problem='MaxCut', solutions=3)\n    ```\n\nThe results obtained by running this example code are shown in the following two figures\n\n<div align=\"center\">\n  <img src=./tests/test_compiler_graph.png width=\"300\"/><img src=./tests/test_compiler_res.png width=\"300\"/>\n</div>\n\n# How to contribute\nFor information on how to contribute, please send an e-mail to members of developer of this project.\n\n# Please cite\nWhen using Qcover for research projects, please cite\n\n- Wei-Feng Zhuang, Ya-Nan Pu, Hong-Ze Xu, Xudan Chai, Yanwu Gu, Yunheng Ma, Shahid Qamar, \nChen Qian, Peng Qian, Xiao Xiao, Meng-Jun Hu, and Done E. Liu, \"Efficient Classical\nComputation of Quantum Mean Value for Shallow QAOA Circuits\", arXiv:2112.11151 (2021).\n\n\n- BAQIS Quafu Group, \"Quafu-Qcover: Explore Combinatorial Optimization Problems on Cloud-based Quantum Computers\", arXiv:2305.17979 (2023).\n\n\n# Authors\nThe first release of Qcover was developed by the quantum operating system team in Beijing Academy of Quantum Information Sciences.\n\nQcover is constantly growing and many other people have already contributed to it in the meantime.\n\n# License\nQcover is released under the Apache 2 license.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0 License",
    "summary": "Quantum computing solver",
    "version": "2.6.0",
    "project_urls": {
        "Bug Reports": "https://github.com/BAQIS-Quantum/Qcover/issues",
        "Homepage": "https://github.com/BAQIS-Quantum/Qcover",
        "Source": "https://github.com/BAQIS-Quantum/Qcover"
    },
    "split_keywords": [
        "qaoa",
        "based",
        "combinational",
        "optimization",
        "solver",
        "qubo",
        "quantum"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7e5a370423f99788a224296d0aafbdef5bb86db87cab43e69c3a73238e3b310",
                "md5": "b0e2611512f619a79762056d9e8e877c",
                "sha256": "101d46dae30a24ee662e4c7bb932323e6e9c0a5caa25e268334b1634b3ea3614"
            },
            "downloads": -1,
            "filename": "Qcover-2.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b0e2611512f619a79762056d9e8e877c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 92783,
            "upload_time": "2023-11-21T05:45:35",
            "upload_time_iso_8601": "2023-11-21T05:45:35.252257Z",
            "url": "https://files.pythonhosted.org/packages/e7/e5/a370423f99788a224296d0aafbdef5bb86db87cab43e69c3a73238e3b310/Qcover-2.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "257e76da3f459f8b93b68ee3b00dab1a08a39588687a63ed6e672ac375d2a0f5",
                "md5": "62119452bd6ad30f0ccb44518107c440",
                "sha256": "6bb2c19001fef95c4d4739abd8ae14988648bb7b604a7d77750f640bc8daa87a"
            },
            "downloads": -1,
            "filename": "Qcover-2.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "62119452bd6ad30f0ccb44518107c440",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 56510,
            "upload_time": "2023-11-21T05:45:37",
            "upload_time_iso_8601": "2023-11-21T05:45:37.763200Z",
            "url": "https://files.pythonhosted.org/packages/25/7e/76da3f459f8b93b68ee3b00dab1a08a39588687a63ed6e672ac375d2a0f5/Qcover-2.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-21 05:45:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BAQIS-Quantum",
    "github_project": "Qcover",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "cirq",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-aqt",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-core",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-google",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-ionq",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-pasqal",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-rigetti",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "cirq-web",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "networkx",
            "specs": [
                [
                    "==",
                    "2.8.8"
                ]
            ]
        },
        {
            "name": "projectq",
            "specs": [
                [
                    "==",
                    "0.8.0"
                ]
            ]
        },
        {
            "name": "pyquafu",
            "specs": [
                [
                    "==",
                    "0.3.6"
                ]
            ]
        },
        {
            "name": "qiskit",
            "specs": [
                [
                    "==",
                    "0.42.1"
                ]
            ]
        },
        {
            "name": "qiskit-aer",
            "specs": [
                [
                    "==",
                    "0.12.0"
                ]
            ]
        },
        {
            "name": "qiskit-ibmq-provider",
            "specs": [
                [
                    "==",
                    "0.20.2"
                ]
            ]
        },
        {
            "name": "qiskit-terra",
            "specs": [
                [
                    "==",
                    "0.23.3"
                ]
            ]
        },
        {
            "name": "quimb",
            "specs": [
                [
                    "==",
                    "1.4.2"
                ]
            ]
        },
        {
            "name": "qulacs",
            "specs": [
                [
                    "==",
                    "0.6.0"
                ]
            ]
        },
        {
            "name": "opt_einsum",
            "specs": [
                [
                    "==",
                    "3.3.0"
                ]
            ]
        },
        {
            "name": "autoray",
            "specs": [
                [
                    "==",
                    "0.6.3"
                ]
            ]
        }
    ],
    "lcname": "qcover"
}
        
Elapsed time: 0.14360s