Circuit Constraints¶
When creating a circuit generator, one may pass some constraints to the generation. As an example, one may require that no more than 53 qubits will be used. Thus, Classiq presents the following constraints, each may be passed 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
Passing constraints is done as follows:
from classiq import ModelDesigner
from classiq.interface.generator.model import Constraints
from classiq.interface.generator.transpiler_basis_gates import TranspilerBasisGates
from classiq.interface.generator.range_types import NonNegativeIntRange
constraints = Constraints(
max_width=20,
max_depth=100,
max_gate_count={
TranspilerBasisGates.CX: 10,
TranspilerBasisGates.T: 20,
},
)
model_designer = ModelDesigner(constraints=constraints)
{
"constraints": {
"max_width": 20,
"max_depth": 100,
"max_gate_count": {
"CX": 10,
"T": 20
}
}
}
Optimization Parameter¶
When synthesizing a circuit, one might wish to optimize the circuit according to some
parameter. This can be done by setting the optimization_parameter
field. The possible
parameters are the same parameters that can be constrained.
In the example below, we remove the width constraint in the circuit, and instead set it as the optimization parameter.
from classiq import ModelDesigner
from classiq.interface.generator.transpiler_basis_gates import TranspilerBasisGates
from classiq.interface.generator.model import Constraints
from classiq.interface.generator.model.constraints import OptimizationParameter
from classiq.interface.generator.range_types import NonNegativeIntRange
constraints = Constraints(
max_depth=100,
max_gate_count={
TranspilerBasisGates.CX: 10,
TranspilerBasisGates.T: 20,
},
optimization_parameter=OptimizationParameter.WIDTH,
)
model_designer = ModelDesigner(constraints=constraints)
{
"constraints": {
"max_depth": 20,
"max_gate_count": {
"CX": 10,
"T": 20
},
"optimization_parameter": "width"
}
}