<!-- BaNnErBlUrFlE-BoDy-start -->
<!-- Preheader Text : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">
Many thanks Barry, that really helped! In my ignorance I was confused by petsc4py’s signature setJacobianEquality(self, jacobian_equality, Mat J=None, Mat P=None, args=None, kargs=None) which I misread as setting J was optional. Here is the
</div>
<!-- Preheader Text : END -->
<!-- Email Banner : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerStart</div>
<!--[if ((ie)|(mso))]>
<table border="0" cellspacing="0" cellpadding="0" width="100%" style="padding: 16px 0px 16px 0px; direction: ltr" ><tr><td>
<table border="0" cellspacing="0" cellpadding="0" style="padding: 0px 10px 5px 6px; width: 100%; border-radius:4px; border-top:4px solid #90a4ae;background-color:#D0D8DC;"><tr><td valign="top">
<table align="left" border="0" cellspacing="0" cellpadding="0" style="padding: 4px 8px 4px 8px">
<tr><td style="color:#000000; font-family: 'Arial', sans-serif; font-weight:bold; font-size:14px; direction: ltr">
This Message Is From an External Sender
</td></tr>
<tr><td style="color:#000000; font-weight:normal; font-family: 'Arial', sans-serif; font-size:12px; direction: ltr">
This message came from outside your organization.
</td></tr>
</table>
</td></tr></table>
</td></tr></table>
<![endif]-->
<![if !((ie)|(mso))]>
<div dir="ltr" id="pfptBanner49ds2li" style="all: revert !important; display:block !important; text-align: left !important; margin:16px 0px 16px 0px !important; padding:8px 16px 8px 16px !important; border-radius: 4px !important; min-width: 200px !important; background-color: #D0D8DC !important; background-color: #D0D8DC; border-top: 4px solid #90a4ae !important; border-top: 4px solid #90a4ae;">
<div id="pfptBanner49ds2li" style="all: unset !important; float:left !important; display:block !important; margin: 0px 0px 1px 0px !important; max-width: 600px !important;">
<div id="pfptBanner49ds2li" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-weight:bold !important; font-weight:bold; font-size:14px !important; line-height:18px !important; line-height:18px">
This Message Is From an External Sender
</div>
<div id="pfptBanner49ds2li" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-weight:normal; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-size:12px !important; line-height:18px !important; line-height:18px; margin-top:2px !important;">
This message came from outside your organization.
</div>
</div>
<div style="clear: both !important; display: block !important; visibility: hidden !important; line-height: 0 !important; font-size: 0.01px !important; height: 0px"> </div>
</div>
<![endif]>
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerEnd</div>
<!-- Email Banner : END -->
<!-- BaNnErBlUrFlE-BoDy-end -->
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
#pfptBanner49ds2li { all: revert !important; display: block !important;
visibility: visible !important; opacity: 1 !important;
background-color: #D0D8DC !important;
max-width: none !important; max-height: none !important }
.pfptPrimaryButton49ds2li:hover, .pfptPrimaryButton49ds2li:focus {
background-color: #b4c1c7 !important; }
.pfptPrimaryButton49ds2li:active {
background-color: #90a4ae !important; }
</style>
<!-- BaNnErBlUrFlE-HeAdEr-end -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
{font-family:wf_segoe-ui_normal;
panose-1:2 11 6 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:10.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word;line-break:after-white-space">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Many thanks Barry, that really helped! In my ignorance I was confused by petsc4py’s signature
<br>
<br>
setJacobianEquality(self, jacobian_equality, Mat J=None, Mat P=None, args=None, kargs=None)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">which I misread as setting J was optional. Here is the complete working code for the public archive in case someone else has the same question.<br>
<br>
import petsc4py.PETSc as PETSc<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># initial guess<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">x = PETSc.Vec().createSeq(2)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">x.set(0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">x.assemble()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">print("initial guess: ", x.array_r)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># create TAO solver and set solution<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver = PETSc.TAO().create()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setType("almm")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setFromOptions()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># add objective and gradient routines<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setSolution(x)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">def myObjGrad(tao, x, g): <o:p>
</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> J = x[0]**2 + x[1]**2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> dJ = 2*x <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> dJ.copy(g)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> return J<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setObjectiveGradient(myObjGrad, None)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># add equality constraint and its derivative<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">def myEqualityConstraint(tao, x, ce):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ce.set((x[0]-2)**2 + x[1]**2 - 1)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">ce = PETSc.Vec().createSeq(1)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">ce.assemble()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setEqualityConstraints(myEqualityConstraint, ce)
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">def myEqualityJacobian(tao, x, JE, JEpre):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> v = PETSc.Vec().createSeq(2)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> v.setValue(0, 4)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> v.assemble()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> vals = 2*x - v <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> JE.setValues(0, [0, 1], vals.array_r)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> JE.assemble()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">JE = PETSc.Mat().createDense([1,2])<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">JE.assemble()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setJacobianEquality(myEqualityJacobian, JE)
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># solve the problem<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.solve()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">print("found optimum at: ", solver.getSolution().array_r)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.destroy()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><br>
Best,<br>
Alberto<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Barry Smith <bsmith@petsc.dev><br>
<b>Date: </b>Monday, 27 May 2024 at 22:15<br>
<b>To: </b>Paganini, Alberto D.M. (Dr.) <a.paganini@leicester.ac.uk><br>
<b>Cc: </b>petsc-users@mcs.anl.gov <petsc-users@mcs.anl.gov><br>
<b>Subject: </b>Re: [petsc-users] [11 SEGV: Segmentation Violation] petsc4py.TAO<o:p></o:p></span></p>
</div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" align="left" width="100%" style="width:100.0%;display:table;border-collapse:seperate;float:none">
<tbody>
<tr>
<td style="background:#A6A6A6;padding:5.25pt 1.5pt 5.25pt 1.5pt"></td>
<td width="100%" style="width:100.0%;background:#EAEAEA;padding:5.25pt 3.75pt 5.25pt 11.25pt">
<div>
<p class="MsoNormal" style="mso-element:frame;mso-element-frame-hspace:2.25pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:column;mso-height-rule:exactly">
<span style="font-size:9.0pt;font-family:wf_segoe-ui_normal;color:#212121">You don't often get email from bsmith@petsc.dev.
<a href="https://urldefense.us/v3/__https://aka.ms/LearnAboutSenderIdentification__;!!G_uCfscf7eWS!cDFJhPD3KVsSrnNZRx_WfSLoEpdk6LP9YcsDXPd-sM98dT4l-Q6CIB9hUzRyBpdcJsKTS_PA6MC0nUKpAtMVp3oeDi-EyTnt$">Learn why this is important</a><o:p></o:p></span></p>
</div>
</td>
<td width="75" style="width:56.25pt;background:#EAEAEA;padding:5.25pt 3.75pt 5.25pt 3.75pt">
</td>
</tr>
</tbody>
</table>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;display:none"><o:p> </o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" align="left" width="100%" style="width:100.0%;display:table;border-collapse:seperate;float:none">
<tbody>
<tr>
<td style="background:#A6A6A6;padding:5.25pt 1.5pt 5.25pt 1.5pt"></td>
<td width="100%" style="width:100.0%;background:#EAEAEA;padding:5.25pt 3.75pt 5.25pt 11.25pt">
<div>
<p class="MsoNormal" style="mso-element:frame;mso-element-frame-hspace:2.25pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:column;mso-height-rule:exactly">
<b><span style="font-size:9.0pt;font-family:wf_segoe-ui_normal;color:#212121">***CAUTION:***</span></b><span style="font-size:9.0pt;font-family:wf_segoe-ui_normal;color:#212121"> This email was sent from an
<b>EXTERNAL</b> source. Think before clicking links or opening attachments. <o:p>
</o:p></span></p>
</div>
</td>
<td width="75" style="width:56.25pt;background:#EAEAEA;padding:5.25pt 3.75pt 5.25pt 3.75pt">
</td>
</tr>
</tbody>
</table>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> Alberto,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> You need to construct a matrix and pass it in as the second argument to solver.setJacobianEquality(myEqualityJacobian, JE) <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> Barry<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> <br>
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"><br>
<br>
<o:p></o:p></span></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">On May 27, 2024, at 11:58</span><span style="font-size:12.0pt;font-family:"Arial",sans-serif"> </span><span style="font-size:12.0pt">AM, Paganini, Alberto D.M. (Dr.) <a.paganini@leicester.ac.uk> wrote:<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<div>
<div id="pfptBanner3dljtst">
<div id="pfptBanner3dljtst">
<div id="pfptBanner3dljtst">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Arial",sans-serif">This Message Is From an External Sender<o:p></o:p></span></p>
</div>
<div id="pfptBanner3dljtst">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Arial",sans-serif">This message came from outside your organization.<o:p></o:p></span></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Dear PETSc experts,</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">I’m trying to set up a simple constrained optimization problem with petsc4py.TAO and I’m hitting a<br>
<br>
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><br>
Below is a minimal failing example (which also highlights how little I know about PETSc :) ). I hit this error because I was trying to understand how to assign values to the Jacobian of the equality constraint in the function myEqualityJacobian. Any advice
on how to avoid the segmentation violation (and more generally, any advice about how to code this up better) are warmly welcomed.</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">import petsc4py.PETSc as PETSc</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"># initial guess</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">x = PETSc.Vec().createSeq(2)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">x.set(0)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">x.assemble()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">print("initial guess: ", x.array_r)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"># create TAO solver and set solution</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver = PETSc.TAO().create()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setType("almm")</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setFromOptions()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"># add objective and gradient routines</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setSolution(x)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">def myObjGrad(tao, x, g):<span class="apple-converted-space"> </span></span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> J = x[0]**2 + x[1]**2</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> dJ = 2*x<span class="apple-converted-space"> </span></span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> dJ.copy(g)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> return J</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setObjectiveGradient(myObjGrad, None)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"># add equality constraint and its derivative</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">def myEqualityConstraint(tao, x, ce):</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> ce.set((x[0]-2)**2 + x[1]**2)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">ce = PETSc.Vec().createSeq(1)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">ce.assemble()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setEqualityConstraints(myEqualityConstraint, ce)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">def myEqualityJacobian(tao, x, JE, JEpre):</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> v = PETSc.Vec().createSeq(2)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> v.setValue(0, 4)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> v.assemble()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> vals = 2*x - v<span class="apple-converted-space"> </span></span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> # How should I enter vals into JE?</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> col = JE.getColumnVector(0)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> vals.copy(col)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> #col = JE.getDenseColumnVec(0)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> #JE.restoreDenseColumnVec(0)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.setJacobianEquality(myEqualityJacobian)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"># solve the problem</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.solve()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">print("found optimum at: ", solver.getSolution().array_r)</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">solver.destroy()</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Many thanks in advance for your help.</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><br>
Best,<br>
Alberto</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>