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

Ignore terms with 0 coefficients #2370

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sacpis
Copy link
Collaborator

@sacpis sacpis commented Nov 8, 2024

Ignore terms with 0 coefficients

Test result

def hamiltonian_clique_graph(penalty, nodes, weights, non_edges) -> cudaq.SpinOperator:

    spin_ham = 0.0
    for wt, node in zip(weights, nodes):
        #print(wt,node)
        spin_ham += 0.5 * wt * spin.z(node)
        spin_ham -= 0.5 * wt * spin.i(node)

    for non_edge in non_edges:
        u, v = (non_edge[0], non_edge[1])
        spin_ham += penalty / 4.0 * (spin.z(u) * spin.z(v) - spin.z(u) -
                                     spin.z(v) + spin.i(u) * spin.i(v))

    return spin_ham

print(hamiltonian_clique_graph(2., [0,1], [1., 1.], [[0,1]]))
root@ae0fb315fdde:/workspaces/cuda-quantum# python3 docs/sphinx/examples/python/test1.py 
[0.5+0j] ZZ
[-0.5+0j] II

@sacpis sacpis force-pushed the ignore_zero_coefficient_terms branch from 4598261 to c20ab81 Compare November 8, 2024 19:39
@sacpis sacpis requested a review from amccaskey November 8, 2024 21:18
@sacpis sacpis removed the request for review from amccaskey November 12, 2024 17:13
@sacpis sacpis marked this pull request as ready for review November 12, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant