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

BQSKit is crashing when trying to compile a unitary using a gate set that has only VariableUnitaryGate #286

Open
alonkukl opened this issue Oct 1, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@alonkukl
Copy link
Contributor

alonkukl commented Oct 1, 2024

The following code makes BQSkit crash with pyo3_runtime.PanicException: not implemented. Probably QFactor is getting a circuit with gates it can't handle.


from bqskit import compile, MachineModel
from bqskit.compiler import Compiler
from bqskit.qis.unitary import UnitaryMatrix
from bqskit.ir.gates import VariableUnitaryGate


target = UnitaryMatrix.random(4)

model = MachineModel(4, gate_set={VariableUnitaryGate(3)})


comp = Compiler(num_workers=10)
synthesized_circuit = compile(target, max_synthesis_size=4, model=model, compiler=comp)
@alonkukl alonkukl added the bug Something isn't working label Oct 1, 2024
@alonkukl
Copy link
Contributor Author

alonkukl commented Oct 1, 2024

I think that the root cause of this crash is the way a layer generator is created from a gate set.

When a layer generator isn't given to QSearch (and to LEAP), then it asks the gate set object to generate a layer generator, using the function build_mq_layer_generator.

In our case, there is no single qubit gate, so the above function adds the U3 as a single qubit, which in turn QFactor can't handle.

BQSKit shouldn't have added a gate that wasn't part of the original gate set. This behaviour is documented The resulting layer generator will use arbitrary single-qudit gates. but it is wrong. It can produce a warning that a single qubit gate is missing, but it shouldn't add a gate to the gate set.

In my case, I can bypass this issue, by directly creating QSearch and providing it with the correct layer generator
WideLayerGenerator(VariableUnitaryGate(3), None)

@edyounis
Copy link
Member

edyounis commented Oct 1, 2024

Most gate sets will not include a general single-qudit gate, so we introduce one during compilation stages that focus on multi-qudit gate optimization/transpilation. You are right; in this case and cases like this, we shouldn't be mocking with the gate set. We should check if the gate set contains multi-qudit general gates. If so, we don't need to use the layer generator with single-qudit gates added.

@alonkukl
Copy link
Contributor Author

alonkukl commented Oct 1, 2024

I have a different perspective.

If the user has explicitly provided a gate set, the tool shouldn't change it. The tool can give a warning or an error if the gate set isn't general enough or has other issues.

@edyounis
Copy link
Member

edyounis commented Oct 1, 2024

In the case that I am referring to, the gate set is modified for specific compilation stages. The later stages reverse the modifications, so the user gate set is always honored.

@alonkukl
Copy link
Contributor Author

alonkukl commented Oct 2, 2024

OK, then your solution above looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants