qrisp.jasp.Jaspr.control#
- Jaspr.control(num_ctrl: int, ctrl_state: int | str = -1) Jaspr[source]#
Returns the controlled version of the Jaspr. The control qubits are added to the signature of the Jaspr as the arguments after the QuantumState.
- Parameters:
- num_ctrlint
The amount of controls to be added.
- ctrl_stateint or str, optional
The control state on which to activate. The default is -1.
- Returns:
- Jaspr
The controlled Jaspr.
Examples
We create a simple script and inspect the controlled version:
from qrisp import * from qrisp.jasp import make_jaspr def example_function(i): qv = QuantumVariable(i) cx(qv[0], qv[1]) t(qv[1]) return qv jaspr = make_jaspr(example_function)(2) print(jaspr.control(2)) # Yields # { lambda ; a:Qubit b:Qubit c:i64[] d:QuantumState. let # e:QubitArray f:QuantumState = jasp.create_qubits 1:i64[] d # g:Qubit = jasp.get_qubit e 0:i64[] # h:QuantumState = jasp.quantum_gate[gate=2cx] a b g f # i:QubitArray j:QuantumState = jasp.create_qubits c h # k:Qubit = jasp.get_qubit i 0:i64[] # l:Qubit = jasp.get_qubit i 1:i64[] # m:QuantumState = jasp.quantum_gate[gate=ccx] g k l j # n:QuantumState = jasp.quantum_gate[gate=ct] g l m # o:QuantumState = jasp.quantum_gate[gate=2cx] a b g n # p:QuantumState = jasp.delete_qubits e o # in (i, p) }
We see that the control qubits are part of the function signature (
aandb).