Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prep_rot_qutip(n, a):
q = qutip.basis(2)
nNorm = np.linalg.norm(n)
R = (-1j * a / (2 * nNorm) * (n[0] * qutip.sigmax() + n[1] * qutip.sigmay() + n[2] * qutip.sigmaz())).expm()
return R * q
def test_gate_objectives_pe():
"""Test gate objectives for a PE optimization"""
from qutip import ket, tensor, sigmaz, sigmax, identity
from weylchamber import bell_basis
basis = [ket(n) for n in [(0, 0), (0, 1), (1, 0), (1, 1)]]
H = [
tensor(sigmaz(), identity(2)) + tensor(identity(2), sigmaz()),
[tensor(sigmax(), identity(2)), lambda t, args: 1.0],
[tensor(identity(2), sigmax()), lambda t, args: 1.0],
]
objectives = krotov.gate_objectives(basis, 'PE', H)
assert len(objectives) == 4
bell_basis_states = bell_basis(basis)
for state in bell_basis_states:
assert isinstance(state, qutip.Qobj)
for i in range(4):
expected_objective = krotov.Objective(
initial_state=bell_basis_states[i], target='PE', H=H
)
assert objectives[i] == expected_objective
assert krotov.gate_objectives(basis, 'perfect_entangler', H) == objectives
assert krotov.gate_objectives(basis, 'perfect entangler', H) == objectives
assert krotov.gate_objectives(basis, 'Perfect Entangler', H) == objectives
def test_gate_objectives_single_qubit_gate():
"""Test initialization of objectives for simple single-qubit gate"""
basis = [ket([0]), ket([1])]
gate = sigmay() # = -i|0⟩⟨1| + i|1⟩⟨0|
H = [sigmaz(), [sigmax(), lambda t, args: 1.0]]
objectives = krotov.objectives.gate_objectives(basis, gate, H)
assert objectives == [
krotov.Objective(initial_state=basis[0], target=(1j * basis[1]), H=H),
krotov.Objective(initial_state=basis[1], target=(-1j * basis[0]), H=H),
]
def objective_liouville():
a1 = np.random.random(100) + 1j * np.random.random(100)
a2 = np.random.random(100) + 1j * np.random.random(100)
H = [
tensor(sigmaz(), identity(2)) + tensor(identity(2), sigmaz()),
[tensor(sigmax(), identity(2)), a1],
[tensor(identity(2), sigmax()), a2],
]
L = krotov.objectives.liouvillian(H, c_ops=[])
ket00 = ket((0, 0))
ket11 = ket((1, 1))
obj = krotov.Objective(
initial_state=qutip.ket2dm(ket00), target=qutip.ket2dm(ket11), H=L
)
return obj
def prep_H_qutip():
q = qutip.basis(2)
H = 1 / np.sqrt(2) * (qutip.sigmax() + qutip.sigmaz())
return qutip.ket2dm(H * q)
def z(self) -> None:
self.parent._apply(qt.sigmaz(), [self.qubit_id])
# end::pauli_rotations[]
-------
spin_operators: list or :class: qutip.Qobj
A list of `qutip.Qobj` operators - [sx, sy, sz] or the
requested operator.
"""
# 1. Define N TLS spin-1/2 matrices in the uncoupled basis
N = int(N)
sx = [0 for i in range(N)]
sy = [0 for i in range(N)]
sz = [0 for i in range(N)]
sp = [0 for i in range(N)]
sm = [0 for i in range(N)]
sx[0] = 0.5 * sigmax()
sy[0] = 0.5 * sigmay()
sz[0] = 0.5 * sigmaz()
sp[0] = sigmap()
sm[0] = sigmam()
# 2. Place operators in total Hilbert space
for k in range(N - 1):
sx[0] = tensor(sx[0], identity(2))
sy[0] = tensor(sy[0], identity(2))
sz[0] = tensor(sz[0], identity(2))
sp[0] = tensor(sp[0], identity(2))
sm[0] = tensor(sm[0], identity(2))
# 3. Cyclic sequence to create all N operators
a = [i for i in range(N)]
b = [[a[i - i2] for i in range(N)] for i2 in range(N)]
# 4. Create N operators