Skip to content
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

Add kwargs passing to _gen_quimb_gates #4

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 37 additions & 31 deletions src/qiskit_quimb/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,87 +49,93 @@ def quimb_gates(circuit: QuantumCircuit) -> list[quimb.tensor.Gate]:
return gates


def _gen_quimb_gates(op: Instruction, qubits: list[int]) -> Iterator[quimb.tensor.Gate]:
def _gen_quimb_gates(
op: Instruction, qubits: list[int], **kwargs
) -> Iterator[quimb.tensor.Gate]:
"""Convert a Qiskit gate to quimb gates."""
match op.name:
case "barrier":
pass
case "ccx":
yield quimb.tensor.Gate("CCX", params=[], qubits=qubits)
yield quimb.tensor.Gate("CCX", params=[], qubits=qubits, **kwargs)
case "ccz":
yield quimb.tensor.Gate("CCZ", params=[], qubits=qubits)
yield quimb.tensor.Gate("CCZ", params=[], qubits=qubits, **kwargs)
case "cp":
(theta,) = op.params
yield quimb.tensor.Gate("CU1", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("CU1", params=[theta], qubits=qubits, **kwargs)
case "cx":
yield quimb.tensor.Gate("CX", params=[], qubits=qubits)
yield quimb.tensor.Gate("CX", params=[], qubits=qubits, **kwargs)
case "cy":
yield quimb.tensor.Gate("CY", params=[], qubits=qubits)
yield quimb.tensor.Gate("CY", params=[], qubits=qubits, **kwargs)
case "cz":
yield quimb.tensor.Gate("CZ", params=[], qubits=qubits)
yield quimb.tensor.Gate("CZ", params=[], qubits=qubits, **kwargs)
case "h":
yield quimb.tensor.Gate("H", params=[], qubits=qubits)
yield quimb.tensor.Gate("H", params=[], qubits=qubits, **kwargs)
case "id":
yield quimb.tensor.Gate("IDEN", params=[], qubits=qubits)
yield quimb.tensor.Gate("IDEN", params=[], qubits=qubits, **kwargs)
case "iswap":
yield quimb.tensor.Gate("ISWAP", params=[], qubits=qubits)
yield quimb.tensor.Gate("ISWAP", params=[], qubits=qubits, **kwargs)
case "measure":
raise ValueError(
"Encountered a measurement gate, which is not allowed. "
"Remove the measurements from your circuit and try again."
)
case "p":
(theta,) = op.params
yield quimb.tensor.Gate("U1", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("U1", params=[theta], qubits=qubits, **kwargs)
case "rx":
(theta,) = op.params
yield quimb.tensor.Gate("RX", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("RX", params=[theta], qubits=qubits, **kwargs)
case "rxx":
(theta,) = op.params
yield quimb.tensor.Gate("RXX", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("RXX", params=[theta], qubits=qubits, **kwargs)
case "ryy":
(theta,) = op.params
yield quimb.tensor.Gate("RYY", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("RYY", params=[theta], qubits=qubits, **kwargs)
case "rzz":
(theta,) = op.params
yield quimb.tensor.Gate("RZZ", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("RZZ", params=[theta], qubits=qubits, **kwargs)
case "ry":
(theta,) = op.params
yield quimb.tensor.Gate("RY", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("RY", params=[theta], qubits=qubits, **kwargs)
case "rz":
(theta,) = op.params
yield quimb.tensor.Gate("RZ", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("RZ", params=[theta], qubits=qubits, **kwargs)
case "s":
yield quimb.tensor.Gate("S", params=[], qubits=qubits)
yield quimb.tensor.Gate("S", params=[], qubits=qubits, **kwargs)
case "sdg":
yield quimb.tensor.Gate("SDG", params=[], qubits=qubits)
yield quimb.tensor.Gate("SDG", params=[], qubits=qubits, **kwargs)
case "swap":
yield quimb.tensor.Gate("SWAP", params=[], qubits=qubits)
yield quimb.tensor.Gate("SWAP", params=[], qubits=qubits, **kwargs)
case "t":
yield quimb.tensor.Gate("T", params=[], qubits=qubits)
yield quimb.tensor.Gate("T", params=[], qubits=qubits, **kwargs)
case "tdg":
yield quimb.tensor.Gate("TDG", params=[], qubits=qubits)
yield quimb.tensor.Gate("TDG", params=[], qubits=qubits, **kwargs)
case "u1":
(theta,) = op.params
yield quimb.tensor.Gate("U1", params=[theta], qubits=qubits)
yield quimb.tensor.Gate("U1", params=[theta], qubits=qubits, **kwargs)
case "u2":
(phi, lam) = op.params
yield quimb.tensor.Gate("U2", params=[phi, lam], qubits=qubits)
yield quimb.tensor.Gate("U2", params=[phi, lam], qubits=qubits, **kwargs)
case "u3":
(theta, phi, lam) = op.params
yield quimb.tensor.Gate("U3", params=[theta, phi, lam], qubits=qubits)
yield quimb.tensor.Gate(
"U3", params=[theta, phi, lam], qubits=qubits, **kwargs
)
case "x":
yield quimb.tensor.Gate("X", params=[], qubits=qubits)
yield quimb.tensor.Gate("X", params=[], qubits=qubits, **kwargs)
case "xx_plus_yy":
theta, beta = op.params
phi = beta + 0.5 * math.pi
a, b = qubits
yield quimb.tensor.Gate("RZ", params=[phi], qubits=[a])
yield quimb.tensor.Gate("GIVENS", params=[0.5 * theta], qubits=[a, b])
yield quimb.tensor.Gate("RZ", params=[-phi], qubits=[a])
yield quimb.tensor.Gate("RZ", params=[phi], qubits=[a], **kwargs)
yield quimb.tensor.Gate(
"GIVENS", params=[0.5 * theta], qubits=[a, b], **kwargs
)
yield quimb.tensor.Gate("RZ", params=[-phi], qubits=[a], **kwargs)
case "y":
yield quimb.tensor.Gate("Y", params=[], qubits=qubits)
yield quimb.tensor.Gate("Y", params=[], qubits=qubits, **kwargs)
case "z":
yield quimb.tensor.Gate("Z", params=[], qubits=qubits)
yield quimb.tensor.Gate("Z", params=[], qubits=qubits, **kwargs)
case _:
raise ValueError(f"Unsupported gate: {op.name}.")
Loading