-
Notifications
You must be signed in to change notification settings - Fork 69
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
Setting memory_limit in contract_path causes "ValueError: invalid subscript 'Ų' in einstein sum subscripts string, subscripts must be letters" #217
Comments
I didn't specify any path finding algorithm, so it must be the default option. def run_with_oe(circuit, pauli_string):
myconverter = CircuitToEinsum(circuit, backend=cupy)
expression, operands = myconverter.expectation(pauli_string, lightcone=True)
memory_limit = "max_input"
# memory_limit = None
path, path_info = oe.contract_path(expression, *operands, memory_limit=memory_limit)
output = oe.contract(expression, *operands, optimize=path, memory_limit=memory_limit)
return output Where |
I think probably the contraction is not small thus the OOM initial problem (contractions in general are exponentially time and space expensive). When you turn on the memory_limit, the algorithm simply stops doing pairwise contractions at a certain point and tries doing a single einsum (i.e. explicit summation), resulting in a likely huge equation with too many subscripts (and also exponentially slower than the pairwise contraction itself). Printing the Likely you will need: |
Thank you for the reply.
Your statement is indeed echoed in the error message. I misinterpreted it as a configuration problem, whereas it is meant to say that it is not a viable option to do a single einsum. I think the error message is not explicit enough.
I have found cuTensorNet to generally find better contraction paths than opt_einsum, but takes longer to do so. I resorted to opt_einsum because I wasn't able to
This doesn't ring any bell to me, except for the step-dependent slicing in https://arxiv.org/abs/2012.02430. Your advice on how to do this is appreciated! |
Coincidentally, the circuit I have been trying to run is the QAOA circuit in that https://arxiv.org/abs/2012.02430 paper. |
I develop the library Here's an example, simulating https://arxiv.org/abs/2012.02430 relatively easily without slicing: # setup graph
import networkx as nx
reg = 3
n = 210
seed = 666
G = nx.random_regular_graph(reg, n, seed=seed)
terms = {(i, j): 1 for i, j in G.edges}
# setup circuit and TN
import quimb as qu
import quimb.tensor as qtn
p = 1
gammas = qu.randn(p)
betas = qu.randn(p)
circ_ex = qtn.circ_qaoa(terms, p, gammas, betas)
tn = circ_ex.amplitude_tn()
# find contraction tree
import cotengra as ctg
opt = ctg.HyperOptimizer(
minimize='combo',
# # just subtree reconf:
reconf_opts={},
# # if you did need dynamic slicing:
# slicing_reconf_opts=dict(target_size=2**30),
progbar=True,
)
tree = tn.contraction_tree(opt, output_inds=())
# log2[SIZE]: 27.00 log10[FLOPs]: 10.46: 100%|████| 128/128 [00:22<00:00, 5.66it/s]
# perform the contraction
tree.contract(tn.arrays, progbar=True)
# 100%|███████████████████████████████████████████| 314/314 [00:03<00:00, 91.08it/s]
# array(-1.76825283e-44-9.7394392e-46j) I do think that paper makes a mistake in claiming they can sample QAOA using frugal rejection though, one needs something like "gate by gate sampling": https://arxiv.org/abs/2112.08499 to sample with only amplitude access to a non chaotic quantum circuit. |
I got I assume that # The pauli_string being passed is a 1-qubit string `{qubits[10]: "Z"}`
def run_with_ctg(circuit, pauli_string):
myconverter = CircuitToEinsum(circuit, backend=cupy)
expression, operands = myconverter.expectation(pauli_string, lightcone=True)
opt = ctg.HyperOptimizer(
# minimize="combo",
reconf_opts={},
# # if you did need dynamic slicing:
# 1 GiB
slicing_reconf_opts=dict(target_size=1 * 1024**3),
progbar=True,
)
tic = time.time()
path, path_info = oe.contract_path(expression, *operands, optimize=opt)
output = oe.contract(expression, *operands, optimize=path)
elapsed = time.time() - tic
print("Elapsed oe", round(elapsed, 3))
return output it took ages to finish the computation. The main differentiator seems to be that QAOA Digression aside, I think this issue is a duplicate of #95 (i.e. the automatic memory slicing and automatic contraction feature)? #95 is solved if #125 is resolved. At this point, it is a matter of packaging |
Yes possibly
It would be great to include a lot of this stuff in |
I have a
contract_path
andcontract
sequence on a tensor that would OOM whenmemory_limit
isNone
. I tried to reduce the memory consumption of the computation (I don't mind if the computation runs slow, as long as it gives me answer), but upon limiting it, I encountered the errorDuring the
contract
step. Is there any extra step that I have to do? I have gone through the documentation and issues, and can't find any relevant information about this.The text was updated successfully, but these errors were encountered: