Circuit Constraints¶
When synthesizing a circuit, you can pass in constraints to the generation; for example, requiring that no more than 53 qubits will be used. Classiq allows the following constraints, each of which can pass to the circuit generator:
- Depth: the maximum depth of the circuit
- Width: the maximum amount of qubits in the circuit
- Gate count: the maximum number of times a gate appears
Pass constraints as follows:
from classiq import Model
from classiq.model import Constraints, TranspilerBasisGates
from classiq.builtin_functions.range_types import NonNegativeIntRange
constraints = Constraints(
max_width=20,
max_depth=100,
max_gate_count={
TranspilerBasisGates.CX: 10,
TranspilerBasisGates.T: 20,
},
)
model = Model(constraints=constraints)
model.synthesize()
Alternatively, you can pass the constraints in the constraints
argument of the
synthesize
method.
{
"constraints": {
"max_width": 20,
"max_depth": 100,
"max_gate_count": {
"CX": 10,
"T": 20
}
},
"logic_flow": []
}
Optimization Parameter¶
When synthesizing a circuit, to optimize the circuit according to a
parameter, set the optimization_parameter
field. The possible
parameters are the same parameters that can be constrained.
The following example shows how to remove the width constraint in the circuit, setting it instead as the optimization parameter.
from classiq import Model
from classiq.model import Constraints, TranspilerBasisGates, OptimizationParameter
from classiq.builtin_functions.range_types import NonNegativeIntRange
constraints = Constraints(
max_depth=100,
max_gate_count={
TranspilerBasisGates.CX: 10,
TranspilerBasisGates.T: 20,
},
optimization_parameter=OptimizationParameter.WIDTH,
)
model = Model()
model.synthesize(constraints=constraints)
{
"constraints": {
"max_depth": 20,
"max_gate_count": {
"CX": 10,
"T": 20
},
"optimization_parameter": "width"
},
"logic_flow": []
}