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

v1.0.0 release #157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Tutorials/1-Operators-tutorial .ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"The transformation unitary $\\hat{V}^{(\\ell)}_k$ is a one qubit gate that transforms $\\hat{X}$ or $\\hat{Y}$ into $\\hat{Z}$.\n",
"\n",
"\n",
"In QForte this requires one to pass a coefficient and q `Circuit` to the utility function `exponentiate_pauli_string().`\n",
"In QForte this requires one to pass a coefficient and q `Circuit` to the utility function `exp_pauli_string().`\n",
"\n",
"> Build the circuit corresponding to $\\exp(-i 0.5 \\hat{X}_3 \\hat{Z}_2 \\hat{Z}_1 \\hat{Z}_0)$ "
]
Expand Down Expand Up @@ -250,7 +250,7 @@
"factor = -1.0j * theta\n",
"\n",
"# Construct the unitary for the exonential\n",
"Uexp, phase = exponentiate_pauli_string(factor, circ)\n",
"Uexp, phase = exp_pauli_string(factor, circ)\n",
"print('\\n The exponential unitary circuit: \\n',Uexp)"
]
},
Expand Down
10 changes: 5 additions & 5 deletions Tutorials/3-Molecular-hamiltonians.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@
"id": "fabulous-press",
"metadata": {},
"source": [
"In QForte one can measure a (symmetric) expectation value of an operator with the function `QC.direct_op_exp_val(operaotr)`. Note that this function returns a complex value.\n",
"In QForte one can measure a (symmetric) expectation value of an operator with the function `QC.expectation(operaotr)`. Note that this function returns a complex value.\n",
"\n",
"> Calculate $E_\\mathrm{HF} = \\bra{\\Phi_\\mathrm{HF}} \\hat{\\mathcal{H}} \\ket{\\Phi_\\mathrm{HF}}$ using `QC.direct_op_exp_val(operaotr)`."
"> Calculate $E_\\mathrm{HF} = \\bra{\\Phi_\\mathrm{HF}} \\hat{\\mathcal{H}} \\ket{\\Phi_\\mathrm{HF}}$ using `QC.expectation(operaotr)`."
]
},
{
Expand All @@ -307,7 +307,7 @@
}
],
"source": [
"Ehf = np.real(QC.direct_op_exp_val(H2mol.hamiltonian))\n",
"Ehf = np.real(QC.expectation(H2mol.hamiltonian))\n",
"\n",
"print(f'The Hartree-Fock energy from Psi4: {H2mol.hf_energy:12.10f}')\n",
"print(f'The Hartree-Fock energy from QForte: {Ehf:12.10f}')"
Expand Down Expand Up @@ -467,7 +467,7 @@
" UI = get_UI(Phi_I)\n",
" QC.apply_circuit(UI)\n",
" \n",
" HII = np.real(QC.direct_op_exp_val(Ham))\n",
" HII = np.real(QC.expectation(Ham))\n",
" \n",
" return HII\n",
"\n",
Expand All @@ -480,7 +480,7 @@
" Usplit = get_Usplit(Phi_I, Phi_J)\n",
" QC.apply_circuit(Usplit)\n",
" \n",
" HIJ = np.real(QC.direct_op_exp_val(Ham)) - 0.5*HII - 0.5*HJJ\n",
" HIJ = np.real(QC.expectation(Ham)) - 0.5*HII - 0.5*HJJ\n",
" \n",
" return HIJ"
]
Expand Down
10 changes: 5 additions & 5 deletions Tutorials/4-Implementing-algorithms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,13 @@
"print('---------------------------------------')\n",
"qc = qforte.Computer(len(ref))\n",
"qc.apply_circuit(Uhf)\n",
"E0 = qc.direct_op_exp_val(H2mol.hamiltonian)\n",
"E0 = qc.expectation(H2mol.hamiltonian)\n",
"\n",
"for i in range(len(ref)):\n",
" qc = qforte.Computer(4)\n",
" qc.apply_circuit(Uhf)\n",
" qc.apply_gate(qforte.gate('X', i))\n",
" Ei = qc.direct_op_exp_val(H2mol.hamiltonian)\n",
" Ei = qc.expectation(H2mol.hamiltonian)\n",
"\n",
" if(i<sum(ref)):\n",
" ei = E0 - Ei\n",
Expand Down Expand Up @@ -436,14 +436,14 @@
" QC.apply_circuit(Uducc)\n",
"\n",
" # Get the PQE energy.\n",
" E0 = np.real(QC.direct_op_exp_val(H2mol.hamiltonian())\n",
" E0 = np.real(QC.expectation(H2mol.hamiltonian())\n",
"\n",
" # Get the excited determinannt energy by applying K to the HF state.\n",
" QC = qf.Computer(4)\n",
" QC.apply_circuit(Uhf)\n",
" QC.apply_operator(K.jw_transform())\n",
" QC.apply_circuit(Uducc)\n",
" Emu = np.real(QC.direct_op_exp_val(H2mol.hamiltonian))\n",
" Emu = np.real(QC.expectation(H2mol.hamiltonian))\n",
" \n",
" # Re-initialize a QuantumComputer.\n",
" QC = qf.Computer(4)\n",
Expand All @@ -455,7 +455,7 @@
"\n",
" # Get the mixed state energy\n",
" QC.apply_circuit(Uducc)\n",
" Eomega = np.real(QC.direct_op_exp_val(H2mol.hamiltonian))\n",
" Eomega = np.real(QC.expectation(H2mol.hamiltonian))\n",
"\n",
" return Eomega, Emu, E0"
]
Expand Down
2 changes: 2 additions & 0 deletions bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"%PYTHON%" setup.py install
if errorlevel 1 exit 1
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$PYTHON setup.py install
25 changes: 25 additions & 0 deletions meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package:
name: "qforte"
version: "1.0.0"

source:
git_rev: "0f6d603da878535c057b4d2594e730551876b1ec"
git_url: "https://github.com/evangelistalab/qforte.git"

requirements:
build:
- python
- setuptools

run:
- python
- numpy
- scipy
- pytest

test:
imports:
- qforte

about:
home: "https://github.com/evangelistalab/qforte"
2 changes: 1 addition & 1 deletion src/qforte/abc/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def measure_energy(self, Ucirc):
if self._fast:
myQC = qforte.Computer(self._nqb)
myQC.apply_circuit(Ucirc)
val = np.real(myQC.direct_op_exp_val(self._qb_ham))
val = np.real(myQC.expectation(self._qb_ham))
else:
Exp = qforte.Experiment(self._nqb, Ucirc, self._qb_ham, 2000)
val = Exp.perfect_experimental_avg([])
Expand Down
4 changes: 2 additions & 2 deletions src/qforte/abc/ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def build_orb_energies(self):
print('---------------------------------------', flush=True)
qc = qf.Computer(self._nqb)
qc.apply_circuit(build_Uprep(self._ref, 'occupation_list'))
E0 = qc.direct_op_exp_val(self._qb_ham)
E0 = qc.expectation(self._qb_ham)

for i in range(self._nqb):
qc = qf.Computer(self._nqb)
qc.apply_circuit(build_Uprep(self._ref, 'occupation_list'))
qc.apply_gate(qf.gate('X', i, i))
Ei = qc.direct_op_exp_val(self._qb_ham)
Ei = qc.expectation(self._qb_ham)

if(i<sum(self._ref)):
ei = E0 - Ei
Expand Down
2 changes: 1 addition & 1 deletion src/qforte/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ PYBIND11_MODULE(qforte, m) {
.def("direct_oppl_exp_val", &Computer::direct_oppl_exp_val)
.def("direct_idxd_oppl_exp_val", &Computer::direct_idxd_oppl_exp_val)
.def("direct_oppl_exp_val_w_mults", &Computer::direct_oppl_exp_val_w_mults)
.def("direct_op_exp_val", &Computer::direct_op_exp_val)
.def("expectation", &Computer::expectation)
.def("direct_circ_exp_val", &Computer::direct_circ_exp_val)
.def("direct_pauli_circ_exp_val", &Computer::direct_pauli_circ_exp_val)
.def("direct_gate_exp_val", &Computer::direct_gate_exp_val)
Expand Down
8 changes: 4 additions & 4 deletions src/qforte/computer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void Computer::apply_2qubit_gate(const Gate& qg) {

}

std::complex<double> Computer::direct_op_exp_val(const QubitOperator& qo) {
std::complex<double> Computer::expectation(const QubitOperator& qo) {
// local_timer t;
std::complex<double> result = 0.0;
if(parallelism_enabled){
Expand All @@ -767,7 +767,7 @@ std::complex<double> Computer::direct_op_exp_val(const QubitOperator& qo) {

coeff_ = old_coeff;
}
// timings_.push_back(std::make_pair("direct_op_exp_val", t.get()));
// timings_.push_back(std::make_pair("expectation", t.get()));
return result;
}

Expand All @@ -777,7 +777,7 @@ std::vector<std::complex<double>> Computer::direct_oppl_exp_val(
std::vector<std::complex<double>> results;

for (const auto& pl_term : qopl.terms()) {
results.push_back(direct_op_exp_val(pl_term.second) * pl_term.first);
results.push_back(expectation(pl_term.second) * pl_term.first);
}

return results;
Expand All @@ -789,7 +789,7 @@ std::vector<std::complex<double>> Computer::direct_idxd_oppl_exp_val(
std::vector<std::complex<double>> results;
if(parallelism_enabled){
for (const auto& idx : idxs){
std::complex<double> val = direct_op_exp_val(qopl.terms()[idx].second);
std::complex<double> val = expectation(qopl.terms()[idx].second);
results.push_back(val*qopl.terms()[idx].first);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/qforte/computer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Computer {

/// get the expectation value of the sum of many circuits directly
/// (ie without simulated measurement)
std::complex<double> direct_op_exp_val(const QubitOperator& qo);
std::complex<double> expectation(const QubitOperator& qo);

/// get the expectation value of many 1qubit gates directly
/// (ie without simulated measurement)
Expand Down
4 changes: 2 additions & 2 deletions src/qforte/ite/qite.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def run(self,

qc_ref = qf.Computer(self._nqb)
qc_ref.apply_circuit(self._Uprep)
self._Ekb = [np.real(qc_ref.direct_op_exp_val(self._qb_ham))]
self._Ekb = [np.real(qc_ref.expectation(self._qb_ham))]

# Print options banner (should done for all algorithms).
self.print_options_banner()
Expand Down Expand Up @@ -371,7 +371,7 @@ def do_qite_step(self):
self._total_phase *= phase1
self._Uqite.add(eiA_kb)
self._qc.apply_circuit(eiA_kb)
self._Ekb.append(np.real(self._qc.direct_op_exp_val(self._qb_ham)))
self._Ekb.append(np.real(self._qc.expectation(self._qb_ham)))

self._n_cnot += eiA_kb.get_num_cnots()

Expand Down
4 changes: 2 additions & 2 deletions src/qforte/utils/exponentiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import qforte
import numpy as np

def exponentiate_pauli_string(coefficient, term, Use_cRz=False, ancilla_idx=None, Use_open_cRz=False):
def exp_pauli_string(coefficient, term, Use_cRz=False, ancilla_idx=None, Use_open_cRz=False):
"""
returns the exponential of an string of Pauli operators multiplied by an imaginary coefficient

Expand All @@ -20,7 +20,7 @@ def exponentiate_pauli_string(coefficient, term, Use_cRz=False, ancilla_idx=None
"""
# This function assumes that the factor is imaginary. The following tests for it.
if np.abs(np.real(coefficient)) > 1.0e-14:
raise ValueError(f'exponentiate_pauli_string() called with a real coefficient {coefficient}')
raise ValueError(f'exp_pauli_string() called with a real coefficient {coefficient}')

# If the Pauli string has no terms this is just a phase factor times the identity circuit
if term.size() == 0:
Expand Down
12 changes: 6 additions & 6 deletions src/qforte/utils/trotterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def trotterize(operator, factor=1.0, trotter_number=1, trotter_order=1):
if (trotter_number == 1) and (trotter_order == 1):
#loop over terms in operator
for term in operator.terms():
term_generator, phase = qforte.exponentiate_pauli_string(factor*term[0],term[1])
term_generator, phase = qforte.exp_pauli_string(factor*term[0],term[1])
for gate in term_generator.gates():
troterized_operator.add(gate)
total_phase *= phase
Expand All @@ -45,7 +45,7 @@ def trotterize(operator, factor=1.0, trotter_number=1, trotter_order=1):
ho_op.add( factor * term[0] / float(trotter_number) , term[1])

for trot_term in ho_op.terms():
term_generator, phase = qforte.exponentiate_pauli_string(trot_term[0],trot_term[1])
term_generator, phase = qforte.exp_pauli_string(trot_term[0],trot_term[1])
for gate in term_generator.gates():
troterized_operator.add(gate)
total_phase *= phase
Expand Down Expand Up @@ -82,13 +82,13 @@ def trotterize_w_cRz(operator, ancilla_qubit_idx, factor=1.0, Use_open_cRz=False
#loop over terms in operator
if(Use_open_cRz):
for term in operator.terms():
term_generator, phase = qforte.exponentiate_pauli_string(factor*term[0],term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx, Use_open_cRz=True)
term_generator, phase = qforte.exp_pauli_string(factor*term[0],term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx, Use_open_cRz=True)
for gate in term_generator.gates():
troterized_operator.add(gate)
total_phase *= phase
else:
for term in operator.terms():
term_generator, phase = qforte.exponentiate_pauli_string(factor*term[0],term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx)
term_generator, phase = qforte.exp_pauli_string(factor*term[0],term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx)
for gate in term_generator.gates():
troterized_operator.add(gate)
total_phase *= phase
Expand All @@ -104,13 +104,13 @@ def trotterize_w_cRz(operator, ancilla_qubit_idx, factor=1.0, Use_open_cRz=False

if(Use_open_cRz):
for trot_term in ho_op.terms():
term_generator, phase = qforte.exponentiate_pauli_string(trot_term[0],trot_term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx, Use_open_cRz=True)
term_generator, phase = qforte.exp_pauli_string(trot_term[0],trot_term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx, Use_open_cRz=True)
for gate in term_generator.gates():
troterized_operator.add(gate)
total_phase *= phase
else:
for trot_term in ho_op.terms():
term_generator, phase = qforte.exponentiate_pauli_string(trot_term[0],trot_term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx)
term_generator, phase = qforte.exp_pauli_string(trot_term[0],trot_term[1], Use_cRz=True, ancilla_idx=ancilla_qubit_idx)
for gate in term_generator.gates():
troterized_operator.add(gate)
total_phase *= phase
Expand Down
4 changes: 2 additions & 2 deletions tests/test_advanced_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_advanced_gates(self):
print(T_circ.str())
trial_state.apply_circuit(T_circ) # This should turn the state to 1110
a1_dag_a2 = build_operator('1.0, Z_2')
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(-1, abs=9e-16) # Measure qubit 2 should give -1

# verify Fredkin gate
Expand All @@ -22,5 +22,5 @@ def test_advanced_gates(self):
trial_state.apply_circuit(F_circ) # This should turn the state to 1101
# trial_state.apply_circuit_safe(F_circ) # This should turn the state to 1101
a1_dag_a2 = build_operator('1.0, Z_2')
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(1, abs=9e-16) # Measure qubit 2 should give +1
2 changes: 1 addition & 1 deletion tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,5 @@ def test_op_exp_val_1(self):
a1_dag_a2.add(0.0+0.25j, circ4)

#get direct expectatoin value
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(0.25, abs=2.0e-16)
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def test_io_simplified(self):
0.25, X_2 X_1; 0.0+0.25j, Y_2 X_1')

#get direct expectatoin value
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(0.25, abs=2.0e-16)
6 changes: 3 additions & 3 deletions tests/test_qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ def test_qft(self):
qft(trial_state, 0, 3)

a1_dag_a2 = build_operator('1.0, Z_0')
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(0, abs=1.0e-16)

# test unitarity
qft(trial_state, 0, 2)
rev_qft(trial_state, 0, 2)

a1_dag_a2 = build_operator('1.0, Z_0')
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(0, abs=1.0e-16)

# test reverse transformation
qft(trial_state, 0, 3)

a1_dag_a2 = build_operator('1.0, Z_0')
exp = trial_state.direct_op_exp_val(a1_dag_a2)
exp = trial_state.expectation(a1_dag_a2)
assert exp == approx(1.0, abs=1.0e-14)