Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 28, 2024
1 parent 89a8154 commit 843c0eb
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/qibotn/eval_qu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def dense_vector_tn_qu(qasm: str, initial_state, mps_opts, backend="numpy"):
return amplitudes



def expectation_qu(qasm: str, pauli_string_pattern, initial_state, mps_opts, backend="numpy"):
def expectation_qu(
qasm: str, pauli_string_pattern, initial_state, mps_opts, backend="numpy"
):

qasm_mod, nqubits = modify_qasm(qasm)
if initial_state is not None:
Expand All @@ -58,32 +59,34 @@ def expectation_qu(qasm: str, pauli_string_pattern, initial_state, mps_opts, bac
qasm, psi0=initial_state, gate_opts=mps_opts
)

obs = pauli_string_gen(nqubits-1, pauli_string_pattern)
obs = pauli_string_gen(nqubits - 1, pauli_string_pattern)

opt = ctg.ReusableHyperOptimizer(
# just do a few runs
# just do a few runs
max_repeats=32,
# only use the basic greedy optimizer ...
methods=['greedy'],
# ... but pair it with reconfiguration
# only use the basic greedy optimizer ...
methods=["greedy"],
# ... but pair it with reconfiguration
reconf_opts={},
# just uniformly sample the space
optlib='random',
# terminate search if contraction is cheap
max_time='rate:1e6',
# account for both flops and write - usually wise for practical performance
minimize='combo-64',
# persist paths found in here
directory='cotengra_cache_eco',
# just uniformly sample the space
optlib="random",
# terminate search if contraction is cheap
max_time="rate:1e6",
# account for both flops and write - usually wise for practical performance
minimize="combo-64",
# persist paths found in here
directory="cotengra_cache_eco",
)
expectation = circ_quimb.local_expectation(
obs, where=list(range(nqubits - 1)), optimize=opt, simplify_sequence="DRC"
)
expectation = circ_quimb.local_expectation(obs, where=list(range(nqubits-1)), optimize=opt,
simplify_sequence ="DRC")


return expectation


def modify_qasm(qasm_circ):
lines =qasm_circ.split("\n")
qasm_circ_mod =[]
lines = qasm_circ.split("\n")
qasm_circ_mod = []
while lines:
line = lines.pop(0).strip()
sta = re.compile(r"qreg\s+(\w+)\s*\[(\d+)\];")
Expand All @@ -94,7 +97,8 @@ def modify_qasm(qasm_circ):
else:
qasm_circ_mod.append(line)
qasm_circ_mod = "\n".join(qasm_circ_mod)
return qasm_circ_mod, int(nqubits)+1
return qasm_circ_mod, int(nqubits) + 1


def pauli_string_gen(nqubits, pauli_string_pattern):
"""Used internally to generate the string based on given pattern and number
Expand All @@ -117,11 +121,10 @@ def pauli_string_gen(nqubits, pauli_string_pattern):
for i in range(nqubits):
char_to_add = pauli_string_pattern[i % len(pauli_string_pattern)]
result += char_to_add


for i, c in enumerate(result):
if (i==0):
if i == 0:
obs = qu.pauli(c)
else:
obs = obs&qu.pauli(c)
obs = obs & qu.pauli(c)
return obs

0 comments on commit 843c0eb

Please sign in to comment.