Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p = 1
m = 1
for b in bits[:n1_bits]:
if b:
p += 2**m
m += 1
q = 1
m = 1
for b in bits[n1_bits:]:
if b:
q += 2**m
m += 1
return p, q
hamiltonian = (num - mk_expr(0, n1_bits) * mk_expr(n1_bits, n2_bits))**2
return vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, n_step), minimizer, sampler), bitseparator
def qaoa(self,shots=1,step=2,verbose=False):
from blueqat import vqe
return vqe.Vqe(vqe.QaoaAnsatz(pauli(self.qubo),step)).run()
:param n_sample: The number of sampling time of each measurement in VQE.
If None, use calculated ideal value.
:param edges: The edges list of the graph.
:returns Vqe object
"""
sampler = sampler or vqe.non_sampling_sampler
minimizer = minimizer or vqe.get_scipy_minimizer(
method="Powell",
options={"ftol": 5.0e-2, "xtol": 5.0e-2, "maxiter": 1000, "disp": True}
)
hamiltonian = pauli.I() * 0
for i, j in edges:
hamiltonian += pauli.Z(i) * pauli.Z(j)
return vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, n_step), minimizer, sampler)
:param n_sample: The number of sampling time of each measurement in VQE.
If None, use calculated ideal value.
:param edges: The edges list of the graph.
:returns Vqe object
"""
sampler = sampler or vqe.non_sampling_sampler
minimizer = minimizer or vqe.get_scipy_minimizer(
method="Powell",
options={"ftol": 5.0e-2, "xtol": 5.0e-2, "maxiter": 1000, "disp": True}
)
hamiltonian = pauli.I() * 0
for i, j in edges:
hamiltonian += pauli.Z(i) * pauli.Z(j)
return vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, n_step), minimizer, sampler)
def numpartition_qaoa(n_step, nums, minimizer=None, sampler=None):
"""Do the Number partition QAOA.
:param n_step: The number of step of QAOA
:param nums: The edges list of the graph.
:returns Vqe object
"""
hamiltonian = pauli.Expr.zero()
for i, x in enumerate(nums):
hamiltonian += pauli.Z[i] * x
hamiltonian = (hamiltonian ** 2).simplify()
return vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, n_step), minimizer, sampler)