mimiqcircuits.operations.control¶
Control operation.
Functions
|
Decorator to register a canonical Control subclass. |
|
Decorator to register a decomposition function for a specific gate type. |
Classes
|
Control operation that applies multi-control gates to a Circuit. |
- class mimiqcircuits.operations.control.Control(num_controls=None, operation=None, *args, **kwargs)[source]¶
Bases:
GateControl operation that applies multi-control gates to a Circuit.
A Control is a special operation that wraps another gate with multiple control qubits.
When a canonical subclass is registered (e.g., GateCX for Control(1, GateX())), constructing Control with matching arguments will return an instance of that subclass. This enables isinstance() checks to work correctly:
Examples
>>> from mimiqcircuits import * >>> isinstance(Control(1, GateX()), GateCX) True >>> c = Circuit() >>> c.push(Control(3,GateX()),1,2,3,4) 5-qubit circuit with 1 instruction: └── C₃X @ q[1:3], q[4] >>> Control(2, GateX()).matrix() [1.0, 0, 0, 0, 0, 0, 0, 0] [0, 1.0, 0, 0, 0, 0, 0, 0] [0, 0, 1.0, 0, 0, 0, 0, 0] [0, 0, 0, 1.0, 0, 0, 0, 0] [0, 0, 0, 0, 1.0, 0, 0, 0] [0, 0, 0, 0, 0, 1.0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 1.0] [0, 0, 0, 0, 0, 0, 1.0, 0]
- static __new__(cls, num_controls=None, operation=None, *args, **kwargs)[source]¶
Create a Control instance, returning canonical subclass if registered.
If a canonical subclass is registered for (num_controls, type(operation)), an instance of that subclass is returned instead of a plain Control.
- Parameters:
- Returns:
Instance of Control or a registered canonical subclass
- __init__(num_controls, operation, *args, **kwargs)[source]¶
Initialize a Control gate.
- Parameters:
- Raises:
TypeError – If operation is not a Gate object or Gate class
ValueError – If num_controls is less than 1
- inverse()[source]¶
Return the inverse of this controlled operation.
- Returns:
New Control operation with inverted target gate
- Return type:
- getparams()[source]¶
Get parameters from the wrapped operation.
- Returns:
Parameters of the wrapped operation
- Return type:
Any
- control(*args)[source]¶
Create a new controlled operation with additional controls.
- Parameters:
*args – Optional number of additional controls
- Returns:
Lazy computation or new Control operation
- Return type:
Union[lazy.LazyValue, Control]
- Raises:
ValueError – If invalid number of arguments
- power(*args)[source]¶
Create a new operation raised to a power.
- Parameters:
*args – Optional power value
- Returns:
Lazy computation or new Control operation
- Return type:
Union[lazy.LazyValue, Control]
- Raises:
ValueError – If invalid number of arguments
- parallel(*args)[source]¶
Create parallel copies of this operation.
- Parameters:
*args – Optional number of parallel copies
- Returns:
Lazy computation or new Parallel operation
- Return type:
Union[lazy.LazyValue, Parallel]
- Raises:
ValueError – If invalid number of arguments
- iswrapper()[source]¶
Check if this operation is a wrapper.
- Returns:
Always True for Control operations
- Return type:
- __str__()[source]¶
Get string representation of the Control operation.
- Returns:
String representation with subscript for number of controls
- Return type:
- mimiqcircuits.operations.control.canonical_control(num_controls, inner_gate_type)[source]¶
Decorator to register a canonical Control subclass.
When Control(num_controls, inner_gate_type()) is called, it will return an instance of the decorated subclass instead.
- Parameters:
- Returns:
Decorator that registers the class
Example
>>> from mimiqcircuits import * >>> @canonical_control(1, GateX) ... class GateCX(Control): ... pass >>> isinstance(Control(1, GateX()), GateCX) True