Skip to content

Commit

Permalink
Merge pull request #173 from BoxiLi/qutip5-gate
Browse files Browse the repository at this point in the history
Align the signature of gate functions and expand_operator with the ones in qutip-v5
  • Loading branch information
BoxiLi committed Jan 29, 2023
2 parents 204d538 + 3c11062 commit 5790ddc
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 379 deletions.
3 changes: 0 additions & 3 deletions doc/source/apidoc/qutip_qip.operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ qutip\_qip.operations
cz_gate
expand_operator
fredkin
gate_expand_1toN
gate_expand_2toN
gate_expand_3toN
gate_sequence_product
globalphase
hadamard_transform
Expand Down
19 changes: 14 additions & 5 deletions src/qutip_qip/algorithms/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


import numpy as np
from ..operations import Gate, snot, cphase, swap
from ..operations import Gate, snot, cphase, swap, expand_operator
from ..circuit import QubitCircuit
from qutip import Qobj
from ..decompose import decompose_one_qubit_gate
Expand Down Expand Up @@ -69,13 +69,22 @@ def qft_steps(N=1, swapping=True):
for i in range(N):
for j in range(i):
U_step_list.append(
cphase(np.pi / (2 ** (i - j)), N, control=i, target=j)
expand_operator(
cphase(np.pi / (2 ** (i - j))),
dims=[2] * N,
targets=[i, j],
)
)
U_step_list.append(snot(N, i))
U_step_list.append(
expand_operator(snot(), dims=[2] * N, targets=i)
)
if swapping:
for i in range(N // 2):
U_step_list.append(swap(N, [N - i - 1, i]))

U_step_list.append(
expand_operator(
swap(), dims=[2] * N, targets=[N - i - 1, i]
)
)
return U_step_list


Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qip/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ def propagators(self, expand=True, ignore_measurement=False):
if expand:
all_targets = gate.get_all_qubits()
qobj = expand_operator(
qobj, N=self.N, targets=all_targets, dims=self.dims
qobj, dims=self.dims, targets=all_targets
)
else:
if expand:
Expand Down
21 changes: 15 additions & 6 deletions src/qutip_qip/circuit/circuitsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ def _mult_sublists(tensor_list, overall_inds, U, inds):
ind_map = {ind: pos for ind, pos in zip(revised_inds, sorted_positions)}

U_sublist = expand_operator(
U_sublist, N, [ind_map[ind] for ind in inds_sublist]
U_sublist, dims=[2] * N, targets=[ind_map[ind] for ind in inds_sublist]
)
U = expand_operator(
U, dims=[2] * N, targets=[ind_map[ind] for ind in inds]
)
U = expand_operator(U, N, [ind_map[ind] for ind in inds])

U_sublist = U * U_sublist
inds_sublist = revised_inds
Expand All @@ -125,7 +127,9 @@ def _expand_overall(tensor_list, overall_inds):

U_overall = tensor(tensor_list)
overall_inds = _flatten(overall_inds)
U_overall = expand_operator(U_overall, len(overall_inds), overall_inds)
U_overall = expand_operator(
U_overall, dims=[2] * len(overall_inds), targets=overall_inds
)
overall_inds = sorted(overall_inds)
return U_overall, overall_inds

Expand Down Expand Up @@ -188,7 +192,9 @@ def _gate_sequence_product(U_list, ind_list):
tensor_list, overall_inds
)
U_left, rem_inds = _gate_sequence_product(U_list[i:], ind_list[i:])
U_left = expand_operator(U_left, num_qubits, rem_inds)
U_left = expand_operator(
U_left, dims=[2] * num_qubits, targets=rem_inds
)
return U_left * U_overall, [
sorted_inds[ind] for ind in overall_inds
]
Expand Down Expand Up @@ -292,6 +298,7 @@ def __init__(
"""

self.qc = qc
self.dims = qc.dims
self.mode = mode
self.precompute_unitary = precompute_unitary

Expand Down Expand Up @@ -468,7 +475,7 @@ def _compute_unitary(self, U_list, inds_list):

if len(overall_inds) != self.qc.N:
U_overall = expand_operator(
U_overall, N=self.qc.N, targets=overall_inds
U_overall, dims=self.qc.dims, targets=overall_inds
)
return U_overall

Expand Down Expand Up @@ -573,7 +580,9 @@ def _decimal_to_binary(decimal, length):
if apply_gate:
if self.precompute_unitary:
U = expand_operator(
U, self.qc.N, operation.get_all_qubits()
U,
dims=self.qc.dims,
targets=operation.get_all_qubits(),
)
self._evolve_state(U)
else:
Expand Down
1 change: 0 additions & 1 deletion src/qutip_qip/device/cavityqed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ..operations import Gate
from .processor import Processor, Model
from .modelprocessor import ModelProcessor, _to_array
from ..operations import expand_operator
from ..pulse import Pulse
from ..compiler import GateCompiler, CavityQEDCompiler

Expand Down
8 changes: 2 additions & 6 deletions src/qutip_qip/device/optpulseprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,12 @@ def load_circuit(
for label in control_labels:
qobj, targets = self.model.get_control(label)
full_ctrls_hams.append(
expand_operator(
qobj, len(self.dims), targets=targets, dims=self.dims
)
expand_operator(qobj, dims=self.dims, targets=targets)
)

full_drift_ham = sum(
[
expand_operator(
qobj, len(self.dims), targets=targets, dims=self.dims
)
expand_operator(qobj, dims=self.dims, targets=targets)
for (qobj, targets) in self.model.get_all_drift()
],
Qobj(
Expand Down
10 changes: 0 additions & 10 deletions src/qutip_qip/gates.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/qutip_qip/operations/gateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,8 @@ def get_qobj(self, num_qubits=None, dims=None):
num_qubits = max(all_targets) + 1
return expand_operator(
self.get_compact_qobj(),
N=num_qubits,
targets=all_targets,
dims=dims,
targets=all_targets,
)


Expand Down

0 comments on commit 5790ddc

Please sign in to comment.