Skip to content

Conversation

@PietropaoloFrisoni
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni commented Nov 10, 2025

Context: This PR implements the state preparation algorithm based on the technique using multiplexers. However, instead of the latter, we use the qswitch function.

Description of the Change: As above. For a description of the algorithm, we refer to the documentation.

Benefits: Qrisp can now initialize a quantum circuit without resorting to qiskit.

Possible Drawbacks: None that I can think of, although we can probably implement a more efficient algorithm in the future. The reason is that the qswitch function introduces several auxiliary qubits, which can easily cause overhead.

Related GitHub Issues: None

@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review November 27, 2025 12:39
# n is static (known at compile time), so we can use normal numpy here
n = int(np.log2(target_array.shape[0]))

thetas, u_params, phases = _preprocess(target_array)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This classical preprocessing function for n=20 takes 0.3 seconds on my laptop (each layer is vectorized with vmap). Therefore, most of the time is spent in the quantum part, which basically just calls qswitch (with a bit reverse operation, as we cannot slice a DynamicQubitArray backward)


int_encoder(self, self.encoder(value))

def init_state_qswitch(self, state_array, method="auto"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@positr0nium Instead of having a separate init_state_qswitch method, what about modifying the existing init_state in such a way that the workflow is dispatched with different implementations depending on the type of the provided argument?

That is, if a dict is provided, the qiskit implementation is used, which is currently based on a different (and currently more efficient) algorithm, while if an array is provided we dispatch to the implementation introduced in this PR. Please let me know what you think : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant