Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] null.qubit failures for 30Q Hamiltonian obs #6735

Open
1 task done
multiphaseCFD opened this issue Dec 19, 2024 · 1 comment
Open
1 task done

[BUG] null.qubit failures for 30Q Hamiltonian obs #6735

multiphaseCFD opened this issue Dec 19, 2024 · 1 comment
Labels
bug 🐛 Something isn't working

Comments

@multiphaseCFD
Copy link
Member

Expected behavior

Ideally, a null.qubit device should be able to estimate resource requirements for a large-scale circuit (30Q+) measured with a Hamiltonian obs target at any wires.

Actual behavior

The following error message was thrown out when running a 29 qubit QAOA application with null.qubit:
numpy._core._exceptions._ArrayMemoryError: Unable to allocate 256. PiB for an array with shape (134217728, 134217728) and data type complex128

Additional information

No response

Source code

import pennylane as qml
from pennylane import numpy as np

from typing import List, Optional, Tuple
import networkx as nx

def clustered_chain_graph(
    n: int, r: int, k: int, q1: float, q2: float, seed: Optional[int] = None
) -> Tuple[nx.Graph, List[List[int]], List[List[int]]]:
    """
    Function to build clustered chain graph

    Args:
        n (int): number of nodes in each cluster
        r (int): number of clusters
        k (int): number of vertex separators between each cluster pair
        q1 (float): probability of an edge connecting any two nodes in a cluster
        q2 (float): probability of an edge connecting a vertex separator to any node in a cluster
        seed (Optional[int]=None): seed for fixing edge generation

    Returns:
        nx.Graph: clustered chain graph
    """

    if r <= 0 or not isinstance(r, int):
        raise ValueError("Number of clusters must be an integer greater than 0")

    clusters = []
    for i in range(r):
        _seed = seed * i if seed is not None else None
        cluster = nx.erdos_renyi_graph(n, q1, seed=_seed)
        nx.set_node_attributes(cluster, f"cluster_{i}", "subgraph")
        clusters.append(cluster)

    separators = []
    for i in range(r - 1):
        separator = nx.empty_graph(k)
        nx.set_node_attributes(separator, f"separator_{i}", "subgraph")
        separators.append(separator)

    G = nx.disjoint_union_all(clusters + separators)

    cluster_nodes = [
        [n[0] for n in G.nodes(data="subgraph") if n[1] == f"cluster_{i}"] for i in range(r)
    ]
    separator_nodes = [
        [n[0] for n in G.nodes(data="subgraph") if n[1] == f"separator_{i}"] for i in range(r - 1)
    ]

    rng = np.random.default_rng(seed)

    for i, separator in enumerate(separator_nodes):
        for s in separator:
            for c in cluster_nodes[i] + cluster_nodes[i + 1]:
                if rng.random() < q2:
                    G.add_edge(s, c)

    return G, cluster_nodes, separator_nodes


def get_clustered_chain_graph():
    r = 2  # number of clusters
    n = 13  # nodes in clusters
    k = 1  # vertex separators

    q1 = 0.7
    q2 = 0.3

    seed = 1967

    G, _, _ = clustered_chain_graph(n, r, k, q1, q2, seed=seed)
    return G


def workload_QAOA_layers_scaling():
    G = get_clustered_chain_graph()

    wires = len(G)
    dev = qml.device("null.qubit", wires=wires)

    cost, _ = qml.qaoa.maxcut(G)

    @qml.qnode(dev)
    def circuit():
        qml.Hadamard(wires=0)
        return qml.expval(cost)
    
    with qml.Tracker(dev) as tracker1:
        circuit()
    print(tracker1.history["resources"][0])


workload_QAOA_layers_scaling()

Tracebacks

No response

System information

>>> qml.about()
Name: PennyLane
Version: 0.40.0.dev38
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Users/shuli.shu/Documents/Code/GitHub/venv-py311/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing_extensions
Required-by: PennyLane_Lightning

Platform info:           macOS-15.2-arm64-arm-64bit
Python version:          3.11.1
Numpy version:           2.0.2
Scipy version:           1.14.1
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.40.0.dev14)
- default.clifford (PennyLane-0.40.0.dev38)
- default.gaussian (PennyLane-0.40.0.dev38)
- default.mixed (PennyLane-0.40.0.dev38)
- default.qubit (PennyLane-0.40.0.dev38)
- default.qutrit (PennyLane-0.40.0.dev38)
- default.qutrit.mixed (PennyLane-0.40.0.dev38)
- default.tensor (PennyLane-0.40.0.dev38)
- null.qubit (PennyLane-0.40.0.dev38)
- reference.qubit (PennyLane-0.40.0.dev38)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@multiphaseCFD multiphaseCFD added the bug 🐛 Something isn't working label Dec 19, 2024
@albi3ro
Copy link
Contributor

albi3ro commented Dec 27, 2024

Note that this problem also occurs with default.qubit. I can execute the circuit, but I cannot track the execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants