-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Is MatrixGate supported with sympy? If not, can/shall we support it? #7206
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
Comments
I suspect this isn't going to be a good way for you to solve your problem. Let's discuss it when you're free. You can put something on my calendar. |
@babacry why not just get the unitary matrices and multiply them? |
I will need to My initial plan is to use either cirq.merge_operations directly or use Another option for me is to multiply numerics of 2x2 matrices then locate all the merging locations by tagging them in the Any other suggestions on |
@babacry simple does the trick def merge_single_qubit_ops(op1, op2):
# merge using unitaries and return PhasedXZGate
def transform_circuit(circuit, sweep):
prv_op = {}
new_ops = []
for op in circuit.all_operations():
if cirq.num_qubits(op) == 1:
q, = op.qubits
prv_op[q] = merge_single_qubit_op(prv_op.get(q, None), op)
continue
for q in op.qubits:
if q in prv_op:
new_ops.append(prv_op[q])
del prv_op[q]
new_ops.append(op)
new_ops.extend(prv_op.values())
return cirq.Circuit(new_ops) later we can add a |
There's also a |
Thanks for the suggestions. I will probably close this feature request as I was just thinking if such thing exists or is a low hanging fruits that can be easily implemented. Eliott, I have different implementation approaches in my mind, the first approach apparently failed as I though I can store things via "MatrixGate('A')". I've tried other approaches under the util functions in transformer_primitives, which I think is the best way to handle all the corner cases we will possibly meet in implementations, #7149 worked IMO, though I still need to fix it, but it would be great if you can do some local test. Nour, thanks for the idea, I was thinking about looping the ops myself, but that requires extra care in handling all the corner cases including recursive transformation and I need to keep track of a lot of variables, which are already handled in the existing modules of transformer_primitives, e.g., merge_operations, merge_k_qubit_gates etc. So I would prefer using the existing function. It generally worked in #7149, but I still need to fix the draft pr. Dax, good to know cirq.mul and we can implement |
Is your feature request related to a use case or problem? Please explain
I wonder if we've already supported / we can support a symbolized MatrixGate like
or
where
sa,sb,sc,sd
are symbolsDescribe the solution you would prefer
I am not an expert of
sympy
, I understand we need to check dimensions, unitaries for an instantiation of aMatrixGate
, wonder what's like and how difficult it is to make MatrixGate compatible with sympy?How urgent is this for you? Is it blocking important work?
P2/P3. It's good to have, but I have workarouds (see below). I can also workaround in my generic approach in implemeting #6994. Feel free to close this feature request if it's not possible to implement.
Describe alternatives/workarounds you've considered
Convert 2x2 matrix gate to PhXZ gate first then symbolize.
Provide additional information or context (e.g., screenshots)
I need this in supporting #6994, which need some intermediate matrix multiplication numeric sweeps that's better stored in symbolized matrices instead of converting to PhXZ first then symbolize, which requires extra calculation.
The text was updated successfully, but these errors were encountered: