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

[bugfix] fix double-free and invalid depth-evaluation in probabilistic gate #45

Merged

Conversation

corryvrequan
Copy link
Contributor

  • Bug description
    When we call QuantumCircuit::to_string with a quantum circuit with ProbabilisticGate in python, the kernel crashes.

  • Reason
    Since the number of target qubits in ProbabilisticGate cannot be determined before execution, it returns zero as a temporal value.
    However, a function QuantumCircuit::to_string crashes when it encounters any gate of which the number of target qubits is zero.

  • Update
    The behavior of QuantumCircuit::to_string is changed, and it now ignores any gate with empty target qubit list.
    I also added small test function for checking to_string with probabilistic gate.

@corryvrequan corryvrequan changed the base branch from master to dev November 19, 2018 14:50
@corryvrequan
Copy link
Contributor Author

corryvrequan commented Nov 20, 2018

  • Bug description

When we add ProbabilisticGate generated by functions such as DepolarizingNoise to a circuit in python, and a circuit accesses the gate, python kernel crashes.

  • Reason

When we add probabilistic gate to a python in this way, python releases instances which are still used in C++. This cause that circuit accesses released gate and use it for state updates.

  • Update

We redirect circuit::add_gate in python to circuit::add_gate_copy in C++,
and we make a new member function circuit::add_gate_consume only for python, which is redirected to circuit::add_gate in C++.

This makes C++-code independent of python-related pointer as default behavior.
Main drawbacks of these changes are that "add_gate" slows down since it copies gate matrix, and it requires additional memory for copying gate matrix.

@corryvrequan corryvrequan changed the title [bugfix] ignore probabilistic gate in depth eval [bugfix] fix double-free and invalid depth-evaluation in probabilistic gate Nov 20, 2018
@TenninYan TenninYan merged commit 3b73403 into qulacs:dev Nov 21, 2018
heliac2000 pushed a commit to heliac2000/qulacs that referenced this pull request Aug 21, 2020
…tic_target_eval

[bugfix] fix double-free and invalid depth-evaluation in probabilistic gate
kotamanegi added a commit to kotamanegi/qulacs that referenced this pull request Jun 14, 2022
m-ymzk added a commit to m-ymzk/qulacs that referenced this pull request Apr 16, 2023
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.

2 participants