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

Evolved operator functions #13361

Merged
merged 34 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3a15589
py version for expand
Cryoris Oct 3, 2024
cea830b
Merge branch 'main' into paulievo
Cryoris Oct 7, 2024
72f2689
expand fully & simplify lie trotter
Cryoris Oct 7, 2024
8cd2c25
use examples that actually do not commute
Cryoris Oct 8, 2024
681105d
add plugin structure
Cryoris Oct 8, 2024
58e4a03
fix plugin name, rm complex from expand
Cryoris Oct 11, 2024
7f2ec3d
paulievo in Rust
Cryoris Oct 11, 2024
f9b72cf
take care of global phase
Cryoris Oct 11, 2024
3985394
support barriers
Cryoris Oct 11, 2024
99a1153
fix time parameter
Cryoris Oct 11, 2024
214b969
fix lint
Cryoris Oct 14, 2024
d96cebf
Merge branch 'paulievo' into rust/paulievo
Cryoris Oct 14, 2024
e8bcc4f
fix final barrier
Cryoris Oct 14, 2024
aba92e2
fix wrapping
Cryoris Oct 15, 2024
4fcf639
add reno and HLS docs
Cryoris Oct 15, 2024
b53b332
Merge branch 'main' into paulievo
Cryoris Oct 15, 2024
5c95b0d
fix unreachable
Cryoris Oct 15, 2024
2eb66f1
fix QPY test & pauli feature map
Cryoris Oct 15, 2024
87496d2
use SX as basis tranfo
Cryoris Oct 15, 2024
4a81172
Merge branch 'main' into paulievo
Cryoris Oct 21, 2024
84ece72
QAOA/EvolvedOp functions
Cryoris Oct 23, 2024
fc43572
add docs
Cryoris Oct 23, 2024
546cc5f
slight performance tweak
Cryoris Oct 23, 2024
551cd8e
Merge branch 'paulievo' of github.com:Cryoris/qiskit-terra into paulievo
Cryoris Oct 23, 2024
f64c8e1
Merge branch 'paulievo' into clib/qaoa
Cryoris Oct 23, 2024
d0cfd50
add reno
Cryoris Oct 23, 2024
05317ff
lint
Cryoris Oct 25, 2024
d8417d9
Merge branch 'main' into clib/qaoa
Cryoris Nov 5, 2024
6bf40b8
fix merge artifacts & typos
Cryoris Nov 5, 2024
e08f71b
docssssssssss
Cryoris Nov 5, 2024
3e009a5
review comments
Cryoris Nov 5, 2024
076f467
review comments
Cryoris Nov 7, 2024
3c71f55
Merge branch 'main' into clib/qaoa
Cryoris Nov 7, 2024
9abd7ea
remove broken docs
Cryoris Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/accelerate/src/circuit_library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod iqp;
mod pauli_evolution;
mod pauli_feature_map;
mod quantum_volume;
mod utils;

pub fn circuit_library(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(pauli_evolution::py_pauli_evolution))?;
Expand Down
12 changes: 3 additions & 9 deletions crates/accelerate/src/circuit_library/pauli_evolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ use pyo3::prelude::*;
use pyo3::types::{PyList, PyString, PyTuple};
use qiskit_circuit::circuit_data::CircuitData;
use qiskit_circuit::operations::{multiply_param, radd_param, Param, PyInstruction, StandardGate};
use qiskit_circuit::packed_instruction::PackedOperation;
use qiskit_circuit::{imports, Clbit, Qubit};
use qiskit_circuit::{imports, Qubit};
use smallvec::{smallvec, SmallVec};

use crate::circuit_library::utils::{Instruction, StandardInstruction};

// custom types for a more readable code
type StandardInstruction = (StandardGate, SmallVec<[Param; 3]>, SmallVec<[Qubit; 2]>);
type Instruction = (
PackedOperation,
SmallVec<[Param; 3]>,
Vec<Qubit>,
Vec<Clbit>,
);

/// Return instructions (using only StandardGate operations) to implement a Pauli evolution
/// of a given Pauli string over a given time (as Param).
Expand Down
11 changes: 2 additions & 9 deletions crates/accelerate/src/circuit_library/pauli_feature_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ use qiskit_circuit::circuit_data::CircuitData;
use qiskit_circuit::imports;
use qiskit_circuit::operations::PyInstruction;
use qiskit_circuit::operations::{add_param, multiply_param, multiply_params, Param, StandardGate};
use qiskit_circuit::packed_instruction::PackedOperation;
use qiskit_circuit::{Clbit, Qubit};
use smallvec::{smallvec, SmallVec};
use smallvec::smallvec;
use std::f64::consts::PI;

use crate::circuit_library::entanglement;
use crate::circuit_library::pauli_evolution;
use crate::circuit_library::utils::Instruction;
use crate::QiskitError;

type Instruction = (
PackedOperation,
SmallVec<[Param; 3]>,
Vec<Qubit>,
Vec<Clbit>,
);

/// Build a Pauli feature map circuit.
///
/// Args:
Expand Down
26 changes: 26 additions & 0 deletions crates/accelerate/src/circuit_library/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This code is part of Qiskit.
//
// (C) Copyright IBM 2024
//
// This code is licensed under the Apache License, Version 2.0. You may
// obtain a copy of this license in the LICENSE.txt file in the root directory
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

use qiskit_circuit::{
operations::{Param, StandardGate},
packed_instruction::PackedOperation,
Clbit, Qubit,
};
use smallvec::SmallVec;

pub(super) type StandardInstruction = (StandardGate, SmallVec<[Param; 3]>, SmallVec<[Qubit; 2]>);
pub(super) type Instruction = (
PackedOperation,
SmallVec<[Param; 3]>,
Vec<Qubit>,
Vec<Clbit>,
);
alexanderivrii marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions crates/circuit/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2335,13 +2335,15 @@ pub fn add_param(param: &Param, summand: f64, py: Python) -> Param {
.call_method1(py, intern!(py, "__add__"), (summand,))
.expect("Sum of Parameter expression and float failed."),
),
Param::Obj(_) => unreachable!(),
Param::Obj(_) => unreachable!("Unsupported addition of a Param::Obj."),
}
}

pub fn radd_param(param1: Param, param2: Param, py: Python) -> Param {
match [param1, param2] {
[Param::Float(theta), Param::Float(lambda)] => Param::Float(theta + lambda),
[param, Param::Float(lambda)] => add_param(&param, lambda, py),
[Param::Float(theta), param] => add_param(&param, theta, py),
[Param::ParameterExpression(theta), Param::ParameterExpression(lambda)] => {
Param::ParameterExpression(
theta
Expand All @@ -2350,7 +2352,7 @@ pub fn radd_param(param1: Param, param2: Param, py: Python) -> Param {
.expect("Parameter expression addition failed"),
)
}
_ => unreachable!(),
_ => unreachable!("Unsupported addition."),
}
}

Expand Down
10 changes: 10 additions & 0 deletions qiskit/circuit/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@
ExcitationPreserving
QAOAAnsatz

The following functions return a parameterized :class:`.QuantumCircuit` to use as ansatz in
a broad set of variational algorithms:

.. autofunction:: hamiltonian_variational_ansatz
.. autofunction:: evolved_operator_ansatz
.. autofunction:: qaoa_ansatz


Data encoding circuits
======================
Expand Down Expand Up @@ -576,8 +583,11 @@
PauliTwoDesign,
RealAmplitudes,
EfficientSU2,
hamiltonian_variational_ansatz,
evolved_operator_ansatz,
EvolvedOperatorAnsatz,
ExcitationPreserving,
qaoa_ansatz,
QAOAAnsatz,
)
from .data_preparation import (
Expand Down
11 changes: 9 additions & 2 deletions qiskit/circuit/library/n_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@
from .pauli_two_design import PauliTwoDesign
from .real_amplitudes import RealAmplitudes
from .efficient_su2 import EfficientSU2
from .evolved_operator_ansatz import EvolvedOperatorAnsatz
from .evolved_operator_ansatz import (
EvolvedOperatorAnsatz,
evolved_operator_ansatz,
hamiltonian_variational_ansatz,
)
from .excitation_preserving import ExcitationPreserving
from .qaoa_ansatz import QAOAAnsatz
from .qaoa_ansatz import QAOAAnsatz, qaoa_ansatz

__all__ = [
"NLocal",
"TwoLocal",
"RealAmplitudes",
"PauliTwoDesign",
"EfficientSU2",
"hamiltonian_variational_ansatz",
"evolved_operator_ansatz",
"EvolvedOperatorAnsatz",
"ExcitationPreserving",
"qaoa_ansatz",
"QAOAAnsatz",
]
Loading
Loading