5

You can use a callback function to save the parameters for each iterations of your vqe algorithm and even store the mean, std. Below an example: # Create the callback function to store intermediate values in vqe counts = [] values = [] parameters_list=[] std_list=[] def store_intermediate_result(eval_count, parameters, mean, std): counts.append(...


4

qiskit-terra 0.16 or lower As answered, probably the most canonical way to do this is with Statevector.from_label and initialize. Here is the full example: from qiskit import * from qiskit.quantum_info import Statevector n = 2 qc = QuantumCircuit(n) qc.initialize(Statevector.from_label('1'*n).data, range(n)) qc.draw() ┌──────────────────────┐ q_0: ┤0 ...


4

You can also create a Statevector, that can be directly initialized as follows: from qiskit.quantum_info import Statevector sv = Statevector.from_label('11') You can use sv.evolve(qc) to apply an operator/circuit to the state, where qc is the operator/circuit. sv.data gives you the numpy array, containing the actual implementation of the state. Check this ...


4

I have found the solution! The problem is that each time you use the transpile function, it generates a different transpiled circuit and the order of the outcome is not necessary the same as the order of the input, so you have to use swap gates to obtain the correct one. In order to always obtain the same circuit you have to fit the seed_transpiler (as with ...


3

Typically the second option: you map the fermionic occupation number for each single-particle state to a qubit. (Also, the usual convention is that $0$ denotes unoccupied, $1$ denotes occupied ;) This mapping is usually accomplished via the Jordan-Wigner or Bravyi-Kitaev transformation, or some hybrid of the two: see https://arxiv.org/abs/1208.5986 for a ...


2

Instead of accessing results._final_simulator_state.density_matrix, which has a leading underscore implying you shouldn't be using it or relying on it to stay stable, use results.final_density_matrix. Making that substitution seems to result in the code working. Separately, I think the fact that what you did doesn't work is a bug. It seems that the method ...


2

The initialize method uses an algorithm to generate a set of gates that implement your input statevector. Therefore it can also be used on real hardware. But it is important to note, that this is a generic algorithm that works for any statevector. There might be much more efficient preparations for your particular case. You should definitely check if there ...


2

Here's the source code for quantumregister.py and quantumcircuit.py. The default is $|0\rangle$. The code goes like: from qiskit import QuantumCircuit, QuantumRegister qr = QuantumRegister(1) circuit = QuantumCircuit(qr) By the way, if you're just beginning with Qiskit, you could check out Dr. Moran's textbook (this specific example is covered in ...


2

There is no replace() method, but you can do the trick by means of pop() and insert(). Example: from qiskit import QuantumCircuit, Aer, execute from qiskit.extensions.standard import XGate simulator = Aer.get_backend("qasm_simulator") qc = QuantumCircuit(4,4) qc.h([0,1,2,3]) qc.measure([0,1,2,3], [0,1,2,3]) print(qc.draw()) result = execute(qc, backend=...


1

John Preskill identified the bottleneck you described as a fundamental problem in quantum deep learning (section 6.5, here). In particular, But typical proposals for quantum machine learning applications are confounded by severe input/output bottlenecks. For applications to large classical data sets one should take into account the cost of encoding ...


1

All your real parts and imaginary parts are interchanged. Have you used complex(1,0) instead of complex(0,1) or something similar? Without the code one can only guess. Hope you can resolve it.


1

If you have the circuit, you can get the registers the circuit acts on from eigs_circ.qregs. You can then create another circuit using the returned quantum register, add an instruction to it (initialize) and then add these two circuits together. Your final code should look something like qregs = eigs_circ.qregs # NB this is a list qc = ...


1

You have some quantum algorithms assuming you prepared a special input state which is not represented as a superposition of bitstrings. For example, you can just say you start in the $| + \rangle$ state for all your qubits. Another one is starting in a state where you have encoded your input in the amplitudes of a quantum state (this type of encoding is ...


Only top voted, non community-wiki answers of a minimum length are eligible