CyberIntel ⬡ News
★ Saved ◆ Cyber Reads
← Back ◌ Quantum Computing Apr 13, 2026

Block Encoded Matrix is Permuted in Qiskit

Quantum Computing SE Archived Apr 13, 2026 ✓ Full text saved

Trying to implement block encoding with LCU in Qiskit and the matrix looks correct but is permuted. What am I doing wrong ? from qiskit.quantum_info import SparsePauliOp, Statevector, Operator from qiskit import QuantumCircuit, transpile from qiskit.circuit.library import StatePreparation, PauliGate import numpy as np a = 0.25 b = 0.75 # matrix to be decomposed A = np.array( [[a, 0, 0, b], [0, -a, b, 0], [0, b, a, 0], [b, 0, 0, -a]] ) pauli_op = SparsePauliOp.from_operator(A) n_ancilla = int(np.

Full text archived locally
✦ AI Summary · Claude Sonnet


    Block Encoded Matrix is Permuted in Qiskit Ask Question Asked today Modified today Viewed 9 times 0 Trying to implement block encoding with LCU in Qiskit and the matrix looks correct but is permuted. What am I doing wrong ? from qiskit.quantum_info import SparsePauliOp, Statevector, Operator from qiskit import QuantumCircuit, transpile from qiskit.circuit.library import StatePreparation, PauliGate import numpy as np a = 0.25 b = 0.75 # matrix to be decomposed A = np.array( [[a, 0, 0, b], [0, -a, b, 0], [0, b, a, 0], [b, 0, 0, -a]] ) pauli_op = SparsePauliOp.from_operator(A) n_ancilla = int(np.ceil(np.log2(len(pauli_op.coeffs)))) n_reg = int(np.log2(len(A))) amps = np.sqrt(np.abs(pauli_op.coeffs) / np.linalg.norm(pauli_op.coeffs,ord=1)) padded_amps = np.zeros(2**n_ancilla) padded_amps[:len(amps)] = amps prep_gate = StatePreparation(padded_amps,label="Prep") qc = QuantumCircuit(n_ancilla + n_reg,n_ancilla) qc.append(prep_gate,qc.qubits[:n_ancilla]) for index, pauli in enumerate(pauli_op.paulis): intstr = f"{int(index):0{len(qc.qubits[:n_ancilla])}b}"[::-1] control_pauli_k = PauliGate(pauli.to_label()).control(num_ctrl_qubits=n_ancilla,ctrl_state=intstr) print(control_pauli_k) qc.append(control_pauli_k,qc.qubits) qc.append(prep_gate.inverse(),qc.qubits[:n_ancilla]) # qc.measure(qc.qubits[:n_ancilla],qc.clbits) qc.draw("mpl") Actual [[ 0.25, -0.43, 0. , 0. , 0. , 0. , 0.75, 0.43], [-0.43, 0.75, 0. , 0. , 0. , 0. , 0.43, 0.25], [ 0. , 0. , -0.25, 0.43, 0.75, 0.43, 0. , 0. ], [ 0. , 0. , 0.43, -0.75, 0.43, 0.25, 0. , 0. ], [ 0. , 0. , 0.75, 0.43, 0.25, -0.43, 0. , 0. ], [ 0. , 0. , 0.43, 0.25, -0.43, 0.75, 0. , 0. ], [ 0.75, 0.43, 0. , 0. , 0. , 0. , -0.25, 0.43], [ 0.43, 0.25, 0. , 0. , 0. , 0. , 0.43, -0.75]] Expected [[ 0.25 0. 0. 0.75 -0.43 0. 0. 0.43] [ 0. -0.25 0.75 0. 0. 0.43 0.43 0. ] [ 0. 0.75 0.25 0. 0. 0.43 -0.43 0. ] [ 0.75 0. 0. -0.25 0.43 0. 0. 0.43] [-0.43 0. 0. 0.43 0.75 0. 0. 0.25] [ 0. 0.43 0.43 0. 0. -0.75 0.25 0. ] [ 0. 0.43 -0.43 0. 0. 0.25 0.75 0. ] [ 0.43 0. 0. 0.43 0.25 0. 0. -0.75]] ``` qiskitquantum-stateunitaryblock-encoding Share Improve this question Follow asked 2 hours ago Raghav Baheti 1 New contributor 1 how did you come up with your "expected" matrix? First thing to check is usually the ordering of the tensor product: qiskit puts the "first" qubit last. So try changing all your basis elements from |abc⟩ | 𝑎 𝑏 𝑐 ⟩ to |cba⟩ | 𝑐 𝑏 𝑎 ⟩ . –  DaftWullie Commented 2 hours ago Add a comment Know someone who can answer? Share a link to this question via email, Twitter, or Facebook. Your Answer Sign up or log in Sign up using Google Sign up using Email and Password Post as a guest Name Email Required, but never shown Post Your Answer By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy. Start asking to get answers Find the answer to your question by asking. Ask question Explore related questions qiskitquantum-stateunitaryblock-encoding See similar questions with these tags. The Overflow Blog The messy truth of your AI strategies Gen Z needs a knowledge base (and so do you) Related 4 TranspilerError: 'The input circuit None is not scheduled' 4 Ansatz printing in Qiskit draws a single block 3 Time complexity of block-encoded matrices 3 Block encoding of a diagonal matrix with equidistant eigenvalues 3 Avoiding garbage amplitudes in block-encoding 2 Constructing a block unitary from non-unitary matrices 1 Verifying block encoding by computing inner products 1 Qiskit simulation failed and returned the following error message 0 Block Encoding a 0-1 Matrix 1 Practical Block Encoding for not necessarily sparse matrix Hot Network Questions Cannot Launch Steam: missing libGL.so.1 and cannot install it Can UK/EU dual nationals enter the UK legally with an EU passport via Ireland? Does Wittgenstein believe in metaphysical necessity? Calculating the expected value of a transformation How do I successfully get to this character in Dark Bramble? If Jesus shed his blood once for all time in the fullness of time does this mean old testament Jews were saved by Grace and not by Law Are the new Talgo trains on the Copenhagen-Hamburg route any faster than the old ones in terms of actual travel time? What security/border checks will I go through in a layover in Madrid when traveling from France to the US? Are there any issues with trading responsibilities for privileges? NSolve where function being searched is the result of a DE Geometric proof of contraction of maximal ideals Photo/Text of this Source How to disassemble a CatEye Viz450 rear light for repair? Does Jesus's warning during His "Triumphal Entry" force interpretation of "this Generation" (Matt. 24) as referring to the First Century Jews? Finding a PCB connector for this OLED display FPC interface marginnote inhibits noindent in following paragraph What are some advantages of set theory compared to type theory for mathematical research (foundations or otherwise)? Is there a way to conduct an internationally-acknowledged referendum? Removing grid lines from a paper drawing Is there a sefer for halachos for when the Mashiach comes? Is it an isosceles triangle? From the LUKS unlock screen, how can I shut down automatically after a timeout if no password is entered? Graphing a system of inequalities in 3 dimensions Invoke a command from a variable on the left side while passing an argument on the right Question feed By continuing to use this website, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. By exiting this window, default cookies will be accepted. To reject cookies, select an option from below. Customize settings Cookie Consent Preference Center When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences, or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, blocking some types of cookies may impact your experience of the site and the services we are able to offer. Cookie Policy Accept all cookies Manage Consent Preferences Strictly Necessary Cookies Always Active These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information. Targeting Cookies Targeting Cookies These cookies are used to make advertising messages more relevant to you and may be set through our site by us or by our advertising partners. They may be used to build a profile of your interests and show you relevant advertising on our site or on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. Performance Cookies Performance Cookies These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance. Functional Cookies Functional Cookies These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly. Cookie List Clear checkbox label label Apply Cancel Consent Leg.Interest checkbox label label checkbox label label checkbox label label Necessary cookies only Confirm My Choices
    💬 Team Notes
    Article Info
    Source
    Quantum Computing SE
    Category
    ◌ Quantum Computing
    Published
    Apr 13, 2026
    Archived
    Apr 13, 2026
    Full Text
    ✓ Saved locally
    Open Original ↗